Tech Support > Computers & Technology > Programming > writing to serial port - where's the device?
writing to serial port - where's the device?
Posted by tj on August 25th, 2003


I've written a program to communicate to a widget connected via a serial
port. I'm certain that I'm missing something so basic, that I can't find
the documentation for it.

I have my widget connected to the one and only serial port on the back of my
laptop. I have a contemporary PnP bios, a recent version of linux.

Questions:
How do I know which comm port is the physical one on the back of the laptop?
Do I need to run setserial or something manually?
Using the code below, I've opened each of the four ports, and get no
errors... although I can't get any widgets to respond

I've read all the serial and modem HOWTOs...and understand about determining
which IRQ, IO PORT, etc... but I don't think its the problem. I want to
know how to specifically communicate with the one on the back of the
laptop. I know I have a built in WinModem, and I can't seem to identify
which port its "using" in order to avoid that port if necessary.

Here's a routine that always returns success (pCommPort is always = 3?!)

int intCommPortOpen(int intCommPort){
printf ("Comm port:\t %s\n", tty_ports[intCommPort]);
pCommPort = open(tty_ports[intCommPort], O_RDWR | O_NOCTTY | O_NDELAY);
if (pCommPort == -1){
printf("Comm port:\t failed opening ttyS%d rc = %d\n",
intCommPort, pCommPort);
return (pCommPort);
}else{
printf("Comm port:\t open %d\n", pCommPort);
fcntl(pCommPort, F_SETFL, 0);
return (0);
}
}

$> setserial
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: 16550A, Port: 0x02f8, IRQ: 3
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

Thanks,
TJ

Posted by Derk Gwen on August 26th, 2003


tj <tj@getlostspammer.com> wrote:
# I've written a program to communicate to a widget connected via a serial
# port. I'm certain that I'm missing something so basic, that I can't find
# the documentation for it.
#
# I have my widget connected to the one and only serial port on the back of my
# laptop. I have a contemporary PnP bios, a recent version of linux.
#
# Questions:
# How do I know which comm port is the physical one on the back of the laptop?

If it's not obviously labelled, then I plug the serial ports into things like
a terminal or some other known equipment, and then just trying reading and writing
to each device until I get some kind of response.

# Do I need to run setserial or something manually?
# Using the code below, I've opened each of the four ports, and get no
# errors... although I can't get any widgets to respond

Once the device is properly defined, I dont't have to do anything else
but open the right /dev/* and then configure the device with stty or ioctl
or the equivalent.

You can look up 'man 4 tty' perhaps to get the ioctl functions to change the
speed, parity, and so on. The two ends of a serial cable cannot directly
specify the line characteristics.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
If you plan to shoplift, let us know.
Thanks

Posted by Jens.Toerring@physik.fu-berlin.de on August 26th, 2003


tj <tj@getlostspammer.com> wrote:
Are you sure about the ttyS1 and ttyS2? According to what you posted
before:

I guess you mean ttyS0 and ttyS1. And usually the serial port
you see on the backside is /dev/ttyS0, while the other tends to
be used for the infrared port. So your best bet is /dev/ttyS0.
BTW, do you know about the 'minicom' program? It can be rather
helpful to figure out these kinds of things. (And don't worry
about the winmodem, they don't use one of the serial ports.)

Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Jens.Toerring@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring

Posted by tj on August 26th, 2003


Jens.Toerring@physik.fu-berlin.de wrote:
Yes - you are correct, I meant ttyS0 and ttyS1.

After disabling the PnP ports in the BIOS, I was able to get my widget to
finally operate on ttyS0.

Thanks,
TJ



Similar Posts