isaacrlevin / presencelight

PresenceLight is a solution to broadcast your various statuses to light bulbs.
MIT License
416 stars 75 forks source link

Problem with Serial communication #866

Open pauliusbau opened 5 months ago

pauliusbau commented 5 months ago

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

isaacrlevin commented 4 months ago

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

pauliusbau commented 4 months ago

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

isaacrlevin commented 4 months ago

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?

JMilthaler commented 4 months ago

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

isaacrlevin commented 4 months ago

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

Send me an email isaac@isaaclevin.com and I will send it to you

JakeShirley commented 2 months ago

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.

isaacrlevin commented 1 month ago

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

JMilthaler commented 1 month ago

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.