Announcement

Collapse
No announcement yet.

USB serial scripting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    USB serial scripting

    I am using a USB port to gather some external data. I have a script placed in the startup file to open the port. Another script periodically does the data gathering. My question is how can I trap an error with the usb port, say, if the plug were to get disconnected, etc. The only error condition I see in the help file relates to the 'port already open' error, but that only occurs on startup. If the data gathering script runs and the port has gone south (experimenting), I see a log message, so there must be a way to trap that in my script. This is my first attempt at scripting, so any comments would be appreciated!

    #2
    I don't think you can (perhaps someone will confirm) get an instant notification , if you look at the .net ports class here https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx (that I imagine HS3 uses for Mono compatibility, HS2 didn't) you will see that there are only four events for a COM port and none of these would particularly help you detect that a device had disappeared from your system. You could however look at getting a list of the names of the COM port to detect which one is missing.

    You mention the error, how are you getting data from the port, I take it you are not using the callback script option? What sort of error do you get?

    Comment


      #3
      Originally posted by mrhappy View Post
      I don't think you can (perhaps someone will confirm) get an instant notification , if you look at the .net ports class here https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx (that I imagine HS3 uses for Mono compatibility, HS2 didn't) you will see that there are only four events for a COM port and none of these would particularly help you detect that a device had disappeared from your system. You could however look at getting a list of the names of the COM port to detect which one is missing.

      You mention the error, how are you getting data from the port, I take it you are not using the callback script option? What sort of error do you get?
      I am using the following call after the port is opened:
      RelayState = hs.GetComPortData(ComPort)

      I intentionally unplugged the cable to the usb port for less than 3 seconds and got the following in the HS3 log:
      May-15 21:16:01 Error Writing data to COM port 5 :Unable to write to COM port (many, many entries, even though the script only runs every 2 seconds).
      that is followed by many entries of the following:
      May-15 21:16:04 Warning Lost 2 seconds, maybe system busy, catching up.
      and subsequently, the system slows down and I had to shutdown HS.

      If the error is detected in HS, then I should be able to access that condition to disable my script.

      Comment

      Working...
      X