SerialConnection: Second connect not working on Linux


I have created a Terminal software using SerialConnection. For testing purposes I am using the USB device “Uno” from Arduino which returns some welcome text after proper connect.

My terminal is working fine on Mac and Windows. I can connect/disconnect several times in a row and this is working fine.
On Linux I can connect only the very first time after starting my App to get the welcome text of the mentioned USB device. Well, after disconnect I can connect again without any error messages but neither the welcome text will be printed in my console window nor the result of any command I’m sending. I always see the the LEDs flashing up on the USB device as they should on receiving and sending data. So I’m pretty sure the connection is still working fine. I don’t understand why the returning text will then not be displayed.
I simply do SerialConnection.Connect/SerialConnection.Close on opening/closing the connection, that’s it.

Yes, I’m aware of the Linux permissions for dialout (all set in group, no issue here).

(I have to mention that I let it run on Ubuntu 18.04 in Parallels on Mac in case that matters. Is there anything I have to consider on Linux side when closing and re-opening a connection?


Hi Farai,

I have serial working on many Raspberry Pi and have never seen this problem, but I have never tested in a Linux desktop machine.
can you post your connecting code, and what version of Xojo you are using.
I think from your post you must be using API2 for the serial port, try API1 version to see if the issue is still there, if it is not then there could be a bug in API2 on Linux, who knows.

if you have working code I can try it here in a raspberry Pi to remove any question of the VM having some effect.


Hi Mark

Thank you for your support. I am using the very latest Xojo. I don’t know what API I’m using as I don’t know where to set that, so probably the default atm. It would have been difficult to offer some code but in between I could find the problem and solution.

I had the feeling that the attributes of SerialConnection have changed between close and connect for whatever reason. I have added a MessageBox before doing the SerialConnection.connect: MessageBox(SerialConnect.Baud.tostring)

Mac is showing always 9600 on every Connect (dunno Windows but probably the same as a friend told me the reconnect works). This is the value I have set in the attribute of SerialConnection.

Now the weird thing with Linux:
First Connect showing value 8 (interesting, Linux showing here not the Baud rate rather than the value listed here).

Second Connect showing me value 13 (= 57600)…I have NO CLUE where and why the Linux build is changing this on close and reconnect (could be managed by Arduino’s driver on installing Arduino developer tool (?) )

Third Connect showing me value 4097 (about Baud rate of 2000000)

Any further Connect shows value 4097 (like on third connect)

Solution here (on Linux, Ubuntu) is to set the Baud rate to the wanted value like: SerialConnect.Baud = SerialConnection.Baud9600 before executing SerialConnection.Connect

It would be interesting to see if others have the same issues (on Linux).

ok, I see, as a matter of normal code practice you should set all the elements of the serial port every time so when you return to the code in the future you can see without thinking about it what the code is doing.

there is no guarantee that the values will be maintained now or in the future between calls to the code.
the fact it works as expected on windows and Mac does not make that behaviour correct nor that the behaviour on linux is bad.

for consistent use between all platforms and future proofing your code readability I would strongly recommend setting all the serial port values to the values you expect them to be and not rely on luck that the compiler does it for you, it will not always correspond that the compiler does what you expect as you have found.

this is true of all controls within the system if you want to be sure all your code is consistent.

you are using API2 and yes the BAUD values are compiler constants not the serial port baud rate, something I found a bit odd at first, UNTIL I realized that you can load a combobox with all the baud rate values and when you select the value in the list its list index is the correct one for the constant, no select-case needed required to bet the baud rate needed.

glad you have a solution, but its not a bug.


You’re right I also have to set all other SerialConnection attributes before opening the connection. I’m a bit surprised the values set are not persistent. I have already worked with other environment and such things were never an issue. I was also confused on opening a modal window and some previous set values inside the modal window were gone (checkboxe, etc. reset to default).

Okay, lesson learned. Set everything at all times yourself, don’t trust the defaults.

yes, its a good thing to do and will save a whole heap of problems in the future and make your code easier to read when you go back to it in a years time!

good luck