# Serial communication on Linux

**URL:** <https://forum.xojo.com/t/serial-communication-on-linux/66053>\
**Category:** Linux\
**Created:** [October 12, 2021, 1:52pm UTC](https://forum.xojo.com/t/serial-communication-on-linux/66053 "2021-10-12T13:52:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ant\_Col](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/c0e974/32.png) [@Ant\_Col](https://forum.xojo.com/u/Ant_Col)\
**Post date:** [October 12, 2021, 1:52pm UTC](https://forum.xojo.com/t/serial-communication-on-linux/66053/1 "2021-10-12T13:52:45Z")

</div>

Hi, I have the following code:

```auto
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?

---

<div class="post-metadata">

**Author:** ![Steven\_Hughes](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@Steven\_Hughes](https://forum.xojo.com/u/Steven_Hughes)\
**Post date:** [October 14, 2021, 6:39am UTC](https://forum.xojo.com/t/serial-communication-on-linux/66053/2 "2021-10-14T06:39:10Z")

</div>

Hi Ant,

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

> [@Ant\_Col](#):
>
> `App.SleepCurrentThread(100)`

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.

---

<div class="post-metadata">

**Author:** ![Ant\_Col](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/c0e974/32.png) [@Ant\_Col](https://forum.xojo.com/u/Ant_Col)\
**Post date:** [October 14, 2021, 10:40am UTC](https://forum.xojo.com/t/serial-communication-on-linux/66053/3 "2021-10-14T10:40:46Z")

</div>

> [@Steven\_Hughes](#):
>
> Also, after the thread is paused for your time period, you then close the port ensuring no more data is sent.

```auto
COM_Arduino.Close

```

right?

---

<div class="post-metadata">

**Author:** ![Steven\_Hughes](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@Steven\_Hughes](https://forum.xojo.com/u/Steven_Hughes)\
**Post date:** [October 14, 2021, 10:59am UTC](https://forum.xojo.com/t/serial-communication-on-linux/66053/4 "2021-10-14T10:59:14Z")

</div>

> [@Ant\_Col](#):
>
> `COM_Arduino.Close`

Yes.

---

<div class="post-metadata">

**Author:** ![Ant\_Col](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/c0e974/32.png) [@Ant\_Col](https://forum.xojo.com/u/Ant_Col)\
**Post date:** [October 14, 2021, 12:30pm UTC](https://forum.xojo.com/t/serial-communication-on-linux/66053/5 "2021-10-14T12:30:23Z")

</div>

no difference without `App.SleepCurrentThread(100)`

---

<div class="post-metadata">

**Author:** ![Steven\_Hughes](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@Steven\_Hughes](https://forum.xojo.com/u/Steven_Hughes)\
**Post date:** [October 15, 2021, 6:08am UTC](https://forum.xojo.com/t/serial-communication-on-linux/66053/6 "2021-10-15T06:08:57Z")

</div>

> [@Ant\_Col](#):
>
> `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](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.

---

<div class="post-metadata">

**Author:** ![Ant\_Col](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/c0e974/32.png) [@Ant\_Col](https://forum.xojo.com/u/Ant_Col)\
**Post date:** [October 15, 2021, 7:41am UTC](https://forum.xojo.com/t/serial-communication-on-linux/66053/7 "2021-10-15T07:41:45Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Steven\_Hughes](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@Steven\_Hughes](https://forum.xojo.com/u/Steven_Hughes)\
**Post date:** [October 18, 2021, 5:41am UTC](https://forum.xojo.com/t/serial-communication-on-linux/66053/8 "2021-10-18T05:41:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ant\_Col](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/c0e974/32.png) [@Ant\_Col](https://forum.xojo.com/u/Ant_Col)\
**Post date:** [October 18, 2021, 1:14pm UTC](https://forum.xojo.com/t/serial-communication-on-linux/66053/9 "2021-10-18T13:14:06Z")

</div>

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.
