Realbasic Serial Communication Linux
Hardware components | |||||
| × | 1 | |||
| × | 1 | |||
Software apps and online services | |||||
| |||||
| |||||
| |||||
|
Xojo is a development tool for creating powerful, native applications for desktop, web, iOS, and Raspberry Pi. Xojo offers Xojo Cloud for easy, secure, maintenance-free web app hosting. The i.MX boards can communicate with a host server (Windows® OS or Linux OS) using a serial cable. Common serial communication programs such as HyperTerminal, Tera Term, or PuTTY can be used. The example below describes the serial terminal setup using HyperTerminal on a host running Windows OS.
Story
Story
.NET Core 3.0 has just got its preview release on Jan 2019. As what Microsoft said in their documentation, System.IO.Ports.SerialPort is now supported on Linux. I cannot wait to dirty my hand with it. In this article, I will show you how to do serial read/write with System.IO.Ports.SerialPort and how you can build the source code on Windows and run the binary on linux-arm (Raspbian).
Note
- By the time I write this article, .NET Core and System.IO.Ports are on preview, when you read this article, do check if there are any new releases. Run your code with the latest stable release.
- I build and test the codes of this article on Windows 10 and run them in Raspberry Pi Raspbian. If you are using Mac/Linux as development machine, SerialPort library should also work.
Development Setup
1. Download and install.NET Core 3.0 SDK (Not Runtime) on you development machine. After installation, open terminal and type dotnet --version
. You should see a dotnet version like 3.0.x.
2. Install Visual Studio Code as C# code editor. Then install C# extension.
3. Install.NET Core on Raspberry pi. If you want to build C# code on development machine and run the binary on PI, you just need to install .NET Runtime
. If you want to build and run the source code on PI, you need to install .NET SDK
which also includes.Net Runtime. Do note you should use the linux arm32
build for your PI. For simplicity, I will show you how to install.NET Core SDK on PI:
After installation, verify with dotnet --info. You should see installation info like this:
4. Prepare any serial enabled device to receive and send serial messages. For me it is an Arduino Uno.
Hello SerialPort
After setting up development tools, let's start our journey with a simple C# project which will print all the serial ports available.
On your dev machine, start a dotnet project with following commands:
Open program.cs file, replace content with following code:
Type dotnet run
to run the code on dev machine.
To build your project for RPi, run:
then go to {your_project_root}binDebugnetcoreapp3.0linux-arm
, copy folder publish
to your PI. On Pi, go to the publish folder, run:
Your hello-serialport is running on Rapsberry Pi!
.NET Core Application Deployment
In the hello serialport project, we did the development on windows, build the linux-arm binary then run the binary on raspberry pi. According to Microsoft's documentation, we just made an Framework-dependent executable(FDE) which means the executable can only run on raspberry pi with proper version.NET Core Runtime installed.
You can play with different kind of deployment by referring following documents:
Serial Read
Open Arduino IDE, go to File-->Examples-->03.Analog-->AnalogInOutSerial and upload it to Arduino. Paste the code here:
This program keep sending out the reading of analog pin. Let's write a C# program to read the message:
Build and run on Raspberry Pi:
One thing to mention is that SerialPort.ReadLine() is a blocking method. If you don't want main thread be blocked, please use multithreading.
please refer to the example provided by Microsoft to learn how to do serial write and multithreading. Serial Events are also good things to explore.
Further Work
- ASP.NET Core is available since v1 of.NET Core. By combining SerialPort API and ASP.NET, we can build a web UI to control some devices like a mobile robot.
- Microsoft open sourced WPF and WinForms which would all be available since.NET Core 3.0. One day we may safely port our old windows desktop serial applications to all platforms or even write a winForm serial communication application on Raspberry Pi!
References
[1] Installing the.NET Core 2.x SDK on a Raspberry Pi and Blinking an LED with System.Device.Gpio. URL: https://www.hanselman.com/blog/InstallingTheNETCore2xSDKOnARaspberryPiAndBlinkingAnLEDWithSystemDeviceGpio.aspx
Read moreSchematics
Leon Song
I am trying to connect minicom to a serial device that is connected via a USB-to-serial adapter. This is a PL2303 and from everything I've read no additional drivers are required. The device is recognised as a PL2303.
I'm a beginner at minicom. Is this the correct command to execute? Or do I need to configure something?
Peter Mortensen10 Answers
First check with dmesg grep tty
if system recognize your adapter.Then try to run minicom with sudo minicom -s
, go to 'Serial port setup' and change the first line to /dev/ttyUSB0
.
Don't forget to save config as default with 'Save setup as dfl'. It works for me on Ubuntu 11.04 on VirtualBox.
MatejMatejYou will need to set the permissions every time you plug the converter in.I use PuTTY to connect. In order to do so, I have created a little Bash script to sort out the permissions and launch PuTTY:

P.S. I would never recommend that permissions are set to 777.
Peter MortensenThe serial port communication programs moserial
or gtkterm
provide an easy way to check connectivity and modify /dev/ttyUSB0
(or /dev/ttyUSB1
!) settings. Even though there maybe only a single USB to RS232 adapter, the n
designation /dev/ttyUSBn
can and does change periodically! Both moserial
and gtkterm
will show what port designation is relevant in their respective pull down menus when selecting an appropriate port
to use.
Check out help.ubuntu.com/community/Minicom for details on minicom
.
I had fix this with adduser *username* dialout
. I never had this error again, even though previously the only way to get it to work was to reboot the PC or unplug and replug the usb to serial adapter.
I get get the same minicom error, 'cannot open /dev/ttyUSB0: No such file or directory'
Three notes:
I get the error when the device attached to the serial port end of my Prolific Technology PL2303 USB/Serial adapter is turned off. After turning on the device (an embedded controller running Linux) minicom connected fine.
I have to run as super user (i.e.
sudo minicom
)Sometimes I have to unplug and plug back in the USB-to-serial adapter to get minicom to connect to it.
I am running Ubuntu 10.04 LTS (Lucid Lynx) under VMware (running on Windows 7). In this situation, make sure the device is attached to VM operating system by right clicking on the USB/Serial USB icon in the lower right of the VMware window and select Connect (Disconnect from Host).
Remember to press Ctrl + A to get minicom's prompt, and type X to exit the program. Just exiting the terminal session running minicom will leave the process running.
Peter MortensenI had the exact same problem, and it was fixed by doing a chmod 777 /dev/ttyUSB0
. I never had this error again, even though previously the only way to get it to work was to reboot the VM or unplug and replug the USB-to-serial adapter. I am running Ubuntu 10.04 (Lucid Lynx) VM on OS X.
Long time reader, first time helper ;)
I'm going through the same hellish
experience here with a Prolific USB <> Serial adapter and so far Linux is the easiest to get it to work.
On CentOS, I didn't need to install any drivers etc. That said,
dmesg grep -i tty
ordmesg grep -i usb
showed me /dev/ttyUSB0.screen ttyUSB0 9600
didn't do the trick for me like it did in OSX- minicom is new to me but it was complaining about lack of /dev/modem

However, this helped: https://www.centos.org/forums/viewtopic.php?t=21271
So install minicom (yum install minicom
) then enter its settings (minicom -s
).
Then select Serial Port Setup
and change the Serial Device (Option A) to /dev/ttyUSB0, or whatever your device file is as it slightly differs per distro.
Then change the Bps (Option E) to 9600 and the rest should be default (8N1 Y N)
Save as default, then simply minicom
and Bob's your uncle.
HTH.
I suggest that newbies connect a PL2303 to Ubuntu, chmod 777 /dev/ttyUSB0 (file-permissions) and connect to a CuteCom serial terminal. The CuteCom UI is simple intuitive. If the PL2303 is continuously broadcasting data, then Cutecom will display data in hex format
gatorbackRealbasic Serial Communication Linux Free
gatorbackI just got my GUC232A cable with a molded-in PL2302 converter chip.
In addition to adding myself and br to group dialout
, I found this helpful tip in the README.Debian file in /usr/share/doc/bottlerocket
:
This package uses debconf to configure the /dev/firecracker symlink, should you need to change the symlink in the future run this command:
dpkg-reconfigure -pmedium bottlerocket
That will then prompt you for your new serial port and modify the symlink. This is required for proper use of bottlerocket.
I did that and voila! bottlerocket is able to communicate with my X-10devices.
Peter MortensenPutty on ubuntuThere is no need to install the driver for PL2303So only type the command to enable the puttySudo chmod 666 /dev/ttyUSB0DoneOpen the putty.