Problem with serial modbus

Hello,

i would like to use OpenHistorian to get e.g. current and voltage values from a device using a serial modbus connection.

The device is connected to serial port COM1 of the computer where OpenHistorian is installed.

If i try to setup the connection to read the holding register 10000, i get the error message: “Exception while reading holding registers starting @ 10000: The port is closed.”

The connection string “portName=COM1; baudRate=19200; dataBits=8; parity=Even; stopBits=One; frameFormat=RTU; transport=SERIAL; unitID=55” was used.
(The unitID is the modbus adress of the device.)

There is no communication on COM1, observed by oscilloscope measurements.

The Log file viewer shows the entries:

Time: 27.03.2023 09:38:34 - Framework - Error - None - None
Event Name: Error Message
Exception: 
System.InvalidOperationException: Exception while reading holding registers starting @ 10000: The port is closed. ---> System.InvalidOperationException: The port is closed.
   at System.IO.Ports.SerialPort.DiscardInBuffer()
   at Modbus.IO.ModbusSerialTransport.Write(IModbusMessage message)
   at Modbus.IO.ModbusTransport.UnicastMessage[T](IModbusMessage message)
   at Modbus.Device.ModbusMaster.PerformReadRegisters(ReadHoldingInputRegistersRequest request)
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ModbusAdapters.ModbusHubClient.<ReadHoldingRegisters>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at openHistorian.DataHub.<ReadHoldingRegisters>d__94.MoveNext()
   --- End of inner exception stack trace ---
Message Type: GSF.ServiceProcess.ServiceHelper
Message Assembly: GSF.ServiceProcess.dll (2.4.24.0) 
Managed Thread Id: 13

Current Stack Trace: 
   at openHistorian.ServiceHost.LogException(Exception ex) IL offset: 23
   at openHistorian.DataHub+<ReadHoldingRegisters>d__94.MoveNext() IL offset: 245
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) IL offset: 370
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) IL offset: 21
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run() IL offset: 111
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(Action action, Boolean allowInlining, Task& currentTask) IL offset: 99
   at System.Threading.Tasks.Task.FinishContinuations() IL offset: 1024
   at System.Threading.Tasks.Task.Finish(Boolean bUserDelegateExecuted) IL offset: 82
   at System.Threading.Tasks.Task`1.TrySetException(Object exceptionObject) IL offset: 118
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetException(Exception exception) IL offset: 75
Time: 27.03.2023 09:38:34 - Framework - Error - None - None
Event Name: Status Message Alarm
Message: Exception while reading holding registers starting @ 10000: The port is closed.


Details: 00000000-0000-0000-0000-000000000000
Message Type: GSF.ServiceProcess.ServiceHelper
Message Assembly: GSF.ServiceProcess.dll (2.4.24.0) 
Managed Thread Id: 13

Current Stack Trace: 
   at GSF.ServiceProcess.ServiceHelper.UpdateStatus(UpdateType type, Boolean publishToLog, String message, Object[] args) IL offset: 95
   at GSF.TimeSeries.ServiceHostBase.DisplayStatusMessage(String status, UpdateType type, Boolean publishToLog) IL offset: 179
   at openHistorian.DataHub+<ReadHoldingRegisters>d__94.MoveNext() IL offset: 245
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) IL offset: 370
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) IL offset: 21
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run() IL offset: 111
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(Action action, Boolean allowInlining, Task& currentTask) IL offset: 99
   at System.Threading.Tasks.Task.FinishContinuations() IL offset: 1024
   at System.Threading.Tasks.Task.Finish(Boolean bUserDelegateExecuted) IL offset: 82
   at System.Threading.Tasks.Task`1.TrySetException(Object exceptionObject) IL offset: 118

What am I doing wrong ?

Just a guess, but it could be that if you have added the device to the system to start polling, then revisit the screen to edit the config, the onscreen connection cannot operate since the system is already polling the device.

If this is the case, try disabling device on the “Browse Devices” screen before attempting to edit so that only one active connection is operating against the device at once.

Generally, we use TCP connections for this screen, so I will say that the serial connection portion is not as well tested.

Thanks,
Ritchie

Thank you very much for the fast reply.

I have deleted my device.
Then i have tried to add a new device: “Devices”->“Add Device / Import Data”->“Modbus (Adds a new Modbus connection)”

I have entered the data for the device and pressed the “Add device”-Button.

Then i got the “Save Device Connection”-window.

I have closed the “Save Device Connection”-window by pressing the Save-Button and in that moment, the openHistorianConsole displayed a red error-message:

[STAT] AdoMetadataProvider has finished metadata refresh.

[STAT] Resuming measurement processing...

[Action Adapter Collection] Failed to load adapter "STATISTIC!SERVICES" [GSF.TimeSeries.Statistics.StatisticsEngine] from "C:\Program Files\openHistorian\GSF.TimeSeries.dll": Exception has been thrown by the target of an invocation.

Database connection closed.

Starting measurement route calculation...

Calculated 1 route for 10 destinations in 1.001 milliseconds.

Successfully cached current configuration to binary.

Successfully cached current configuration to XML.

[MYDEVICE] Attempting connection...

[MYDEVICE] Connection established.

[MYDEVICE] Executing poll operation 1.

[MYDEVICE] Device disconnected.

[MYDEVICE] Disconnected from .

[MYDEVICE] The port is closed.

[MYDEVICE] Attempting connection...

[MYDEVICE] Connection established.

That may be accurate - if it keeps polling, i.e., open, poll, close and repeat.