47 #if !defined(LINUX_SERIAL_H) && !defined(win_x86) 48 #define LINUX_SERIAL_H 66 fd = open(port_name, O_RDWR | O_NOCTTY | O_NDELAY);
69 fprintf(stderr,
"Unable to open %s\n\r", port_name);
77 fprintf(stderr,
"%s is not a serial port\n", port_name);
81 *handle = (
int *) malloc(
sizeof(
int));
82 **(
int **) handle = fd;
88 struct termios options;
91 tcgetattr(*(
int *) handle, &options);
95 options.c_cflag |= CS8;
98 options.c_cflag |= (CLOCAL | CREAD);
101 cfsetispeed(&options, B115200);
102 cfsetospeed(&options, B115200);
114 options.c_cc[VMIN] = 0;
115 options.c_cc[VTIME] = 1;
118 tcsetattr(*(
int *) handle, TCSAFLUSH, &options);
126 int n = write(*(
int *) handle, buffer, length);
130 fprintf(stderr,
"Error in serial write\r\n");
138 for (i=0; i<length; ++i) printf(
" %x", (
unsigned char)(buffer[i]));
148 int bytesRead = read(*(
int *) handle, buffer, length);
159 for (i=0; i<bytesRead; ++i) printf(
" %x", (
unsigned char)buffer[i]);
171 close(*(
int *) handle);
178 #endif // LINUX_SERIAL int SetupSerial(void *handle)
int OpenSerial(void **handle, const char *port_name)
int CloseSerial(void *handle)
int WriteData(void *handle, const char *buffer, int length)
int ReadData(void *handle, char *buffer, int length)