Re: Interesting problem with Serial Port
From: Chuck Dillon (spam_at_nimblegen.com)
Date: 01/28/05
- Next message: beetle: "Re: compiling multiple source files and static functions"
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: compiling multiple source files and static functions"
- In reply to: Kazman: "Interesting problem with Serial Port"
- Next in thread: Kazman: "Re: Interesting problem with Serial Port"
- Reply: Kazman: "Re: Interesting problem with Serial Port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 28 Jan 2005 08:26:54 -0600
Kazman wrote:
> I have an interesting problem I have come across recently. So I am
> running NetBSD, and I have written a TCP/IP server which takes commands
> from a client PC, passes it on to a radio receiver, and then parses the
> results from the receiver.
>
> So first I wrote the code to hook up with the serial port and
> communicate with the radio. It worked just fine. So then I added the
> code to do the TCP/IP communications. Now I can't use the serial port.
> I can open it up, but the data I write never goes out the serial port.
> I can change settings with no problem. My write operations return
> saying the bytes were written, but hooking the port up to a hex
> terminal shows nothing goes out. And all of my read functions return
> -1.
What does errno say when read() returns -1? My guess is that code
elsewhere is doing something to your open file handle. Could there be
initialization code elsewhere that is closing open files. Just a guess
but I'd say something like that is happening and the descriptior you
have is now associated with a write only stream.
Use a system call tracer (truss, strace don't know what it's called on
NetBSD) and see what is going on.
-- ced
>
> So I made a new program with just the serial port communications code.
> Sure enough, all alone without the TCP/IP code, I was able to write and
> receive data on the serial port.
>
> Any ideas why this would be happening? I'm simply blown away by this
> problem. I've never seen anything like it before. The code in the
> stand alone serial port program is exactly the same as the code in the
> server program. Yet one works and the other doesn't.
>
> Also, I can't seem to get the read command to block for a long time(10
> seconds). I shall post my settings below. Is there anything I'm doing
> wrong? Any help or advice would be greatly appreciated! Thanks for
> your time!
>
> /* Set up the serial port */
> portfd = open(portname, O_RDWR | O_NOCTTY);
> if (portfd < 0)
> {
> fprintf(stderr, "open_rs485: failed to open device %s", portname);
> exit(-1);
> }
> settings.c_cflag=0;
> cfsetispeed(&settings, B9600);
> cfsetospeed(&settings, B9600);
> settings.c_cflag |= (CREAD | CLOCAL);
> settings.c_cflag &= ~PARENB;
> settings.c_cflag &= ~CSTOPB;
> settings.c_cflag &= ~CSIZE;
> settings.c_cflag |= CS8;
> settings.c_cflag &= ~CRTSCTS;
> settings.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
> settings.c_oflag &= ~(IXON | IXOFF | IXANY);
> settings.c_oflag &= ~OPOST;
> settings.c_cc[VMIN]=0;
> settings.c_cc[VTIME]=100;
> tcflush(portfd, TCIFLUSH);
> tcflush(portfd, TCOFLUSH);
> tcsetattr(portfd,TCSANOW,&settings);
>
-- Chuck Dillon Senior Software Engineer NimbleGen Systems Inc.
- Next message: beetle: "Re: compiling multiple source files and static functions"
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: compiling multiple source files and static functions"
- In reply to: Kazman: "Interesting problem with Serial Port"
- Next in thread: Kazman: "Re: Interesting problem with Serial Port"
- Reply: Kazman: "Re: Interesting problem with Serial Port"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|