Serial communication on Linux

Hi, I have the following code:

COM_Arduino.SerialPort = myPort 
COM_Arduino.Baud = Serial.Baud9600
COM_Arduino.Bits = Serial.Bits8
COM_Arduino.Stop = Serial.StopBits1
COM_Arduino.Parity = Serial.ParityNone

if COM_Arduino.Open Then
  COM_Arduino.Write("HUB_ON")
  COM_Arduino.Flush
  App.SleepCurrentThread(100)
  COM_Arduino.Close
Else
  MsgBox("errore")
End

This works fine on windows. On Linux, however, no. I can get it to work (I hear the noise of a hub turning on) only if I execute the line in debug, putting a breakpoint first.
I specify that an error is not thrown, but that the “write” instruction simply has no effect.

Anyone have an idea of ​​what’s wrong with it?

Hi Ant,

Does the following line also stop the Serial Port working on Linux?

If it does then your data will not be sent out.
Also, after the thread is paused for your time period, you then close the port ensuring no more data is sent.

COM_Arduino.Close

right?

Yes.

no difference without App.SleepCurrentThread(100)

Replace the line above using the command: -

COM_Arduino.XmitWait()

You can find this command in the documentation on page: -

https://documentation.xojo.com/api/hardware/serialconnection.html#serialconnection-xmitwait

This should allow all data to be sent before your command closes the com port.

hi Steven,
I tried to use XmitWait and unfortunately it still doesn’t work :frowning:

It only works if I run in debug mode, step-by-step

Hi Ant,

Sorry for my late reply but I was doing it from work and so I haven’t seen your reply until today.
Unfortunately I cannot help anymore as I don’t have a Linux machine to hand but hopefully someone who does maybe able to help you more.

Some updates: I realized that, on windows, opening and closing the serial port at each “Sub” does not give any problems. The device is not reset. On Linux, on the other hand, the device is reset at each “Open”. Therefore, the behavior is completely different, with the same code.