• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

Modbus + Socket can not read write coils?

Started by sxbug, September 10, 2020, 01:24:59 pm

Previous topic - Next topic

sxbug

Hi
There is a problem with its MODBUS reading coil(Using Demo Socket+Modbus). I use demo to test it, Read Register is OK, Read Coil is mistake. After reading the M100 coil of FX3U PLC, the value read  is off, which  actually is on. When I reading it with other MODBUS components(Delphi modbustcp in github), it is correct.
These data are as follows:
Delphi ModbusTcp Component:
send:01 00 00 00 00 06 FF 01 04 4C 00 01
rece  :01 00 00 00 00 04 FF 01 01 01
Display: coil is on

nrComm Modbus socket:
send:31 BC 00 00 00 06 FF 01 04 4C 00 01
rece  :31 BC 00 00 00 04 FF 01 01 01
Display: coil is off. It's mistake.

How can I do? Thanks

sxbug@163.com

Roman Novgorodov

September 11, 2020, 06:05:05 am #1 Last Edit: September 11, 2020, 06:06:43 am by Roman Novgorodov
Hello

I do not understand why requests are differ?

First one is 01 00 00 ...
Second is    31 BC 00 ...

It seems like first is RTU mode and second one uses ASCII mode.
ModbusDemo allows to change RTU/ASCII please check

Roman Novgorodov
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

Roman Novgorodov

September 11, 2020, 07:38:53 am #2 Last Edit: September 11, 2020, 07:52:06 am by Roman Novgorodov
Quote from: undefinedThe address obtained by this function - Coils.GetCoilNumber(i)  is not correct, and the high bit is lost . pls check it. Thanks

The GetCoilNumber() method just returns high 16-bit value of 32 bit integer.

function TnrModbusCoilList.GetCoilNumber(index: integer): word;
begin
  Result := Dword(Items[index]) shr 16;
end;

I think, there is no error, kid :-)
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

sxbug

Hi
   Thank you for your help.
   I used two programs, so the first program was 01 00 and the second program was 31 BC.

  Now I tested RTU and ASCII, but there are still problems, the results are the same.

Monitoring procedures:
[21:02:34.805]rec←◆00 04 00 00 00 06 FF 01 04 4C 00 01
[21:02:40.859]rec←◆00 05 00 00 00 06 FF 01 04 4C 00 01
[21:02:41.983]send→◇00 05 00 00 00 04 FF 01 01 01 □

demo program:
TCP Connected to 192.168.1.100 : 502
Timeout!!! No reply from device!
Device 255 disconnected
Device 255 connected
Device: 255 Coil:004C=False

Thanks

    sxbug

sxbug

Another question is, why not display all the CoilsNumber?    Thanks

sxbug

function TnrModbusCoilList.GetCoilNumber(index: integer): word;
begin
  Result := Dword(Items[index]) shr 16;   //Items[0] = 4C 00 01  , I think it should be equal to 04 4C 00
end;

Is there a problem with CoilList?
Thanks

Roman Novgorodov

September 15, 2020, 08:07:40 am #6 Last Edit: September 15, 2020, 08:10:58 am by Roman Novgorodov
Hello

Thank you for your information.

You are right.
We see some problems with COIL functionality in TnrModbus implementation.
and fixed read and write issues with coils.

You can check new version of ModbusDemo if you want:

http://nrcommlib.com/nrcomm/ModbusDemo.exe.zip

We are going to release a version of nrComm Lib in the next few days.

Roman Novgorodov
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

sxbug

Hi
TCP Connected to 192.168.0.4 : 502
Device: 255 Coil:004C=True

The Coil return value is OK, but CoilNumber is mistake too.  in Asc mode.

Thank you for your work
 
                         sxbug

Roman Novgorodov

Hello

Thank you for information.
You are right again.

Please check new demo:
http://nrcommlib.com/nrcomm/ModbusDemo.exe.zip

Roman Novgorodov
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

sxbug

Hi
  The reading of register and coil is tested, and the return value and address are correct all.
But this time I used  RTU  mode(ASC mode could not work), I think the Modbus work  mode should be verified to see if it is correct.

     congratulations.

                 sxbug