Differences
This shows you the differences between the selected revision and the current version of the page.
| serial_settings 2007/03/04 19:36 | serial_settings 2007/03/18 22:34 current | ||
| Line 12: | Line 12: | ||
| ===== Quick and dirty ===== | ===== Quick and dirty ===== | ||
| - | Write your own program, which makes all the settings for you. Based on [[http://www.sunspot.co.uk/Projects/SWEEX/files/serialports/rs232_c_progs/rs232io_ttyS1_96.c|sunspots work]] I use the following c programm: | + | Write your own program, which makes all the settings for you. Based on [[http://www.sunspot.co.uk/Projects/SWEEX/files/serialports/rs232_c_progs/rs232io_ttyS1_96.c|sunspots work]] I use [[http://schimmelnetz.de/projekte/eddi/files/set_ttyS1_2400_8N1.c|this c programm]]. Change the baudrate and the device name in the sources to your needs or implement baudrate and device name as command line arguments. |
| - | <code> | + | |
| - | #include <stdio.h> | + | |
| - | #include <errno.h> | + | |
| - | #include <sys/types.h> | + | |
| - | #include <sys/stat.h> | + | |
| - | #include <fcntl.h> | + | |
| - | #include <termios.h> | + | |
| - | #include <stdlib.h> | + | |
| - | #include <string.h> | + | |
| - | + | ||
| - | #define BAUDRATE B2400 | + | |
| - | + | ||
| - | int main(int argc,char* argv[]) { | + | |
| - | int fd; | + | |
| - | struct termios newtio; | + | |
| - | char *device; | + | |
| - | + | ||
| - | device="/dev/ttyS1"; | + | |
| - | fd = open(device,O_RDWR); | + | |
| - | if(fd < 0) { | + | |
| - | fprintf(stderr,"*** open %s: %s\n",device,strerror(errno)); | + | |
| - | exit(-1); | + | |
| - | } | + | |
| - | + | ||
| - | bzero(&newtio,sizeof(newtio)); | + | |
| - | + | ||
| - | cfsetospeed(&newtio,BAUDRATE); | + | |
| - | + | ||
| - | newtio.c_cflag |= CS8; | + | |
| - | newtio.c_cflag |= CLOCAL; | + | |
| - | newtio.c_cflag |= CREAD; | + | |
| - | + | ||
| - | newtio.c_cflag &= ~CRTSCTS; /* NO output hardware flow control */ | + | |
| - | newtio.c_cflag &= ~PARENB; /* no parity */ | + | |
| - | newtio.c_cflag &= ~CSTOPB; /* no stopbit */ | + | |
| - | + | ||
| - | newtio.c_iflag = IGNPAR; /* ignore input parity */ | + | |
| - | newtio.c_lflag = 0; /* turn all off (non-canonocal, non-echo) */ | + | |
| - | newtio.c_oflag = 0; /* turn all off */ | + | |
| - | newtio.c_cc[VTIME] = 20; /* timeout in 1/10 sec */ | + | |
| - | newtio.c_cc[VMIN] = 0; /* minimum characters to read */ | + | |
| - | + | ||
| - | tcflush(fd,TCIFLUSH); | + | |
| - | tcsetattr(fd,TCSANOW,&newtio); | + | |
| - | } | + | |
| - | </code> | + | |
| - | + | ||
| - | TODO: Baudrate as command line argument | + | |
| - | + | ||
| - | Binary version available on request. | + | |
| Compile it using the [[crosscompiler]], strip it and copy it into ''trunk/openwrt/target/linux/image/adm5120/base-files/sbin/'' before you next firmware build. After you run it, your /dev/ttyS1 runs fine with 8N1, no hardware handshaking and the baudrate you entered in the sources. | Compile it using the [[crosscompiler]], strip it and copy it into ''trunk/openwrt/target/linux/image/adm5120/base-files/sbin/'' before you next firmware build. After you run it, your /dev/ttyS1 runs fine with 8N1, no hardware handshaking and the baudrate you entered in the sources. | ||
