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?