Trouble with Coil Read Write - CLICK PLC

464 views
Skip to first unread message

TedG

unread,
Jan 12, 2015, 5:07:02 PM1/12/15
to nmodbus...@googlegroups.com
New to Modbus but not to C#. I have a Click PLC that I am trying to communicate with. The Read and Write of 16-bit registers works fine, but I can't read or write the coil registers. I feel that this is a coil addressing problem, but I'm not sure how to translate what the PLC is telling me. The PLC states that the Modbus coil addresses are 0x4000-0x47CF (which,oddly,  it translate to 16385-18384 decimal) with function code (01,05,15). I'm assuming the function code is decimal. I can imagine all sorts of things that could be causing issues, but before I go into burn-the-midnight-oil mode, I thought I would ask...

//This works fine:
ushort[] iValues = master.ReadHoldingRegisters(1, 1, 10);
foreach (ushort us in iValues)
{
  sOut
+= us.ToString() + ":";
}
Console.WriteLine(sOut.TrimEnd(':'));

//This returns all zeros (false) even thought some of the coils in the specified range are set...
bool[] bValues = master.ReadCoils(1, 1, 10);
foreach (bool b in bValues)
{
   
ushort us = Convert.ToUInt16(b);
   sOut
+= us.ToString() + ":";
}
Console.WriteLine(sOut.TrimEnd(':'));

Can anyone tell me from the coil address provided above if there is something I need to do differently (perhaps a starting address offset?) in order to read/write the coils?

TedG

unread,
Jan 14, 2015, 2:52:59 PM1/14/15
to nmodbus...@googlegroups.com
I figured this out. Just in case it helps anyone else. The addressing on the Click PLC is really odd. The (01,05,15) spec that they provide in the manual and the "Address Picker" tool is actually a list of the function codes that can be used for reading and writing - which agrees with the NMODBUS code. The big challenge was figuring out the offset of the addresses. In the click, the first "C" coil is actually address 16384, not 16385 as specified in the manual. So ReadCoils(Addr,16384,10) will give you the first 10 coil results using NMODBUS against the CLICK PLC. I had to actually set a pattern of coil bits in the PLC memory and walk the addresses to figure this out. Basically, If I had used the HEX value of 0x4000 instead of the Decimal Value 16385, I would have figured this out about 4 hours sooner!

jmccl...@gmail.com

unread,
May 1, 2017, 10:14:34 PM5/1/17
to NModbus
I am just now starting to use Click PLCs and may need some help when incorporating this into VTScada. I have Scadapacks and Allen Bradleys PLCs which seem to be not so bad figuring out but may have questions soon hopefully you are still to answer some.
Reply all
Reply to author
Forward
0 new messages