[ O4SiS @ 29.04.2007. 18:09 ] @
Poštovanje imam problem sa prikazom hex vrijednosti vrijednosti koja je stigla na serijski port. napravio sam jedan program (upotrebom serial programming howto) Izvorni kod programa Code: #include <stdio.h> #include <sys/ioctl.h> #include <fcntl.h> #include <termios.h> #include <stdlib.h> struct termios tio; int main() { int fd, status, whichBaud, result,i; long baud; char buffer[255]; char stanje[] = "\x1b\x53"; baud = B9600; fd = open(device ,O_RDWR | O_NOCTTY); if (fd <0) { printf("error"); exit(1); } tio.c_cflag = baud | CS8 | CREAD | CLOCAL; tio.c_iflag = IGNPAR; /* ignore parity errors */ tio.c_oflag = 0; /* set output flag non-canonical, no processing */ tio.c_cc[VTIME] = 0; /* no time delay */ tio.c_cc[VMIN] = 0; /* no char delay */ tcflush(fd, TCIFLUSH); /* flush the buffer */ tcsetattr(fd, TCSANOW, &tio); /* set the attributes */ /* Set up for no delay, ie non-blocking reads will occur. When we read, we'll get what's in the input buffer or nothing */ fcntl(fd, F_SETFL, FNDELAY); write(fd,&stanje,2); usleep(100 * 1000); result = read(fd,buffer,255); printf("%c\n",result); buffer[result] = 0; // zero terminate so printf works printf("%s\n",buffer); } /* close the device file */ close(fd); } Povezao sam dva kompjutera i kad pošaljem hex vrijedost 31 ovamo imam 1 i tako dalje (ASCII) Ali kad pošaljem 0x81 odnosno b10000001 vrijednost ne dobivam ništa... Kako da prikažem pristiglu vrijednost kao hex vrijednost ili još bolje binarnu vrijednost? Da li je potrebna konverzija? Ima li gotova funkcija da se ta vrijednost kovertira? |