1b087521eSChiichen #include <fcntl.h>
2b087521eSChiichen #include <stdio.h>
3b087521eSChiichen #include <string.h>
4b087521eSChiichen #include <unistd.h>
5b087521eSChiichen
main()6b087521eSChiichen int main() {
7b087521eSChiichen // 打开设备文件
8b087521eSChiichen int fd = open("/dev/char/uart:1088", O_WRONLY | O_NONBLOCK);
9b087521eSChiichen char buf[1] = {0};
10b087521eSChiichen int n;
11b087521eSChiichen memset(buf, 0, 1);
12b087521eSChiichen while (1) {
13b087521eSChiichen n = read(fd, buf, 1);
14b087521eSChiichen close(fd);
15b087521eSChiichen fd = open("/dev/char/uart:1088", O_WRONLY | O_NONBLOCK);
16b087521eSChiichen if (n != 0) { // 添加字符串结束符
17b087521eSChiichen printf("Received: %s\n", buf); // 打印接收到的数据
18b087521eSChiichen if (buf[0] == 'g') {
19b087521eSChiichen break;
20b087521eSChiichen }
21b087521eSChiichen }
22b087521eSChiichen }
23*bc6f0a96S裕依 printf("fd: %d", fd);
24b087521eSChiichen // 写入字符串
25b087521eSChiichen char *str = "------fuck-----";
26b087521eSChiichen int len = write(fd, str, strlen(str));
27*bc6f0a96S裕依 printf("len: %d", len);
28b087521eSChiichen // 关闭文件
29b087521eSChiichen close(fd);
30b087521eSChiichen return 0;
31b087521eSChiichen }