# Serial (RS232) communication is one-way

## anroy

I need to use my Gentoo machine to obtain data from an external instrument via a 9-pin serial port.  Very old stuff.

It was not working, so I have been trying to diagnose the problem.

I bought a cable that is called a "cross cable" in Japan (where I am located), I think this corresponds to what is called a "null-modem cable" in America.  Both ends are female, and it is used to directly connect 2 PCs.

So here is the setup:

PC-1: Gentoo OS

PC-2: Has partitions for both Windows XP and Xandros Linux.

I installed Minicom on PC-1

On PC-2, in Xandros I also installed Minicom.  In the Windows side I use Hyper Terminal.

I connected the PCs, started up the terminal programs on both boxes, and would type messages such as "Hello World".

Whether I used Xandros or Windows on PC-2, the result was always the same: I could send messages from PC-1 and it would show up in the terminal program of PC-2, however the other way round never worked.  Nothing I ever typed in PC-2 showed up in PC-1.

On both machines I checked the serial port permissions.  The Xandros machine result was as below.

```

# ls -l /dev/ttyS0

crw-rw-rw- 1 root tty 4, 64 Aug 24 16:31 /dev/ttyS0
```

However in the case of the Gentoo machine, the permissions were as follows:

crw-rw----

I set them to crw-rw-rw- using chmod, to be the same as the Xandros setting.  It didn't help anything.

Grasping for straws, I even disconnected the cross cable from the computers, and reconnected reversing the ends.  Still no luck.

Is it possible that the Gentoo OS is set up in such a way that it can send from the serial port and not receive?  Does this kind of thing happen?    :Embarassed:  Does anyone know where I should look next?

(As for the possibility that the problem lies in PC-2, in that it can receive and not send, well, I am disinclined to think that since the results were the same whether or not the OS was Xandros or Windows.  Mind you, whether it is running Xandros or Windows, it is still the same box and consequently using the same physical serial port)

----------

## eccerr0r

Instead of just inclining to think, try shorting pin 2 and 3 on each system with no flow control and see if data loops back to the machine. 

If both work, then your cable is bad.

Whichever one doesn't work, quite possibly is an interrupt problem/conflict for receiving.

----------

## anroy

 *eccerr0r wrote:*   

> Instead of just inclining to think, try shorting pin 2 and 3 on each system with no flow control and see if data loops back to the machine. 
> 
> If both work, then your cable is bad.

 

I will try this later, thanks.

If this "looping back" works, how would that appear to me?  For example if I type "Hello World" in minicom, would "Hello World" then be displayed on the next line, or somewhere nearby?  If it gets displayed in the same spot where I am typing it may be hard to tell if the displayed text is the loop back or my own typing... however turning local echo off would solve that by not displaying my own typing, right?  (sorry, I'm a total newbie at this stuff)

 *eccerr0r wrote:*   

> Whichever one doesn't work, quite possibly is an interrupt problem/conflict for receiving.

 

I tend to suspect this is the issue, rather than the cable.

This whole investigation started because the Gentoo machine was not receiving data from an external instrument I had connected to it.  That was a different serial cable (one end of that cable was built right in to the instrument).  I'd think the probability that both cables are bad is low (but of course not zero).

Another piece of info (and changing the topic from cables): The Gentoo machine at my client's site also fails to get data from that instrument (this was really where it all started, and the problem was passed on to me).  This at least indicates that the problem is not in the physical port hardware, since we are talking about two seperate Gentoo PCs.

My client built my Gentoo PCs for me using a HDD image from his machine.  So my kernel and software configuration is the same as his... so I suspect the that the problem lies here.

Does anyone have any idea on how to investigate if there is an interrupt problem/conflict for receiving... or even pointers to what I need to read/study to better understand what that means?  Is that a kernel topic?  I'm an experienced programmer but I've never done anything low-level and possess at best a nebulous grasp of what interrupts are.

----------

## eccerr0r

If you have local echo off, typing on the terminal emulator program will print out what you type.

If in local echo mode, you'll see two of each character show up. HHeelllloo  WWoorrlldd

If it's the interrupt conflict that you're suspecting, start looking in /proc/interrupts.

However if this is not an ISA bus system I'd probably start looking elsewhere, unless you're using something like lirc or something that potentially takes over the serial port (IRDA, etc.).

----------

## anroy

I have narrowed things down to where I realize I am getting the following.

If I run the following command on the Gentoo machine (PC-1):

cat /proc/tty/driver/serial

I get, along with the number of bytes transfered by rx and tx, the output "fe:2", which I assume means two frame errors.

The rx figure is correct in that it jives with the number of bytes I sent from PC-2... this indicates that the Gentoo machine IS receiving data.  However the fe:2 means that it is not detecting the stop bits, and this is preventing it from displaying output text in minicom.

I have checked and rechecked that all the settings (bit rate, parity etc) all match on both machines.  I am wondering if there is some factor in the kernel that is making it not recognize the stop bit.  I have had other indications as well that a stop bit or a terminator is not being detected (long story).  What are some possible causes?  (e.g. the OS is doing too much interrupting or not enough?)

----------

## eccerr0r

You do have flow control disable?  Just making sure...

I recall having some strange issues when flow control is enabled and the rest of the system doesn't match.

----------

## anroy

 *eccerr0r wrote:*   

> If you have local echo off, typing on the terminal emulator program will print out what you type.
> 
> If in local echo mode, you'll see two of each character show up. HHeelllloo  WWoorrlldd
> 
> If it's the interrupt conflict that you're suspecting, start looking in /proc/interrupts.
> ...

 

I did

```
# cat /proc/interrupts
```

What should I specifically look for?  I see a line that says

```
4: 243 IO-APIC-edge serial
```

among many other lines.

I am not sure if this is an ISA bus system... is that something really old?  Also what is lirc and IRDA... will Google them but your insight as to what they do to a serial port would be helpful.

Thanks!

(By the way, I've always had flow control off)

----------

## linuxtuxhellsinki

 *anroy wrote:*   

> I am not sure if this is an ISA bus system... is that something really old?
> 
> 

 

Yes (~Pentium I / II).

 *anroy wrote:*   

> 
> 
>   Also what is lirc and IRDA... will Google them but your insight as to what they do to a serial port would be helpful.
> 
> 

 

=Infrared, it usually uses the same IRQ and stuff as COM2 if I remember correctly.

----------

## anroy

OK...

I have come to the conclusion that there is something fishy about the

serial driver in Gentoo.  Below I describe the tests that led me to

this conclusion.

I conducted a series of chat tests between 2 machines, PC-1 and PC-2,

using terminal software on both machines and connected the serial

ports of the PCs using an RS232 cross cable (this may be called a NULL

modem cable in some regions).

PC-1 has Gentoo Linux installed.  PC-2 has 3 partitions: Windows XP,

Windows 2000, and Xandros Linux.

The terminal software used was Minicom on Gentoo, and HyperTerminal on

Windows.

The connection settings on both sides were as follows.

-------------------

Bit rate: 9600

Data size: 8 bit

Parity: none

Stop bits: 1

Flow control: none

In short form: 9600, 8N1

-------------------

I tested to see if text typed in the terminal of one machine properly

showed up in the other machine or not.  I also made use of the

following Linux (Unix) command to view the number of bytes sent (tx)

and received (rx):

# cat /proc/tty/driver/serial

Here are my test results

(1) Gentoo Linux and Windows XP

PC-1: Ran Gentoo Linux off HDD, used Minicom

PC-2: Ran Windows XP off HDD partition, used HyperTerminal

Results:

FAILURE  :Sad: 

Text typed on PC-1 is correctly displayed on PC-2.  However text typed

on PC-2 is NOT displayed on PC-1.

Using # cat /proc/tty/driver/serial on PC-1, I could see that the

number of received bytes was increasing correctly.  So the bytes from

PC-2 are being received, just not showing up in Minicom.

(2) Gentoo Linux and Windows 2000

PC-1: Ran Gentoo Linux off HDD, used Minicom

PC-2: Ran Windows 2000 off HDD partition, used HyperTerminal

Results:

FAILURE  :Sad: 

Exactly the same results as in test (1).

(3) Gentoo Linux and Xandros Linux

PC-1: Ran Gentoo Linux off HDD, used Minicom

PC-2: Ran Xandros Linux off HDD partition, used Minicom

Results:

FAILURE  :Sad: 

Exactly the same results as in test (1).

... Now at this point, if you are starting to suspect a hardware issue

on PC-1, this is where things get interesting and I prove this is not

the case!

(4) Knoppix Linux and Xandros Linux

PC-1: Ran Knoppix Linux off a live CD, used Minicom

PC-2: Ran Xandros Linux off HDD partition, used Minicom

Results:

SUCCESS!!!   :Smile: 

Everything typed on one machine shows up in the other machine's

terminal.  This indicates that the hardware on PC-1 is fine.

(5) Ubuntu Linux and Xandros Linux

PC-1: Ran Ubuntu Linux off a live CD, used Minicom

PC-2: Ran Xandros Linux off HDD partition, used Minicom

Results:

SUCCESS!!!   :Smile: 

Results identical to test (4) above.

... Now, to make sure that it is not a problem with the way I have

installed Gentoo, I used a live CD version of Gentoo from the CD

enclosed in a recent book, Linux Bible 2007 Edition, which should have

much more credibility than my own installation (since I am a newbie,

and those guys are authors).  In fact, here is the book:

http://www.amazon.com/Linux-Bible-2007-KNOPPIX-Distributions/dp/0470082798/

(5) Gentoo Linux from live CD and Xandros Linux

PC-1: Ran Gentoo Linux off a live CD, used Minicom

PC-2: Ran Xandros Linux off HDD partition, used Minicom

Results:

FAILURE  :Sad: 

Results identical to test (1) above.  So the live CD Gentoo is

behaving the same way as my own Gentoo installation.

(6) Gentoo Linux and Windows 2000, on seperate machines at my client's

site.

FAILURE  :Sad: 

I asked my client to do exactly what I did in test (2) above, using

their machines.  The results were exactly the same as my test (2)

results, which further reinforce the probability that I don't have a

hardware problem and that my Gentoo installation is not the problem.

So this leaves me with the conclusion that there is something flawed

in Gentoo itself.

I am not very knowledgeable about serial drivers.  I would like to

compare the serial driver versions between my Gentoo machine and my

Xandros machine (as well as the versions of the serial drivers in the

live CD Knoppix and Ubuntu).  Does anyone know what specific files I

need to look at and compare?

Also, does anyone have any idea as to how I should go about solving

this problem?  I need to have proper serial data receive functionality

on my Gentoo machine, since that will be used to get data from a

measuring instrument.

Thanks!

----------

## Bojan

Can you post the result of:

```
cat /etc/inittab | grep -e ttyS
```

on your Gentoo machine?

----------

## anroy

 *Bojan wrote:*   

> Can you post the result of:
> 
> ```
> cat /etc/inittab | grep -e ttyS
> ```
> ...

 

Here it is:

```
#s0:12345:respawn:/sbin/agetty 9600 ttyS0 vt100

#s1:12345:respawn:/sbin/agetty 9600 ttyS1 vt100
```

Sorry I wasn't able to get it to you earlier.

----------

## Bojan

And you've (most probably) got the solution to your problem.

Uncomment a single or both lines.

You can also edit it a bit to adjust speed and welcome message etc.

Quick googling gives a nice howto:

http://www.vanemery.com/Linux/Serial/serial-console.html

----------

## Stever

 *Quote:*   

> Uncomment a single or both lines

 

That will enable a login on the serial port, which is not what they wanted.

I'm not sure what is wrong with your setup, but it is not a gentoo-wide problem.  I can use minicom on gentoo to communicate in both directions with another PC through null-modem cable without any problems.  This is with /dev/ttyS0, 115,200 8N1 and hardware flow control enabled, on an old PII box.

----------

## sng613

 *Stever wrote:*   

>  *Quote:*   Uncomment a single or both lines 
> 
> That will enable a login on the serial port, which is not what they wanted.
> 
> I'm not sure what is wrong with your setup, but it is not a gentoo-wide problem.  I can use minicom on gentoo to communicate in both directions with another PC through null-modem cable without any problems.  This is with /dev/ttyS0, 115,200 8N1 and hardware flow control enabled, on an old PII box.

 

What did you do to make it work? did you use setserial ?

----------

