当前位置:网站首页>Client example analysis of easymodbustcp

Client example analysis of easymodbustcp

2022-04-23 17:41:00 シシヌ

Modbus It is a serial communication protocol for industrial electronic equipment ,easymodbusTCP Can assist in software and adoption modbus Protocol device for communication , Achieve the effect of remote control .

This is a easymodbus Official testing tools ,modbus The default port of the device is 502, The most important thing left is to correspond to modbus Four ways to read and write addresses , The most commonly used ones have been taken as an example ,30001-39999,40001-49999 Corresponding Input Registers and Holding Registers,

modbusClient.ReadInputRegisters(int startingAddress, int quantity);
modbusClient.ReadHoldingRegisters(int startingAddress, int quantity);
startingAddress Register address , Such as 
modbusClient.ReadInputRegisters(30055, 2);

From 30055 Start , Read two digits , I actually read 30055,30056.

Corresponding sending command , There is no substantial difference between sending a single and multiple ,

modbusClient.WriteSingleRegister(int startingAddress, int value);
modbusClient.WriteMultipleRegisters(int startingAddress, int[] values);

Generally speaking, the equipment side receives int It will be converted to binary , So if the equipment side 30055 Multiple states are stored , Usually corresponding bit[8] perhaps bit[16], Need to control at the same time bit[0] and bit[1] by true Send directly when int 3 that will do ,

modbusClient.WriteSingleRegister(30055, 3);

 

版权声明
本文为[シシヌ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231740108335.html