| #include <stdio.h> |
| #include <errno.h> |
| |
| #include "ql/ql_uart.h" |
| |
| |
| int main(int argc, char *argv[]) |
| { |
| if(argc != 3) { |
| printf("./uart_test <dev> <baudrate>\n"); |
| return -1; |
| } |
| |
| int fd = Ql_UART_Open(argv[1], (Enum_BaudRate)atoi(argv[2]), FC_NONE); |
| if(fd < 0) { |
| printf("Ql_UART_Open() fail.\n"); |
| return -1; |
| } |
| |
| ST_UARTDCB dcb; |
| memset(&dcb, 0x0, sizeof(ST_UARTDCB)); |
| dcb.databit = DB_CS8; |
| dcb.parity = PB_NONE; |
| dcb.flowctrl = FC_NONE; |
| |
| if(Ql_UART_SetDCB(fd, &dcb)) { |
| printf("Ql_UART_SetDCB() fail.\n"); |
| return -1; |
| } |
| |
| char buff[1024]; |
| int len; |
| while(1) { |
| memset(buff, 0x0 ,1024); |
| len = Ql_UART_Read(fd, buff, 1024); |
| if(len > 0) { |
| if(memcmp(buff, "exit", 4) == 0) { |
| Ql_UART_Write(fd, "exit\r\n", 6); |
| break; |
| } else { |
| printf("<%s\n", buff); |
| |
| Ql_UART_Write(fd, "OK\r\n", 4); |
| } |
| } else { |
| printf("Ql_UART_Read() fail:%d, errno = %d\n", len, errno); |
| } |
| } |
| Ql_UART_Close(fd); |
| |
| printf("exit!!!\n"); |
| |
| return 0; |
| } |
| |
| |