I'm hoping somebody here can help me out as I'm close to having no hair left!
I'm trying to programme a motion controller (a Dynomotion KFlop+Kanalog to be precise) to talk to a Click PLC over Modbus.
I have the sample script working, which reads the inputs and copies thier status to virtual bits and sets the outputs depending on other virtual bits (virtual bits are essentially an easily accesible globally readable/writeable storage bit within the KFlop).
What I need to do is read two internal holding registers (DS registers in Click speak), however I'm struggling to identify the correct modbus address. Part of this is I don't quite understand how the sample script modbus request is actually working.
For the read register example, the following modbus request is sent-
Tx:01;04;e0;00;00;01;06;0a;
01 is the device ID, 04 is the function code, e000 is the register address, 0001 is the number of registers to read, and the 060a is the CRC.
Now, according to the manual, the hex address of the X (input) register, is 0000, so how does that translate to e000 in the above request?
Also, according to the Click manual, 04 is not a valid function code for the X register, only 02 is valid.
Officially 04 is a Read Input Register request, whereas 02 is Read Input Status.
Anyway, the main issue is how do I access the DS/holding register.
The hex address for the first holding register (DS1 - simply stores a value between 1 and 6) I need to read is also 0000, but with a function code of 3 (Read Holding Registers), 6 (Preset Single Register) or 16 (Preset Multiple Registers). Going by my understanding of the manual, the switch between the X and DS registers is made depending on the function code so the following request should work, so swapping the 04 for 03 in the above example should work, however it doesn't and I get the X register value returned.
I've tried swapping the e for a 0 but then things fail.
Can somebody help me out, and explain what I'm doing wrong?
I've attached the extract from the Click help regarding the addressing, and it's probably worth noting that the CRC code is automatically handled by the KFlop script, so that isn't the problem.