I am using the SerialConnection classes in a console helper application to access a Serial-to-USB device on Windows and macOS.
Basically connection looks like this:
Var seriald As serialdevice = SerialDevice.WithName(Me.PortName)
If seriald <> Nil Then
serial.Baud = Me.Baud
serial.Bits = Me.Bits
serial.CTS = Me.cts
serial.DTR = Me.dtr
serial.Parity = CType(Me.Parity, SerialConnection.Parities)
serial.StopBit = CType(Me.StopBits, SerialConnection.StopBits)
serial.XON = Me.xon
serial.Device = seriald
serial.Connect
Return True
End If
With an exception handler following, returning False.
Serial is an already created instance property of type SerialConnection, with its three events linked to class methods via Addhandler.
This works nicely on Windows, and I can read data in the DataAvailable Handler.
On macOS, the SerialConnection.Error handler fires twice before the connect method returns true (sic!).
Errorcode both times is 2, which most possibly means kBluetoothSDPErrorCodeInvalidServiceRecordHandle at least this would correspond to the SerialConnections handle which is Nil (or rather -1) while its Device property is set correctly.
Any hints what I might be doing wrongly? Or a Xojo 2019r3 bug?
EDIT: An old project using the old serial class works.
I have not tried the new API2 serial stuff, why is it there when we have a perfectly working API 1 version?
19R3 with the existing serial class is working without any issue in all my projects.
I would be happy to hear comment from staff as to what the API2 serial class is designed to ‘update’ over the original.
Thanks all. I opened a private beta case as this is part of a customers project which I did not want to strip down.
Ill keep you updated.
@Mark Carlton : From my point of view, SerialConnection follows the same structure other sockets have too under API 2.0: The same event names, the same error handling. Makes it easier to adapt code to different sockets.
Besides from that, I dont have the feeling things changed under the hood. Except for, well, the inability to connect under macOS
I think I found the error to be located in SerialDevice.WithName which I was using. Does not create a valid Device on macOS.
SerialDevice.At does. With this limitation you could use 2019r3.
[quote=471356:@Ulrich Bogun]I think I found the error to be located in SerialDevice.WithName which I was using. Does not create a valid Device on macOS.
SerialDevice.At does. With this limitation you could use 2019r3.[/quote]
I historically made a bug report about this some time ago, in the old api. I guess they not even updated the newer API 2.0 code.
Getting a serial device by it’s name didn’t work but testing against it trough an indexed loop was the only way. I’ll try to find the bug report when on the computer.
[quote=471370:@Ulrich Bogun]Doh! So the class was modernized and the bug was ported instead of fixed.
Thank you, Derk! Added your ticket to my case.[/quote]