From: joltes@login1.fas.harvard.edu (Dick Joltes)
Subject: Re: Serial I/O under Digital UNIX
Date: 1997/02/03 [thread overview]
Message-ID: <5d5cb8$cbf$1@news.fas.harvard.edu> (raw)
In-Reply-To: 854757280snz@genesis.demon.co.uk
Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
>In article <5ctc4i$o9p@news.fas.harvard.edu>
> joltes@fas.harvard.edu "Dick Joltes" writes:
>
>>Question for the C & OSF gurus...
>
>This isn't a question about the C language itself so I've added
>comp.unix.programmer to the newsgroups list and removed comp.lang.c
>from the followups. comp.lang.c is inappropriate for questions about
>a specific platform.
Thank you. I'd forgotten about comp.unix.programmer...
>>The problem is that the old open/read calls don't seem to be working.
>>I get invalid data when I query the cash acceptor module, and I think
>>it has to do with the change from clist to STREAMS-based I/O under
>>Digital UNIX (& OSF).
>
>That is entirely possible although I don't know Digital UNIX specifically.
>
>> I put the device into RAW mode using standard
>>termios calls as we did under Ultrix (though there was a specific call
>>under Ultrix that did everything necessary at once) and then just try
>>writing a query byte to the device. It returns something (or at least
>>it seems to) but it's not the correct string.
>
>RAW mode covers a multitude of sins under termios, as you note there isn't
>a simple setting for it. You need to give the exact settings you used.
Here's what I'm setting now (using Stevens' book _Advanced Programming
in the UNIX Environment_ as a basis):
if ((tty_termios.c_cflag & CLOCAL) == 0) {
tty_termios.c_cflag |= CLOCAL;
}
if ((tty_termios.c_ispeed & BAUD) == 0) {
tty_termios.c_ispeed = tty_termios.c_ospeed = BAUD;
}
tty_termios.c_cc[VMIN] = 1; /* 1 byte at a time */
tty_termios.c_cc[VTIME] = 0; /* no timer */
tty_termios.c_cflag = CS8;
tty_termios.c_iflag &= ~(IXON | BRKINT | IGNBRK | ICRNL | IGNPAR);
tty_termios.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
tty_termios.c_cflag &= ~(CSIZE | PARENB);
tty_termios.c_oflag &= ~(OPOST);
if ((tcsetattr (fd, TCSAFLUSH, &tty_termios) == -1)) {
perror ("ics_input2: tcsetattr: can't set terminal");
exit (-1);
}
>>ics_expect (byte)
>>
>> char byte;
>>{
>> char buf[8];
>>
>> if (read (fd, buf, 2) == 2) {
>> byte == buf[0];
>
>This line doesn't appear to do anything particularly useful.
This is left over from a previous programmer (who didn't document much,
as I've found out). At this point I'm not touching anything that does
not seem directly related to the problem at hand. Once that's resolved
I'll go through and clean up the rest of the code (and add enhancements).
>> return;
>> }
>
>The point being here that without knowing the exact settings it is impossible
>to say whether both reply bytes will be returned through a single read,
>whether they might be returned individually, read() might even return 0
>length in some cases. Depending on your settings the tty may not be as "RAW"
>as you thought it was, it may still be dong some form in input processing.
>
>For robustness your code should expect to receive short input and be able
>to recall read to get the rest of the input if that is the case.
>
>> else {
>> fprintf (stderr, "ics_expect: Bad response from unit: %d\n",
>> (int) buf[0]);
>> exit (1);
>> }
>>}
>>
>>The write completes without error, but every time I try running the
>>code I get the "Bad response..." error from ics_expect.
>
>So what did you receive from the read() call? What was the return value?
>If it returned data what was it and what data did you expect? If read()
>returned an error condition what was the value of errno?
This is what leads me to belive that I'm missing something in the settings
for RAW mode--whenever I change any of the mode settings I pass to the
tty, the return code changes with it (in one case it's -72, in another
it's -64...). The reads seem to complete just fine, they just return
bad data. The initial write to the device seems okay as well (i.e. I
can do it) but since I'm not sure if the tty's mode is correct I don't
know if I'm sending it clean data.
Any help appreciated.
------------------------------------------------------------------------------
Dick Joltes mailto: <joltes@fas.harvard.edu>
Manager, Multiplatform Services http://www.fas.harvard.edu/~joltes
------------------------------------------------------------------------------
The other day upon the stair / I met a man who wasn't there.
He wasn't there again today / I think he's from the CIA. -- Mad Magazine
next prev parent reply other threads:[~1997-02-03 5:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-01-31 5:00 Serial I/O under Digital UNIX Dick Joltes
1997-02-01 5:00 ` Lawrence Kirby
1997-02-03 5:00 ` Dick Joltes [this message]
1997-02-03 5:00 ` Eric Werme
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox