我只是在尝试每秒不断地向终端写入以连续接收数据的功能时遇到问题:
int plash(int filedes) {
static struct p_1 = {
.X = 1,
.Y = 10,
.Z = 13
};
return write(fd, &p_1, sizeof(p_1));
}
int elli() {
while (1) {
int g = plash(fd);
printf("Writing to port:%d\n", g);
sleep(1);
}
return 1;
}
int main(int argc, char *argv[]) {
uint8_t buffer[128];
int bRead;
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY);
while (fd > 0) {
elli();
bRead = read(fd, buffer, 128);
printf("Got %i Bytes\n", bRead);
}
}
我认为程序写入端口,但它没有执行之后调用的读取函数。你们能帮我看看吗?