SerialConnection Baud confusion

Xojo Version 2025 R2.1
Developing on a Mac for a Linux production target.

According to the documentation the Baud rate of a SerialConnection is set by assigning one of the Baud class constants to the .Baud property.

SerialConnection1.Baud = SerialConnection.Baud4800
MessageBox(SerialConnection1.Baud.ToString)
> 6

So far so good. However when I open the port the .Baud property changes to the actual board rate.

SerialConnection1.Connect
MessageBox(SerialConnection1.Baud.ToString)
> 4800

And stays that way after the port is closed

SerialConnection1.Close
MessageBox(SerialConnection1.Baud.ToString)
> 4800

Is this the expected behaviour?
Do I have to reassign a class constant if I want to reopen the port?

I guess docs need a more clear choice of words.

Seems that what you put into Serial.Baud is just a “Xojo index” of a table, and what you read back from Serial.Baud is the real chosen Baud Rate (set and get differs)

It’s not even that consistent.

If you set .Baud and immediately read it back the class constant value is returned. It only changes to the absolute value after the port has been opened.

Clumsy work around for a clumsy behaviour

Function BaudConstant(baud)
  //return baud as a class constant
  Var BaudConstants() As Integer = Array(300, 600, 1200, 1800, 2400, _
    3600, 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 230400)

  If Baud < 300 Then
    Return baud
  Else
    Return BaudConstants.IndexOf(baud)
  End If
End

I agree. Bad consistency.

To make things worse, it does not complain about any invalid values and “connects”

What it says is “The “Baud” class constants can be used to get or set the Baud rate”, italics mine, and “can” being the operative word.

What it doesn’t explicitly state is that you can just specify the actual integer baud rate, which imo results in more readable code.

… and more intelligent comms hardware will detect the actual baud rate and set accordingly - regardless of what you select.

You can select what you like but the hardware will ignore you. This stuff was done and dusted 30 years ago.

Maybe you should revisit the OSI 7-layer model. Baud rate, 7/8 bits and start and stop bits all belong in the transport layer. It has been enshittified by those who don’t know exposing some - but not all - of the parameters at the application layer.

Another issue is the connection control codes. For this reason binary data (ie files) should be encoded as Base64 to ensure it’s safe to transmit over a serial connection without affecting the connection.

Sorry, I am old-school. Down in the bits and bytes.

Thanks Juia

I just love a good argument on the semantics of the English language. [/sarcasm]

When you say, “Doesn’t explicitly state.” What you mean is, doesn’t mention it at all :wink: