I have an app that is installed on about a dozen machines (all Windows 10 64-bit but the app is 32-bit). The app starts up about a minute after the machine is booted up (they are shutdown nightly) and connects to 3 separate serial devices. On several machines (but not all - arg!) one of the devices serial ports fails to open fairly consistently. When it fails it gives me a LastErrorCode of 31. We attempt to close and reopen the port several times but to no avail. If we restart the app it starts up as it should. It’s almost as if the serial port is in some weird state that Xojo can’t negotiate.
There is nothing special about the serial device. Select the port, baud, stop bit, set RequestToSend = false, and then connect and start polling. The Connect itself seems to be open but it’s the error event that catches it.
Does anyone know what error code 31 is? According to the Xojo Docs most windows errors are in the range of 10004 to 11004 so I’m wondering if this is a Xojo error. Anyone have any ideas?
Try a reinstall of the serial drivers if its a USB<>Serial device.
If its a USB<>Serial device, try a different device, it might be on its way out.
Try a call to GetLastError and FormatMessage straight after the Serial.Open (or in the Error event) to see if it returns more information.
My assumption was that Xojo simply fails to open connection and puts the OS level error code into LastErrorCode.
Sending the number 31 to GetWindowsErrorMessageMBS, will give you an error message, but that may be just the general failure message quoted above.