# [NOT COMPLETELY SOLVED]: Which serial port to talk to?

## ONEEYEMAN

Hi, ALL,

I need to make a program that will connect to some hardwatr thru the serial port.

However, when looking at the /dev I see this:

/dev/ttys0

/dev/ttyS1

/dev/ttyS2

/dev/ttyS3

/dev/ttyS4

/dev/ttyS5

WHich file I need to open? Is there any options in the kernel I need to turn on?

When I boot Windows the port I am connected to is "COM4".

Thank you.Last edited by ONEEYEMAN on Wed Mar 24, 2010 5:09 am; edited 2 times in total

----------

## eccerr0r

You could use setserial to determine mapping:

doujima:~$ sudo setserial /dev/ttyS0

/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4

I believe windows COM4 should be port 0x2e8, which usually gets mapped to /dev/ttyS3.  This of course depends if the mapping is the same, as there are only four PC/XT serial ports defined (anything past it could be anything):

COM1 /dev/ttyS0 0x3f8 IRQ4

COM2 /dev/ttyS1 0x2f8 IRQ3

COM3 /dev/ttyS2 0x3e8 IRQ4

COM4 /dev/ttyS3 0x2e8 IRQ3

----------

## ONEEYEMAN

Hi, eccerr0r,

Do I need to turn on any kernel options? I have a USB->Serial bridge, since my DELL laptop does not have serial port on its own...

Also what package I need to install in order to get "setserial"?

Thank you.

----------

## John R. Graham

```
~ # emerge -s setserial

Searching...

[ Results for search key : setserial ]

[ Applications found : 1 ]

*  sys-apps/setserial

      Latest version available: 2.17-r3

      Latest version installed: [ Not Installed ]

      Size of files: 51 kB

      Homepage:      http://setserial.sourceforge.net/

      Description:   Configure your serial ports with it

      License:       GPL-2
```

  :Razz: 

- John

----------

## eccerr0r

USB serial ports show up as /dev/ttyUSB0 etc., but setserial (sys-apps/setserial) is useless on these -- setserial is for legacy serial ports.

Since we're talking USB serials here, I don't know too much about them, I only have belkin's that seem to work with /dev/ttyUSB0, etc.

----------

## John R. Graham

Okay, you're right.  Instead, that would be, for example

```
stty -F /dev/ttyUSB0 19200
```

substituting the correct device and baud rate for your application.  That works on USB serial and legacy serial.

- John

----------

## ONEEYEMAN

 *john_r_graham wrote:*   

> 
> 
> Okay, you're right.  Instead, that would be, for example
> 
> ```
> ...

 

John,

How do I know which number to use?

I am sure that under /dev there will be:

/dev/ttyUSB0

/dev/ttyUSB1

/dev/ttyUSB2

and so on...

Thank you.

----------

## eccerr0r

If you're using udev, you will only see one /dev/ttyUSBX per serial port..

You should see each /dev/ttyUSBX get allocated in the kernel circular log (seen in dmesg) as you plug it in... so if you unplug and replug the USB, should see what device it gets assigned to in dmesg.

If you don't, you may not have compiled the driver needed.  You can try lsusb to see what/who made the adaptor, and use that to select an appropriate driver (or select all USBserial drivers).

----------

## ONEEYEMAN

Hi,

I turned on the needed kernel driver and now I see the "/dev/ttyUSB0" file.

However, when my program tried to read from this file descriptor it goes to the infinite loop.

Is there any HyperTerminal - like program that I can run and check that my device is communicating thru that port and the data is sent out?

Thank you.

P.S.: Is there any additional kernel options I need to check?

----------

## eccerr0r

I use minicom (looks like procomm/telix from dos days).  There's some x11 ones but I can't recall the names of them... Or you could use 'cu' to start a rudimentary serial session on an xterm/console/...

I could have sworn there was a 'sabayon' or something that was a x11 serial terminal emulator but I must be mistaken...

----------

## cwr

Kermit's another useful (serial) terminal program.

Will

----------

## ONEEYEMAN

Hi, ALL,

Here is my second question:

I installed "gtkterm" on my box, and when I run it it successfully connects and reads the data.

However, after compiling and running simplest test program from  here I am receiving EAGAIN error.

Any idea how to always get the data as in the "gtkterm"?

Thank you.

----------

