Set up the serial port in Wine

 Posted by:   Posted on:   Updated on:  2018-11-11T21:03:50Z

How to configure serial ports in Wine Windows compatibility layer. Access hardware COM ports from Windows application running within Linux.

The serial port is not of much use today, but there are still some things that rely on serial port communication. For example DIY microcontrollers electronics projects or some firmware updaters require connecting devices via serial port.

Another issue is that modern computers no longer have serial ports. But this can be easily solved by using a USB-to-serial adapter when you need a serial port.

Windows detects and names serial ports as COM1, COM2, COM3, etc. It doesn't make the difference between genuine ports or USB adapters. Linux on the other hand names hardware ports as /dev/ttyS0, /dev/ttyS1, /dev/ttyS2, etc. and USB adapter ports as /dev/ttyUSB0, /dev/ttyUSB1, /dev/ttyUSB2, etc.

Set up the serial port in Wine
The question is how do you map a Wine Windows serial port to a Linux device. Most answers I was able to find said you just have to add a symbolic link to the port in Wine's dosdevices directory. But when I did that, the STB firmware updater I was trying to use still didn't detect any serial port.

No serial port detected in Wine
No serial port detected in Wine
So, here is what I did to make it work. First of all, unless you want to run Wine each time as root, add yourself to the dialout group, so you can access serial ports without root permissions. This can be done from Terminal:
sudo adduser <your_username> dialout
You should log off and back in for the changes to take effect. This affects not only Wine, but all other Linux application that need serial port access.
Good news! Starting from Wine version 2.8, giving user access to serial ports is the only thing you need to do. Ports should be detected automatically.
The updated Wiki claims Wine detects ports when it is run. You should look in ~/.wine/dosdevices folder for links to tty ports. If they are missing, proceed as follows.

The first step is to make the necessary symbolic links. Again, in Terminal:
ln -s /dev/ttyUSB0 ~/.wine/dosdevices/com1
ln -s /dev/ttyS0 ~/.wine/dosdevices/com2
Adapt these commands for your situation. The first one is needed if you use a serial to USB adapter while the second one is for hardware motherboard ports. Add a symbolic link for each of the available serial ports. This command actually gives access to serial ports from Wine. And any Windows software where you can manually edit the serial port will work with only this. However many Windows apps allow user to select a port from a detected ports list. And they will detect nothing in Wine.

Now you need to add a Wine registry key as stated on Strangen0tes blog. Although you could use Wine's regedit, it is easier to launch a text editor and add the required registry key(s). In Terminal:
gedit ~/.wine/system.reg
What you should add here is not clearly known, so you should try with the following options from Wine Wiki until you find something that works.

This is the common option that works with most applications:
[Hardware\\Devicemap\\Serialcomm] 1231984861
"Serial0"="COM1"
The other one is:
[Hardware\\Devicemap\\Serialcomm] 1131331688
"COM1"="COM1"
Both worked for me. Yet there may be apps that don't read this registry key when looking for serial ports.

The association between COMx and /dev/ttyX is made in the symbolic link you made earlier.

If you use Linux and rely on a Windows only serial port application, besides virtualization, you could use Wine. If you configure it, most Windows applications will be able to detect and use the serial ports. Have you succeeded?

7 comments :

  1. Awesome worked a treat using the common option. To set com1 for Scanmaster-ELM.

    ReplyDelete
  2. Very useful, thanks for sharing. If anyone is using the PlayOnLinux frontend to Wine, the ~/.wine part of the paths above become ~/.PlayOnLinux/wineprefix/myvirtualdrivename (replace myvirtualdrivename by your actual virtual drive name)

    ReplyDelete
  3. Tried it too. Does not work yet. How to check in wine if it sees the com port? The ttyUSB0 was first on 33 (ATEN USB to serial bridge). First i did the howto on this page: http://www.goletcoin.com/2016/06/connect-aten-serial-to-usb-uc232a-on.html that worked ok. Trying to run an ESpec HUmidity control software on Ubuntu Mate.

    ReplyDelete
    Replies
    1. Things had changed in recent versions of Wine. I tested version 3 and although it automatically adds entries of all ports to registry, applications do not detect serial ports. However they can open and use them when you have the option to set any port you want (write port number in a text box).

      Delete
  4. Hi, thanks for the post, helped me immediately to resolve wine serial port availibility. I'm running on wine 3.0 (Ubuntu 3.0-1ubuntu1) and after adding a group dialout to a user and restart, I was able to access the port from wine app. The only issue I have was that the app has only visible two com ports and my USB/RS232 cable was com33. Relinking com2 in ~/.wine/dosdevices to my /dev/ttyUSB0 helps.

    Thanks again

    ReplyDelete
  5. Great! What about bluetooth device, what i need to use under wine as a serial com as well? Thanx

    ReplyDelete

Please read the comments policy before publishing your comment.