Hi kizilkaya,
Attached is an example that should read the 8 Inputs to Kogna Virtual Bits 48-55 and write Virtual Bits 56-63 to the outputs Using Kogna's RS485 Port. It is untested. Your example doesn't help much because the library functions weren't provided or documented.
This table defines the ModBus Commands
Code: Select all
ModbusMaster_Cmds ModbusMaster_MonitorList[] = {
// string is "dev,cmd,adrhi,adrlo,lenhi,lenlo" bytes of modbus command. bytelen, data, and checksum are added as necessary.
{"\x0A\x03\x9C\x61\x00\x08", 6, 0}, //ID=10, Read Holding Registers as inputs to MBRegisters[0-7] starting Modbus address 40033 decimal
{"\x0A\x10\x9C\x51\x00\x08", 6, 8}, //ID=10, Write MBRegisters[8-15] to Output Holding Registers starting Modbus Address 40017 decimal
{0, 0, 0} // end flag
};
These functions move the ModBus Register data to/from Kogna Virtual Bits
Code: Select all
// marshal and move values read from PLC/Slave into MBRegisters to KFlop memory
void ModbusMaster_RegUnload()
{
// Move 8 PLC inputs to virtual bits via MBRegisters[0]
// Note use SetStateBit which is Atomic and Thread Safe
int i;
for (i = 0; i < 8; i++)
SetStateBit(48 + i, MBRegisters[i] & 1); // 8 input bits
}
// marshal and move values to be sent to PLC/Slave into MBRegisters
void ModbusMaster_RegLoad()
{
// Move 8 virtual bits to PLC outputs via MBRegisters[1]
int i;
for (i = 0; i < 8; i++)
MBRegisters[8+i] = ReadBit(48 + 8 + i); // the 8 output bits after the 8 input bits
}
To aid in debugging you might connect the device directly to the PC and use this
modpoll utility to verify the commands.
HTH