On Thu, 2008-10-23 at 13:12 +1000, Peter Homann wrote:
... snip
> There are 2 parts here. The Modbus interface basically transfers registers
> or discretes between a  Master (EMC) and Slaves(ModIO). You can almost
... snip
> appropriate to the output, say 5Hz, 25Hz, etc. Then if EMC set the value
> in the register array, it would be transferred to the PLC, turning on the
> output.

> Cheers,
> 
> Peter.

I agree that the ModIO and ModBus are different parts of a system that
can be developed and operate in their own realms. But for me, it is too
big a project get my brain around how ModBus works, how different ModBus
units work, and how the different Modbus units should work together. In
trying to eat this elephant, I thought the first spoonful could be the
absolute minimum system to have EMC use one serial port to request one
task at a time to one ModIO, no or minimal buffering, addressing,
scheduling, prioritizing, etc. Since the ModIO could do quite allot in
this configuration, I thought it worth while even if the effort can't be
applied to a proper end product.

I haven't though about this for a while, so it's a bit foggy. But I
think this might work.

An HAL component is needed, which describes a black box in software,
which has pins, bit pins for each ModIO digital IO, float pins for a PWM
output value, bit pins to enable the PWM's, float pins to read the
counters, etc. The HAL component would have a read function and a write
function. The write function would run once every thread cycle and read
one EMC output pin and send its value to the ModIO. On the next cycle it
sends the next pin value, and so on. The read function would do the same
except data goes in the other direction, ModIO to EMC pins. ModBus can
set multiple registers in one frame but that makes things much more
difficult and there is a limited amount of time in each cycle.

The HAL component is a C program with features added to allow C
variables to be seen by EMC as pins. So far, I have a stand-alone C
program to output a command to read a ModIO digital pin (actually a
register):

http://www.wallacecompany.com/machine_shop/EMC2/modbus/read_Din-1b.c
http://www.wallacecompany.com/machine_shop/EMC2/modbus/

The main features are:
...
/* Fill command buffer */
int cbuffer_bytes = 8;
static unsigned char cmd_buffer[] = {
    0x06,  // slave address
    0x03,  // function code, read registers
    0x04,  // starting register address, high byte
    0x7F,  // starting register address, low byte
    0x00,  // number of registers, high byte
    0x01,  // number of registers, low byte
    0x00,  // low byte of CRC
    0x00,  // high byte of CRC
};
...

This is a preformatted message and would need to be changed to set
variables from HAL pins.

and:

...
main () {
    prep_serial_port();
    int cycles;
    for (cycles = 0; cycles <= 100; cycles++) {
        printf("Cycle - %3d\n", cycles);
        display_cbuffer();
        msgCRC = CRC16( &cmd_buffer[ 0 ], 6 );
        printf("CRC = %2x\n", msgCRC);
        send_cbuffer();
        usleep(10000);
        recv_response();
        rmsgCRC = CRC16( &response_buffer[ 0 ], 5 );
        printf("Local Rs CRC = %x\n", rmsgCRC);
        printf("\n");
    }
    return;
}
...

This would become part of the read and write functions which would take
the data from the current EMC pin and set or read a feature of the
ModIO.

Kirk


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to