简体   繁体   中英

How to use serial port in a Mono application under Linux?

I would like to use an application under Debian, that is written in .net appearantly. I don't have the source, only the .exe file. I installed mono from the Debian repositories. The program starts and runs fine.

The program is not a complicated one, and uses serial port. (This is a car ECU programmer.)

The program seems written in a way, I can only select COM0...COM100 as serial port, seems not prepared for Linux.

Is there any way for making it work under Linux?

What I did so far, I added an udev rule (ACTION=="add" KERNEL=="ttyUSB0" NAME="COM0"), but it didn'T work.

Is there any way on operating system or on mono framework level, that would lure the program to use the /dev/ttyUSB0 by selecting "COM0" in the application itself?

Error messages in the application when trying to reach the COM0 port: "CloseObdPort: Object reference not set to an instance of an object" and then "No such file or directory"

Regards, Daniel

Check that the user is member of dialout group. You can do this using the 'groups' command.

To add a user to dialout group, you can use -: 'sudo adduser username dialout'

From memory I think you need to log out & back in to take effect.

I'm answering my own question:

The solution is surprisingly simpe: I created a symlink ./COM0 -> /dev/ttyUSB0

This way the application was looking for "COM0" in the application root, it found the symlink and managed to open the port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM