I am using the code found at the following repository:
https://github.com/Festo-se/PGVA-1/blob/main/examples/c%23/src/driver/PgvaDriver.cs
I use the following line of code to connect using a serial port:
pgva = new PgvaDriver("serial", comboBoxPort.Text, 8502, "192.168.0.199", 115200, 16);
And I am able to connect to the serial port chosen in comboBoxPort. How do I go about closing the port? If I just try
port.Close();
I receive a number of error messages:
Read Error: System.InvalidOperationException: The port is closed.
at System.IO.Ports.SerialPort.DiscardInBuffer()
at Modbus.Serial.SerialPortAdapter.DiscardInBuffer()
at Modbus.IO.ModbusSerialTransport.Write(IModbusMessage message)
at Modbus.IO.ModbusTransport.UnicastMessage[T](IModbusMessage message)
at Modbus.Device.ModbusMaster.PerformReadRegisters(ReadHoldingInputRegistersRequest request)
at Modbus.Device.ModbusMaster.ReadInputRegisters(Byte slaveAddress, UInt16 startAddress, UInt16 numberOfPoints)
at driver.PgvaDriver.ReadData(Int32 register) in C:\Users\PgvaDriver.cs:line 157
How do I succesfully close the port when necessary, and then re-open the serial port?
Thanks!