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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // ****************************************************************************
  2. // tSerial.c
  3. //
  4. // Build: gcc tSerial.c wiringSerial.o -o tSerial
  5. // ****************************************************************************
  6. #include <stdio.h>
  7. #include <stdint.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <unistd.h>
  11. #include "wiringSerial.h"
  12. // @DEBUG
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #include <fcntl.h>
  16. // @DEBUG
  17. // ****************************************************************************
  18. #define HERE() do { printf ("%s(%d).%s\r\n", __FILE__, __LINE__, __FUNCTION__); } while(0)
  19. #define DPRINTF(fmt, args...) do { \
  20. printf ("%s(%d).%s ", __FILE__, __LINE__, __FUNCTION__); \
  21. printf(fmt, ## args); \
  22. fflush(stdout); \
  23. } while (0)
  24. // ****************************************************************************
  25. int main(int argc, char *argv[])
  26. {
  27. // ----------------------------------------------------
  28. printf ("\r\n\r\n");
  29. HERE();
  30. // ----------------------------------------------------
  31. HERE();
  32. #if 1
  33. const char devName[] = "/dev/tty";
  34. int fd = serialOpen(devName, 115200);
  35. #else
  36. const char devName[] = "test.txt";
  37. int fd = serialOpen(devName, -1);
  38. #endif
  39. DPRINTF("fd = %d\r\n", fd);
  40. if (fd == -1)
  41. {
  42. perror("open");
  43. DPRINTF("ERROR: fd = %d\r\n", fd);
  44. }
  45. serialPrintf(fd, "%s(%d).%s HELLO THERE!\r\n", __FILE__, __LINE__, __FUNCTION__);
  46. serialFlush(fd);
  47. serialClose(fd);
  48. // ----------------------------------------------------
  49. HERE();
  50. printf ("\r\n");
  51. return EXIT_SUCCESS;
  52. }
  53. // ****************************************************************************