r4213 - in developers/werner/ahrt/host/tmc: . examples
werner at sita.openmoko.org
werner at sita.openmoko.org
Sat Mar 15 22:37:06 CET 2008
Author: werner
Date: 2008-03-15 22:37:01 +0100 (Sat, 15 Mar 2008)
New Revision: 4213
Modified:
developers/werner/ahrt/host/tmc/README
developers/werner/ahrt/host/tmc/examples/tty.py
developers/werner/ahrt/host/tmc/tty.c
Log:
Some cleanup of the tty driver.
- tty.c (struct tty_dsc, tty_open, tty_write), README: added option "echo" to
enable checking of command echo
- tty.c (struct tty_dsc, tty_open, tty_dci), README: added option "no_dci" to
disable sending of DCI
- examples/tty.py: use "no_dci"
Modified: developers/werner/ahrt/host/tmc/README
===================================================================
--- developers/werner/ahrt/host/tmc/README 2008-03-15 13:37:29 UTC (rev 4212)
+++ developers/werner/ahrt/host/tmc/README 2008-03-15 21:37:01 UTC (rev 4213)
@@ -155,12 +155,14 @@
The serial transport accepts the following arguments:
-[bps=N,] [crtscts,] device
+[bps=N,] [crtscts,] [echo,] [no_dci,] device
bps=N The speed of the serial interface. Default: use the
previous setting.
crtscts Use RTS/CTS flow control: Default: turn it off.
- device Device
+ echo The instrument echos back commands.
+ no_dci The instrument does not support the DCI function.
+ device Device
Instrument quirks
Modified: developers/werner/ahrt/host/tmc/examples/tty.py
===================================================================
--- developers/werner/ahrt/host/tmc/examples/tty.py 2008-03-15 13:37:29 UTC (rev 4212)
+++ developers/werner/ahrt/host/tmc/examples/tty.py 2008-03-15 21:37:01 UTC (rev 4213)
@@ -7,7 +7,7 @@
import tmc, time
-d = tmc.Instr("tty", "bps=9600", "/dev/ttyUSB0")
+d = tmc.Instr("tty", "bps=9600", "no_dci", "/dev/ttyUSB0")
d.send('*IDN?')
print d.read()
Modified: developers/werner/ahrt/host/tmc/tty.c
===================================================================
--- developers/werner/ahrt/host/tmc/tty.c 2008-03-15 13:37:29 UTC (rev 4212)
+++ developers/werner/ahrt/host/tmc/tty.c 2008-03-15 21:37:01 UTC (rev 4213)
@@ -29,6 +29,8 @@
struct tty_dsc {
int fd; /* file descriptor */
int crlf; /* 0 = in message, 1 = CR seen, 2 = CRLF seen */
+ int echo; /* device echos commands back */
+ int dci; /* device support DCI */
struct termios attr;
};
@@ -70,9 +72,21 @@
int i;
struct termios attr;
+ d = malloc(sizeof(struct tty_dsc));
+ if (!d) {
+ perror("malloc");
+ return NULL;
+ }
+ d->crlf = 0;
+ d->echo = 0;
+ d->dci = 1;
for (i = 0; i != argc; i++) {
if (!strcmp(argv[i], "crtscts"))
crtscts = 1;
+ else if (!strcmp(argv[i], "echo"))
+ d->echo = 1;
+ else if (!strcmp(argv[i], "no_dci"))
+ d->dci = 0;
else if (!strncmp(argv[i], "bps=", 4)) {
bps = strtoul(argv[i]+4, &end, 0);
if (*end)
@@ -88,12 +102,6 @@
if (i != argc-1)
goto usage;
- d = malloc(sizeof(struct tty_dsc));
- if (!d) {
- perror("malloc");
- return NULL;
- }
- d->crlf = 0;
d->fd = open(argv[i], O_RDWR | O_NOCTTY, 0);
if (d->fd < 0) {
@@ -120,7 +128,9 @@
return d;
usage:
- fprintf(stderr, "usage: \"tty\", [crtscts,] [bps=N,] device\n");
+ fprintf(stderr,
+ "usage: \"tty\", [crtscts,] [bps=N,] [echo,] [no_dci,] device\n");
+ free(d);
return NULL;
fail_fd:
@@ -208,16 +218,12 @@
if (do_write(d->fd, buf, len) < 0)
return -1;
-#if 0
- if (expect(d->fd, buf, len) < 0)
+ if (d->echo && expect(d->fd, buf, len) < 0)
return -1;
-#endif
if (do_write(d->fd, "\r\n", 2) < 0)
return -1;
-#if 0
- if (expect(d->fd, "\r\n", 2) < 0)
+ if (d->echo && expect(d->fd, "\r\n", 2) < 0)
return -1;
-#endif
return 0;
}
@@ -278,7 +284,7 @@
{
struct tty_dsc *d = dsc;
- return do_write(d->fd, "\003", 1);
+ return d->dci ? do_write(d->fd, "\003", 1) : 0;
}
More information about the commitlog
mailing list