presencelight icon indicating copy to clipboard operation
presencelight copied to clipboard

Problem with Serial communication

Open pauliusbau opened this issue 1 year ago • 8 comments

Describe the bug I am trying to control a custom Arduino device via Serial. COM ports are enumerated successfully, but App throws timeout messages every time it trys to send a message out (see below). I tired several different USB-Serial adapters and different COM port configurations. I tried to reset settings. Tried to reinstall the app. No luck whatsoever. No Serial communication is getting through (sniffed serial bus with logic analyzer). Any ideas how to fix this issue?

Log messages:

"Timestamp":"2024-02-11T14:23:56.3271400+02:00",
"Level":"Error",
"MessageTemplate":"Error Performing Serial Write - LocalSerialHost:PerformSerialMessage Line: 278",
"Exception":"System.TimeoutException: The operation has timed out.\r\n at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count, Int32 timeout)\r\n at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count)\r\n at System.IO.Ports.SerialPort.InternalRead(Char[] buffer, Int32 offset, Int32 count, Int32 timeout, Boolean countMultiByteCharsAsOne)\r\n at System.IO.Ports.SerialPort.ReadTo(String value)\r\n at System.IO.Ports.SerialPort.ReadLine()\r\n at PresenceLight.Core.LocalSerialHostService.<>c__DisplayClass17_0.<PerformSerialMessage>b__0()",
"Properties":{
    "SourceContext":"PresenceLight.Core.LocalSerialHostService",
    "LineNumber":278,
    "FilePath":"D:\\a\\presencelight\\presencelight\\src\\PresenceLight.Core\\Lights\\LocalSerialHostService\\LocalSerialHost.cs",
    "MemberName":"PerformSerialMessage",
    "message":"Available\\n",
    "Application":"PresenceLight"}


"Timestamp":"2024-02-11T14:23:56.3286543+02:00",
"Level":"Information",
"MessageTemplate":"Sending Available\\n to COM3 - LocalSerialHost:PerformSerialMessage Line: 288",
"Properties":{
    "SourceContext":"PresenceLight.Core.LocalSerialHostService",
    "LineNumber":288,
    "FilePath":"D:\\a\\presencelight\\presencelight\\src\\PresenceLight.Core\\Lights\\LocalSerialHostService\\LocalSerialHost.cs",
    "MemberName":"PerformSerialMessage",
    "message":"Available\\n",
    "Application":"PresenceLight" }

Further details

  • OS: Windows 11 (no admin rights)
  • PresenceLight App Type: AppPackage
  • PresenceLight Version 5.8.2
  • Did you clear settings.json? (C:\Users\username\AppData\Local\Packages\37828IsaacLevin.197278F15330A.SomeValue\LocalState\settings.json: Yes, didn't help :(
  • ASP.NET Core version: 5.0.17

pauliusbau avatar Feb 12 '24 08:02 pauliusbau

hey @pauliusbau, sadly I did not add this feature and don't have the HW to test. Possibly @JMilthaler can help as he did the work on this. FWIW did this ever work for you? The code hasn't been touched in 1 years :O

isaacrlevin avatar Feb 21 '24 00:02 isaacrlevin

Hey. No, it haven't. It's the first time I am trying it out.

pauliusbau avatar Feb 21 '24 06:02 pauliusbau

Hmmm yea, unless something changed in System.IO.Ports I am not sure what the issue, unless you have the ability to clone the repo and test locally?

isaacrlevin avatar Feb 21 '24 22:02 isaacrlevin

It's been quite a long time since I looked at this code, so it may take a bit to reacquaint myself with the details, but I can also look. I don't remember if the settings.json file has any sensitive information in it. If not, having a copy of that may help me see what's going on.

I do also have a very simple example of an Arduino based serial communication in my repo - https://github.com/JMilthaler/PresenceLightHardware/tree/master/PresenceLight.Hardware.Serial

** edit ** Ignore PresenceLight.Hardware.BLE in that repo - the hardware was never reliable and often stopped working randomly

JMilthaler avatar Feb 21 '24 23:02 JMilthaler

The only thing you need to add is the client ID in appsettings.json.

Send me an email [email protected] and I will send it to you

isaacrlevin avatar Feb 21 '24 23:02 isaacrlevin

I am also seeing something similar. My serial connections work fine for a day or two, but then I start getting these errors: System.IO.IOException: The semaphore timeout period has expired. : 'COM3' and serial commands fail to send.

JakeShirley avatar May 16 '24 13:05 JakeShirley

sadly I do not have a device to test this feature. More than happy to review a PR if you have a fix

isaacrlevin avatar May 23 '24 16:05 isaacrlevin

I am also seeing something similar. My serial connections work fine for a day or two, but then I start getting these errors: System.IO.IOException: The semaphore timeout period has expired. : 'COM3' and serial commands fail to send.

I think this happens when the serial device goes to sleep or loses power. I can only speak to the Seeduino XIAO because that's what I used, but I had to disable all power saving functions on the device or I received similar issues.

JMilthaler avatar May 23 '24 16:05 JMilthaler