Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#173391 - 01/08/2003 17:36 Serial/STDOUT?
foxtrot_xray
addict

Registered: 03/03/2002
Posts: 687
Loc: Atlanta, Georgia
Hey guys,
Now that I got the VFD powered and displaying, I'm tryin' to do something..

I'm actually opening "/dev/ttyS1" as a file_descriptor. I can write to it using the write() command, but when I do a read(), it ALWAYS reads from stdin! Even though I'm sending it the fd for the previously openend serial port.. Here's the snippits to my code, in case you see something I don't..


vfd_fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY);
if (vfd_fd != -1)
{
/* Configure port.. */
tcgetattr(vfd_fd, &port_opt);
cfsetispeed(&port_opt, B19200);
cfsetospeed(&port_opt, B19200);
port_opt.c_oflag |= (CLOCAL | CREAD);
tcsetattr(vfd_fd, TCSANOW, &port_opt);

/* Send reset command.. */
vfd_reset();
}

/* Reset port params... */
tcgetattr(vfd_fd, &port_opt);
cfsetispeed(&port_opt, B19200);
cfsetospeed(&port_opt, B19200);
//port_opt.c_oflag |= (CLOCAL | CREAD);
tcsetattr(vfd_fd, TCSAFLUSH, &port_opt);

/* Loop, to reset display.. */
while (reset_ok)
{
write(vfd_fd, "\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000\x000", 20);
usleep(100);
write(vfd_fd, "\x01B\x052", 2);
usleep(50000);

/* Read the responce? */
//fcntl(vfd_fd, F_SETFL, FNDELAY);
read(vfd_fd, vfd_ret, 1);
perror("VFD_REST: Error: ");
fcntl(vfd_fd, F_SETFL, 0);

printf("VFD_REST: '%s'\n", vfd_ret);
}


I open it special so I can set the baud rate in AC *OR* DC mode. And it works pretty well. I have to reset it because sometimes when the player boots up, the garbage ASCII locks the display up to where I HAVE to hard reset the display. When it'd reset, it sends back a character (which will, eventually, drop me out of the while loop.)
The read() command freezes until I hit a key on the keyboard, to which it then echos back at me what *I* typed in, regardless of the fact the write() command sent the characters out to the display thru /dev/ttyS1..
Strange..
_________________________
Mike 'Fox' Morrey 128BPM@124MPH. Love it! 2002 BRG Mini Cooper

Top
#173392 - 02/08/2003 03:37 Re: Serial/STDOUT? [Re: foxtrot_xray]
V99
member

Registered: 12/01/2002
Posts: 192
Loc: Phoenix, AZ
Try clearing these bits... they're in my code, although I can't say I know exactly why.

port_opt.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON);

Also this probably won't affect you since you're talking to the VFD both ways, but while we're near the subject, the cfsetispeed and cfsetospeed actually do the opposite of what they say (how I look at it anyway).. ispeed is the speed of stuff leaving the empeg and going to your device, ospeed is the speed of stuff coming into the empeg. If yours are different (at the time my VFD was running at 38.4 and my joystick 19.2) and you set it the way that sounds right you will waste hours trying to figure out why the hell you can't output correct data to the display or read keys from your joystick.

Top
#173393 - 03/08/2003 13:48 Re: Serial/STDOUT? [Re: foxtrot_xray]
jaharkes
enthusiast

Registered: 20/08/2002
Posts: 340
Loc: Pittsburgh, PA
Why are you doing the tcgetattr/tcsetattr twice?
It should be port_opt.c_cflag = CLOCAL|CREAD; You seem to be setting the c_oflag with those bits. The corresponding bits in the oflag mask would be OFDEL|TAB1

I typically set c_iflag = c_oflag = c_lflag = 0; and c_cflag = (CSIZE&CS8)|CLOCAL|CREAD;

The three digit hex encoding always irks me, it is normal for octal numbers, but in this case does \x010 translate to the array 0, 16 or simply 16? I couldn't find a clear answer in my C reference book.

As far as the read being from stdin, I don't know really what could be causing it. Maybe one of the things I mentioned magically fixes it. You can also check the declared types and order of your variables. If vfd_fd is not an int, or the variable declared right before vfd_fd is a char buffer, you might have a simple overflow problem, clobbering the variable with null bytes.
_________________________
40GB - serial #40104051 gpsapp

Top
#173394 - 03/08/2003 17:33 Re: Serial/STDOUT? [Re: jaharkes]
foxtrot_xray
addict

Registered: 03/03/2002
Posts: 687
Loc: Atlanta, Georgia

Why are you doing the tcgetattr/tcsetattr twice?

That's my bad, just take the first one out. Can't cut and paste properly.


It should be port_opt.c_cflag = CLOCAL|CREAD; You seem to be setting the c_oflag with those bits. The corresponding bits in the oflag mask would be OFDEL|TAB1
I typically set c_iflag = c_oflag = c_lflag = 0; and c_cflag = (CSIZE&CS8)|CLOCAL|CREAD;

Is there anywhere these are defined? (For documentation, I mean.) The c_?flag things I just got looking at another piece of code, and figured that I didn't have to set it to 8N1, since it defaults to that anyways..


The three digit hex encoding always irks me, it is normal for octal numbers, but in this case does \x010 translate to the array 0, 16 or simply 16? I couldn't find a clear answer in my C reference book.

As far as I could tell (and it works this way when I'm sending it data..) "\x016" is just 0x16, and "\x13F" would be 0x13F..


As far as the read being from stdin, I don't know really what could be causing it. Maybe one of the things I mentioned magically fixes it. You can also check the declared types and order of your variables. If vfd_fd is not an int, or the variable declared right before vfd_fd is a char buffer, you might have a simple overflow problem, clobbering the variable with null bytes.

I'll try what you have above, as well as what was in the other response. It just threw me because all my write()'s were functioning normally..

Thanks!
Mike.
_________________________
Mike 'Fox' Morrey 128BPM@124MPH. Love it! 2002 BRG Mini Cooper

Top