You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
838 B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include "serial.h"
  5. int serial_com_id;
  6. int serial_test() {
  7. PORT COM1;
  8. char buff[1024] = {0};
  9. int rcv_len = 0;
  10. printf("Start open com%d\n", serial_com_id);
  11. COM1 = serial_init(serial_com_id, 115200, 8, 1, 0);
  12. while (1) {
  13. Serial_SendData(COM1, "hello finny", 12);
  14. memset(buff, 0, 1024);
  15. rcv_len = Serial_ReciveData(COM1, buff, 1024);
  16. printf("rcv:%s\n", buff);
  17. Sleep(1);
  18. }
  19. }
  20. int main(int argc, char *argv[]) {
  21. if (argc != 2) {
  22. printf("please input com id\n");
  23. return -1;
  24. }
  25. printf("Serial port number is:%s\n", argv[1]);
  26. serial_com_id = atoi(argv[1]);
  27. if (serial_com_id == 0) {
  28. /* 转换错误 */
  29. printf("The serial port id is incorrect\n");
  30. return -2;
  31. }
  32. serial_test();
  33. while (1) {
  34. }
  35. return 0;
  36. }