From: chris r. <cr...@wh...> - 2006-04-20 22:42:11
|
Hi, I have a Basix and a STUART waysmall. I can't get /dev/ttyS2 to work when using a C program. I can do at the prompt ... #stty -F /dev/ttyS2 speed 9600 baud; -brkint -imaxbel #echo "foobar" > /dev/ttyS2 and have foobar show up on another computer. then doing.... # cat /proc/tty/driver/PXA\ serial 2: uart:STUART mmio:0x40700000 irq:13 tx:89 rx:0 verifies that character were actually sent. the only odd thing is that the echo will send the characters and then hang the prompt for about 30 seconds ???? BUT, if i write a simple C program, (at the end of the email), i can't get anything so show up on the other machine. in fact, the characters show up on the console, ttyS0. Doing # cat /proc/tty/driver/PXA\ serial after running the C-program verifies that nothing was sent out. I can however using the "system" command from in the C program and get it to work fine, with the 30 second hang up. So, whats the deal?????????? in the code below, i get a correct >0 integer value for the file descriptor and write, returns the current number of characters sent, that end up on ttyS0 instead of ttyS2. Thanks - Chris The C-code /*--------------------------------------------------------------------*/ #include "sampler.h" #include "sampler_util.h" void main() { char cmd_string[128]; unsigned char serial_cmd[128] = {'\0'}; int fd,num_sent; printf("Hello, small world!\n"); //set up the serial port fd = set_port_cmu(); printf("fd=%d, %s\n",fd,PORT); tcflush(fd,TCIFLUSH); //make and send a string sprintf(serial_cmd,"serial_testing"); num_sent = write(fd,serial_cmd,10); printf("num_sent %d\n",num_sent); //this works using the system cmd sprintf(cmd_string,"echo \"serial_test_system\" > /dev/ttyS2"); printf("%s\n",cmd_string); system(cmd_string); //close serial port close(fd); } /*--------------------------------------------------------------------*/ AND an h file *--------------------------------------------------------------------*/ #include "sampler.h" /* Defines */ #define BAUDRATE B9600 #define PORT "/dev/ttyS2" #define FALSE 0 #define TRUE 1 extern int set_port(); extern int set_port_cmu(); *--------------------------------------------------------------------*/ AND the port opening stuff *--------------------------------------------------------------------*/ int set_port_cmu() { struct termios serial_opts; int fd; fd = open(PORT, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { perror(PORT); return -1; } else fcntl(fd, F_SETFL, FNDELAY); tcgetattr(fd, &serial_opts); // set baud rate cfsetispeed(&serial_opts, BAUDRATE); cfsetospeed(&serial_opts, BAUDRATE); // enable receiver mode and set local mode serial_opts.c_cflag |= (CLOCAL | CREAD); // set 8n1 serial_opts.c_cflag &= ~PARENB; serial_opts.c_cflag &= ~CSTOPB; serial_opts.c_cflag &= ~CSIZE; serial_opts.c_cflag |= CS8; // disable hardware control serial_opts.c_cflag &= ~CRTSCTS; // raw input serial_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) | (ECHOCTL | ECHOPRT); // set the options tcsetattr(fd, TCSANOW, &serial_opts); return(fd); } *--------------------------------------------------------------------*/ -- ======================================= Chris Roman, Ph.D. Woods Hole Oceanographic Institution Deep Submergence Laboratory cr...@wh... Phone 508-289-2652 Fax 508-457-2191 http://www.whoi.edu/people/croman ======================================= |