question

melonNG-6986 avatar image
0 Votes"
melonNG-6986 asked melonNG-6986 commented

How can I connect serail port in linux by .net core?

There are two serial ports in my device, I have to get data from the A port, convert and transfer it to the B port.

I want to develop it by .net core.

In the windows system there is a port name(For example COM1/COM2). I need the port name to connect to the serial port by system.io.port.

However, I don't know how to get the port name in Linux.

How can I get it? Thank you.

dotnet-csharpdotnet-iot
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SandervandeVelde42 avatar image
0 Votes"
SandervandeVelde42 answered melonNG-6986 commented

Hello @melonNG-6986 ,

Comports in Linux are typically identified as eg "/dev/ttyS0".

Perhaps you need to elevate access rights (Use this 777 for testing only) eg.:

 sudo chmod 777 /dev/ttyS0 

Note: These elevated rights then need to survive a reboot. Put them in eg. /etc/rc.local (depending on the Linux flavor you use).

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @melonNG-6986

Building on @SandervandeVelde42's response...

Debug.WriteLine(String.Join(",", SerialPort.GetPortNames()));

Should give you a list of the available serial ports.

You don't mention the platform you're using... If it's a RaspberryPI have a look at the "raspi-config" tool.

If you need some very plain sample code showing sync & async serial port programming, have a look at the "ShieldSerial" project on one of LoRaWAN module libraries

Bryn



0 Votes 0 ·

Hello @melonNG-6986 ,

Here is a GitHub project wrote in the past regarding parsing GPS information, from a serial port. My blog with background information is seen here.


0 Votes 0 ·

Yes, I am using RaspberryPI. I found this article about raspi-config:https://www.raspberrypi.com/documentation/computers/configuration.html Is it right?

0 Votes 0 ·

Thanks a lot.

0 Votes 0 ·