Serial LastErrorCode

I’ve been testing a serial port on Xojo and the LastErrorCode only ever seems to return 2.

If I open a serial port thats already open I get LastErrorCode = 2 If I try and open a serial port that doesn’t exist I get LastErrorCode = 2

Should I expect it to return 101 when I try and open a port that doesn’t exist and 101 when 100 when I open a port thats already open?

[code]Select Case Me.LastErrorCode

Case Serial.AccessDenied ’ 100

’ Message Box
MsgBox “The selected serial port could not be opened, access denied.”

Case Serial.PortNotFound ’ 101

’ Message Box
MsgBox “The selected serial port could not be opened, port not found.”

Case Serial.InvalidOptions ’ 102

’ Message Box
MsgBox “The selected serial port could not be opened, invalid options.”

Case Serial.BreakCondition ’ 103

’ Message Box
MsgBox “The selected serial port could not be opened, BreakCondition.”

Case Serial.FramingError ’ 104

’ Message Box
MsgBox “The selected serial port could not be opened, FramingError.”

Case Else

’ Message Box
MsgBox “The selected serial port could not be opened.”

End Select[/code]

Sorry it took me so long to look at this, I missed it the first time around.

Errors outside the xojo range above are ok, they just aren’t crossplatform so they dont make them easily available.

That’s very odd.

System error code 2 is:

ERROR_FILE_NOT_FOUND 2 (0x2) The system cannot find the file specified.

If I try to open a port by name and the name is wrong I get error code 2 as expected.

If I try to open a port by name e.g. “COM4” that is already in use I get error code 2, that seems like a bug, you might want to pop that into feedback to see if William thinks so too. I just tested the same thing in VS as it came back with error 5 so I think it is a bug.

If I try and open an already opened port by index number after enumerating the list I get system error code 5 as expected:

ERROR_ACCESS_DENIED 5 (0x5) Access is denied.

Just FYI, all windows specific codes are here https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx if they are outside the range of the generic ones covered by the framework.