Apollo3zehn / FluentModbus

Lightweight and fast client and server implementation of the Modbus protocol (TCP/RTU).
MIT License
188 stars 69 forks source link

Signals, RTS, DTR, CTS ??? #114

Closed Seba131 closed 1 month ago

Seba131 commented 3 months ago

Good morning, is there a chance to add support for RTS, DTR, CTS signals? They would be very helpful to me.

Apollo3zehn commented 3 months ago

Hi, you can use your self-managed SerialPort by doing the following:

var serialPort = new SerialPort("COM1")
{
    DtrEnable = true,
    RtsEnable = true
};

serialPort.Open();

client.Initialize(
    new ModbusRtuSerialPort(serialPort), 
    ModbusEndianness.LittleEndian);
Seba131 commented 3 months ago
public ModbusRtuClient modbusRtu = new ModbusRtuClient();

modbusRtu.BaudRate = 9600;
itp...

If I already have the option modbusRtu.Connect("COM1"); then I won't select it anymore inSerialPort("COM1")

DTR

Apollo3zehn commented 3 months ago

I am sorry, my example above missed the creation of the ModbusRtuClient:

Here is a better sample now:

var serialPort = new SerialPort("COM1");
var client = new ModbusRtuClient();

client.Initialize(
    new ModbusRtuSerialPort(serialPort), 
    ModbusEndianness.LittleEndian);

serialPort.Open();

serialPort.DtrEnable = true;
serialPort.RtsEnable = true;

As long as you have control over the instantiation of ModbusRtuClient the code sample should work. Or do you encounter other problems I did no cover in my answer (I did not fully understand your last post so I am not sure)?

Seba131 commented 3 months ago

ok. It works.