[ myrmidon @ 10.01.2006. 20:22 ] @
Pozdrav svima, pisem jedan mali program koji mi pravi probleme. Naime imam jedan uredjaj vezan na serijski port, kada uredjaju posaljem poruku "9G" on mi odgovara sa "9G12,22;". Ovo savrseno radi u minicom-u. Parametri: 9600 8N1 NO HARDWARE FLOW CONTROL NO SOFTWARE FLOW CONTROL /dev/ttyS0 /dev/ttS0 mi je pristupacan, jer sam uradio chmod a+rw /dev/ttyS0 Isto pokusavam da postignem sa sledecim kodom , ali uzalud. (ubedjen sam da nesto u komunikacionim parametrima nisam dobro podesio HEEELP): Code: #include <stdio.h> /* Standard input/output definitions */ #include <string.h> /* String function definitions */ #include <unistd.h> /* UNIX standard function definitions */ #include <fcntl.h> /* File control definitions */ #include <errno.h> /* Error number definitions */ #include <termios.h> /* POSIX terminal control definitions */ #include <stdio.h> int open_port(void) { int fd=open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY); if(fd<0) { printf("Unable to open port\n"); } return fd; } /* ************************************* Setting parameters for serial port **************************************/ void set_parameters(int fd) { struct termios options; fcntl(fd, F_SETFL, FNDELAY); /* Configure port reading */ tcgetattr(fd, &options); /* Get the current options for the port */ cfsetispeed(&options, B9600); /* Set the baud rates to 9600 */ cfsetospeed(&options, B9600); /* Enable the receiver and set local mode */ options.c_cflag |= (CLOCAL | CREAD); options.c_cflag &= ~PARENB; /* Mask character size to 8 bits, no parity */ options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; options.c_cflag &= ~CRTSCTS; /* Disable hardware flow control */ options.c_lflag &= ~(ICANON | ECHO | ISIG); /* RAW mode */ /* Set the new options for the port */ tcsetattr(fd, TCSANOW, &options); } /********************************* main **********************************************************************************/ int main(void) { int fd,n; char buf[8]; fd=open_port(); set_parameters(fd); n=write(fd,"9G",3); if(n!=3) printf("Write to port failed!\n"); read(fd,buf,8) ; printf("Read from serial:%s",buf); close(fd) ; return 0; } |