Ubuntu Usb Serial Port

The commands and steps described in this article have been run on an Ubuntu 18.04 LTS system. How to mount a USB drive on Ubuntu. Let us follow these steps to mount a USB drive manually to your system: Step1: Plug in the USB drive to an available port. On Windows, COM ports are named COM1 through COM256. On Linux, serial devices can have arbitrary names but are typically character devices with a major number of 4 and a minor number from 64 to 256 represented by /dev/ttyS0 through /dev/ttyS191. By default init will populate this mapping using the mknod system call.

Active3 months ago

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 Mortensen
14.5k19 gold badges89 silver badges118 bronze badges
codingJoecodingJoe
1,6468 gold badges37 silver badges56 bronze badges

10 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.

MatejMatej
1,1441 gold badge11 silver badges24 bronze badges

You 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 Mortensen
14.5k19 gold badges89 silver badges118 bronze badges
McPartyMcParty

The 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.

EkimEkim

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.

RomanRoman

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 or dmesg | 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.

Sam GreadlySam Greadly

I get get the same minicom error, 'cannot open /dev/ttyUSB0: No such file or directory'

Three notes:

  1. 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.

  2. I have to run as super user (i.e. sudo minicom)

  3. 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 Mortensen
14.5k19 gold badges89 silver badges118 bronze badges
MaxMax

I 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.

Peter Mortensen
14.5k19 gold badges89 silver badges118 bronze badges
Joshua EtienneJoshua Etienne

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

gatorbackgatorback
2391 gold badge4 silver badges24 bronze badges

I 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 Mortensen
14.5k19 gold badges89 silver badges118 bronze badges
DexterIsMyHeroDexterIsMyHero

Putty 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.

Nikhil ParasharNikhil Parashar

Not the answer you're looking for? Browse other questions tagged linuxserial-portusbhardware-interface or ask your own question.

Active1 year ago

What is the proper way to get a list of all available serial ports/devices on a Linux system?

In other words, when I iterate over all devices in /dev/, how do I tell which ones are serial ports in the classic way, that is, those usually supporting baud rates and RTS/CTS flow control?

The solution would be coded in C.

I ask because I am using a third-party library that does this clearly wrong: It appears to only iterate over /dev/ttyS*. The problem is that there are, for instance, serial ports over USB (provided by USB-RS232 adapters), and those are listed under /dev/ttyUSB*. And reading the Serial-HOWTO at Linux.org, I get the idea that there'll be other name spaces as well, as time comes.

So I need to find the official way to detect serial devices. The problem is that none appears to be documented, or I can't find it.

I imagine one way would be to open all files from /dev/tty* and call a specific ioctl() on them that is only available on serial devices. Would that be a good solution, though?

Update

hrickards suggested to look at the source for 'setserial'.Its code does exactly what I had in mind:

First, it opens a device with:

Then it invokes:

If that call returns no error, then it's a serial device, apparently.

I found similar code in Serial Programming/termios, which suggested to also add the O_NOCTTY option.

There is one problem with this approach, though:

When I tested this code on BSD Unix (that is, Mac OS X), it worked as well. However, serial devices that are provided through Bluetooth cause the system (driver) to try to connect to the Bluetooth device, which takes a while before it'll return with a timeout error. This is caused by just opening the device. And I can imagine that similar things can happen on Linux as well - ideally, I should not need to open the device to figure out its type. I wonder if there's also a way to invoke ioctl functions without an open, or open a device in a way that it does not cause connections to be made?

Linux list serial ports

What should I do?

Thomas Tempelmann
Thomas TempelmannThomas Tempelmann
6,3523 gold badges52 silver badges99 bronze badges

11 Answers

The /sys filesystem should contain plenty information for your quest. My system (2.6.32-40-generic #87-Ubuntu) suggests:

Which gives you descriptions of all TTY devices known to the system. A trimmed down example:

Following one of these links:

Here the dev file contains this information:

This is the major/minor node. These can be searched in the /dev directory to get user-friendly names:

The /sys/class/tty dir contains all TTY devices but you might want to exclude those pesky virtual terminals and pseudo terminals. I suggest you examine only those which have a device/driver entry:

A.H.A.H.
48.9k11 gold badges72 silver badges102 bronze badges

In recent kernels (not sure since when) you can list the contents of /dev/serial to get a list of the serial ports on your system. They are actually symlinks pointing to the correct /dev/ node:

This is a USB-Serial adapter, as you can see. Note that when there are no serial ports on the system, the /dev/serial/ directory does not exists. Hope this helps :).

Ubuntu Usb Serial Port
flu0flu0

I'm doing something like the following code. It works for USB-devices and also the stupid serial8250-devuices that we all have 30 of - but only a couple of them realy works.

Basically I use concept from previous answers. First enumerate all tty-devices in /sys/class/tty/. Devices that does not contain a /device subdir is filtered away. /sys/class/tty/console is such a device. Then the devices actually containing a devices in then accepted as valid serial-port depending on the target of the driver-symlink fx.

and for ttyS0

All drivers driven by serial8250 must be probes using the previously mentioned ioctl.

Only port reporting a valid device-type is valid.

The complete source for enumerating the serialports looks like this. Additions are welcome.

Søren HolmSøren Holm

I think I found the answer in my kernel source documentation:/usr/src/linux-2.6.37-rc3/Documentation/filesystems/proc.txt

Here is a link to this file:http://git.kernel.org/?p=linux/kernel/git/next/linux-next.git;a=blob_plain;f=Documentation/filesystems/proc.txt;hb=e8883f8057c0f7c9950fa9f20568f37bfa62f34a

mk2mk2
user6655984
RealHuman75RealHuman75

setserial with the -g option appears to do what you want and the C source is available at http://www.koders.com/c/fid39344DABD14604E70DF1B8FEA7D920A94AF78BF8.aspx.

hrickardshrickards
5812 gold badges6 silver badges20 bronze badges

I have no serial device here to test it, but if you have python and dbus you can try it yourself.

If it fails you can search inside hwmanager_i.GetAllDevicesWithProperties() to see if the capability name 'serial' that I just guessed has a different name.

HTH

baolbaol

I do not have a USB serial device, but there must be a way to find the real ports using the HAL libraries directly:

The posted python-dbus code nor this sh script lists the bluetooth /dev/rfcomm* devices, so it is not the best solution.

Note that on other unix platforms, the serial ports are not named ttyS? and even in linux, some serial cards allow you to name the devices. Assuming a pattern in the serial devices names is wrong.

kelk1kelk1

Using /proc/tty/drivers only indicates which tty drivers are loaded. If you're looking for a list of the serial ports check out /dev/serial, it will have two subdirectories: by-id and by-path.

EX:

Thanks to this post: https://superuser.com/questions/131044/how-do-i-know-which-dev-ttys-is-my-serial-port

Community
blarfblarf

Ubuntu Find Usb Serial Port

My approach via group dialout to get every tty with user 'dialout'ls -l /dev/tty* | grep 'dialout'to only get its folderls -l /dev/tty* | grep 'dialout' | rev | cut -d ' ' -f1 | rev

Port

easy listen to the tty output e.g. when arduino serial out:head --lines 1 < /dev/ttyUSB0

listen to every tty out for one line only:for i in $(ls -l /dev/tty* | grep 'dialout' | rev | cut -d ' ' -f1 | rev); do head --lines 1 < $i; done

I really like the approach via looking for drivers:ll /sys/class/tty/*/device/driver

You can pick the tty-Name now:ls /sys/class/tty/*/device/driver | grep 'driver' | cut -d '/' -f 5

McPepprMcPeppr

The serial communication manager library has many API and features targeted for the task you want. If the device is a USB-UART its VID/PID can be used. If the device is BT-SPP than platform specific APIs can be used. Take a look at this project for serial port programming: https://github.com/RishiGupta12/serial-communication-manager

Ubuntu Usb Serial Port Driver

samuel05051980samuel05051980

Ubuntu Show Usb Serial Ports

Not the answer you're looking for? Browse other questions tagged linuxserial-port or ask your own question.