rossmann-engineering / EasyModbusTCP.NET

Modbus TCP, Modbus UDP and Modbus RTU client/server library for .NET implementations
928 stars 402 forks source link

DTR and RTS control of serial port #9

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi there,

Some older RS-232/RS-485 converters rely on power from the RS-232 handshake lines. However, by default Easymodbus disables these lines which means the converters are unable to transfer the data back/forth.

Add RTS and DTR control to the component.

Regards, Darren

jorgecc commented 3 years ago

Hi there:

For the record: (years later)

The field serialport (of the class SerialPort ) is private but you can expose using reflection

  modbusClient = new ModbusClient("COM3");
  var prop = modbusClient.GetType().GetField("serialport", System.Reflection.BindingFlags.NonPublic
      | System.Reflection.BindingFlags.Instance);

 // Then you can change the dtr field.
  SerialPort sp= (SerialPort) prop.GetValue(modbusClient);
  sp.DtrEnable=true;

You can also recompile the project and add a property to change it.