liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <errno.h> |
| 3 | |
| 4 | #include "ql/ql_uart.h" |
| 5 | |
| 6 | |
| 7 | int main(int argc, char *argv[]) |
| 8 | { |
| 9 | if(argc != 3) { |
| 10 | printf("./uart_test <dev> <baudrate>\n"); |
| 11 | return -1; |
| 12 | } |
| 13 | |
| 14 | int fd = Ql_UART_Open(argv[1], (Enum_BaudRate)atoi(argv[2]), FC_NONE); |
| 15 | if(fd < 0) { |
| 16 | printf("Ql_UART_Open() fail.\n"); |
| 17 | return -1; |
| 18 | } |
| 19 | |
| 20 | ST_UARTDCB dcb; |
| 21 | memset(&dcb, 0x0, sizeof(ST_UARTDCB)); |
| 22 | dcb.databit = DB_CS8; |
| 23 | dcb.parity = PB_NONE; |
| 24 | dcb.flowctrl = FC_NONE; |
| 25 | |
| 26 | if(Ql_UART_SetDCB(fd, &dcb)) { |
| 27 | printf("Ql_UART_SetDCB() fail.\n"); |
| 28 | return -1; |
| 29 | } |
| 30 | |
| 31 | char buff[1024]; |
| 32 | int len; |
| 33 | while(1) { |
| 34 | memset(buff, 0x0 ,1024); |
| 35 | len = Ql_UART_Read(fd, buff, 1024); |
| 36 | if(len > 0) { |
| 37 | if(memcmp(buff, "exit", 4) == 0) { |
| 38 | Ql_UART_Write(fd, "exit\r\n", 6); |
| 39 | break; |
| 40 | } else { |
| 41 | printf("<%s\n", buff); |
| 42 | |
| 43 | Ql_UART_Write(fd, "OK\r\n", 4); |
| 44 | } |
| 45 | } else { |
| 46 | printf("Ql_UART_Read() fail:%d, errno = %d\n", len, errno); |
| 47 | } |
| 48 | } |
| 49 | Ql_UART_Close(fd); |
| 50 | |
| 51 | printf("exit!!!\n"); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | |