C程序我想读由GPS的XBee协议发送的数据帧。 XStick收到以下数据的USB:读取的/ dev/ttyUSB0与LINUX
CHARS : 15931 SENTENCES = 0 CHECKSUM : 58
Heading : 55 Tilt: -46 Roll:2
CHARS : ....
等等...我可以通过终端控制输入阅读:
$ screen /dev/ttyUSB0
我想以同样的方式看到这些细节,但与C语言编写的程序下面是我做的:
#include
#include
#include
#include
#include
#include "serial_port.h"
void read_Serial_Port(const char* DEVICE_PORT)
{
int file;
struct termios options;
char message[100];
unsigned int nCountMax = 60;
bool b;
file = open(DEVICE_PORT, O_RDONLY | O_NOCTTY | O_NDELAY);
if(file == -1){perror("Unable to open the serial port\n");}
printf("Serial port open successful\n");
tcgetattr(file, &options);
cfsetispeed(&options, B9600);