MODBUS Problems

Hello,

I’m very new to the c language and am having some problems understanding a few things. first would some one please explain the following code to me?

unsigned _mbsCmdWord		( unsigned wOff );

I understand the variable decleration but what are the arguments in parenthesis for?

Second) I’m using the RCM3610 to make a MODBUS RTU slave device. I’ve been looking at the sample code and can’t figure out a few things.

From my main program I would call MODBUS_Serial_tick() in MODBUS_SLAVE.LIB.

When that function is finished and returned to the main program, where can I find the received command and data? Would somebody show me some example code for accessing this information?

Thank you,

hello,

1 : “first would some one please explain the following code to me?”

unsigned _mbsCmdWord ( unsigned wOff );

is the declaration of the “_mbsCmdWord” function, which take an unsigned argument, and return an unsigned value. The defintion of this function is in MODBUS_SLAVE.LIB too :

unsigned _mbsCmdWord ( unsigned wOff )
{ unsigned CommandWord;
CommandWord = (acMSCmd[wOff] << 8) & 0xFF00;
CommandWord |= acMSCmd[wOff + 1];
return CommandWord;
}

2 : “When that function is finished and returned to the main program, where can I find the received command and data?”

in the definition of the “MODBUS_Serial_tick” function, in MODBUS_SLAVE.LIB, you can see :

#if MODBUS_DEBUG_PRINT & 2
printf ( “ByteCount=%2d MBaddress=%2d MBcmd=%2d
\r”,
ByteCount, acMSReply[0], acMSReply[1] );
#endif

If you use, the “Modbus_Serial_Slave.c”, you have to change :

#define MODBUS_DEBUG_PRINT 0 // 0xFC
#define MODBUS_SLAVE_DEBUG nodebug

to

#define MODBUS_DEBUG_PRINT 2 // 0xFC
#define MODBUS_SLAVE_DEBUG debug

to print informations via “printf”. Look at your “MODBUS_Serial_Tx” definition : maybe another MODBUS_DEBUG_PRINT value will print another informations!