- Home /
Serial communication on Linux works using mono, but not inside of Unity
Hi,
I am having some trouble with serial communication on Linux. I am trying to send and receive information between an arduino and Unity. I suspect that it might be a Linux permission thing, but it might also be some Unity setting that I have missed. I already added the Linux user to the dialout group as per instructions on the Arduino website, and I made sure to select .NET 4.x in the Unity project settings. The serial communication is actually working when I compile and run the following C# using mono, outside of Unity:
using System.IO.Ports;
sp = new SerialPort("/dev/ttyACM0", 9600);
sp.Open();
However, the same code in Unity at run-time tells me:
IOException: No such file or directory
The frustrating thing is that this is actually working on another Linux machine and I am having trouble understanding what the difference could be that is causing it not to work on the other.
Here are some differences on both systems:
The working Linux is Lubuntu 19 with the Unity installation inside of /home, which is on the same partition as root. The Unity version is 2019.2.
The non-working system is Linux Mint 19.3 with the Unity installation also in /home, but this is a different partition from root. The Unity version is 2019.3.
The permissions look slightly different too:
crw-rw----+ 1 root dialout 166, 0 mei 1 05:08 /dev/ttyACM0 --> Lubuntu
crw-rw---- 1 root dialout 166, 0 May 1 15:03 /dev/ttyACM0 --> Mint
Also:
getfacl /dev/ttyACM0
gives me the following on Lubuntu (working):
# file: dev/ttyACM0
# owner: root
# group: dialout
user::rw-
user:myname:rw-
group::rw-
mask::rw-
other::---
and the following on Linux Mint (not working):
# file: dev/ttyACM0
# owner: root
# group: dialout
user::rw-
group::rw-
other::---
Does anyone have any insight into why in one scenario Unity can't access /dev/ttyACM0, while in the other one it can? Or any idea's how I might find out? (Also, I wanted to test this out with the same 2019.2 Unity version, but for some reason my Unity Hub does not want to load any archived installation).
Answer by thijsbs · May 02, 2020 at 08:53 PM
I finally found the culprit. Apparently the Unity Hub launcher was recently changed to a sandboxed version using flatpak, and for some reason /dev is blacklisted by default. To get around this, Unity Hub should be launched with the parameter:
--device=all
The entire command to get this to work for me is:
/usr/bin/flatpak run --branch=stable --arch=x86_64 --device=all --command=start-unityhub com.unity.UnityHub
Your answer
Follow this Question
Related Questions
Unity - IOException: SerialPort.Open() 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
open C# scripts on Linux in native monodevelop 1 Answer
Can't auto find Arduino without crashing 0 Answers