View Full Version : Anybody know about Modbus addressing?

15-11-2013, 12:33 AM
I'm pulling my hair out trying to get a KFlop to read the correct register in a Click PLC.

The KFlop sample code uses the following line to read the input register and store the input statuses into virtual bits-

01 is the device ID, 04 the Function Code, e000 the register address, 0001 the number of registers, with the 060a being the CRC code (the sample script generates the CRC code so I don't have to worry about that).
The input statuses are accessed via the Click's X register at hex address 0000.
(I'm not sure how the e000 translates to 0000, but it works!)

Now I want to read the Click's Holding Register DS1, which also has the hex address of 0000.
According to the manual, the preceding function code should control what registers are read, so swapping the 04 for 06, should mean DS1 gets read, but it doesn't. I still end up with the contents of X register.

Anybody got any suggestions?
Even if it is to tell me I've missed something stupid!

Here's the Click help extract covering the addressing-

15-11-2013, 09:07 AM
Maybe you could post the code here.

15-11-2013, 12:31 PM
The code is over 400 lines worth, and it does work for reading and writing the main PLC inputs and outputs.

I have figured out my problem though, and answered my own questions.
The E range of hex addresses point to the Input and Output holding registers, which store the values in hex blocks, which are what the sample code use. Being new to PLCs, I had no idea about the extra registers, it wasn't until I went through all the registers in the Address Picker, that I found the E addresses, and everything slotted into place.

I've been out this morning and a command of 01;03;00;00;00;01;..;.. reads DS1, and I've also got the KFlop writing a new value to DS2, so all that's left is to code the KFlop to store the DS1 value where I can read it in Mach, and get it to read a new value from Mach and write it into DS2.

15-11-2013, 01:05 PM
That's good then, I've not used the Click PLC before but you are correct in that they use defined sets of registers for different tasks, some are retentive memory, some are general purpose, etc.
They are generally called 'tables' and that's a good way to think of them.

This is old hat now but it shows the principle, e.g. G tables are registers for general use, R tables are retentive following power down, etc.
GEM Driver > GEC GEM80 PLC > Data Types (http://www.citect-webhelp.schneider-electric.com/citect/Drivers/Content/gem82f1v.htm)

15-11-2013, 01:18 PM
There's no G or R in a Click, but there are various registers that handle different data types.

This was my first ever attempt at using a PLC, and it's not been too painful considering. Hardest part was getting my head around ladder logic, as what could be done in a couple lines of more normal programming code, takes umpteen rungs and switches. It took me a few attempts to get the logic for the tool changer working how it should.

The Click is reasonably priced, and I'll probably look at using them in the mill for the toolchanger, but it'll be another couple months before I get anywhere near starting that project.