libcm is a C development framework with an emphasis on audio signal processing applications.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

cmSerialPort.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //| Copyright: (C) 2009-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. #ifndef cmSerialPort_h
  4. #define cmSerialPort_h
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. //( { file_desc:"Serial port interface." kw[system devices rt] }
  9. typedef unsigned cmSeRC_t;
  10. enum
  11. {
  12. kOkSeRC = cmOkRC,
  13. kFlushFailSeRC,
  14. kSetAttrFailSeRC,
  15. kCloseFailSeRC,
  16. kOpenFailSeRC,
  17. kResourceNotAvailableSeRC,
  18. kGetAttrFailSeRC,
  19. kWriteFailSeRC,
  20. kReadFailSeRC,
  21. kTimeOutSeRC,
  22. kThreadErrSeRC
  23. };
  24. enum
  25. {
  26. kDataBits5SeFl = 0x0001,
  27. kDataBits6SeFl = 0x0002,
  28. kDataBits7SeFl = 0x0004,
  29. kDataBits8SeFl = 0x0008,
  30. kDataBitsSeMask = 0x000f,
  31. k1StopBitSeFl = 0x0010,
  32. k2StopBitSeFl = 0x0020,
  33. kEvenParitySeFl = 0x0040,
  34. kOddParitySeFl = 0x0080,
  35. kNoParitySeFl = 0x0000,
  36. kDefaultCfgSeFlags = kDataBits8SeFl | k1StopBitSeFl | kNoParitySeFl
  37. };
  38. typedef void (*cmSeCallbackFunc_t)( void* cbArg, const void* byteA, unsigned byteN );
  39. typedef cmHandle_t cmSeH_t;
  40. cmSeH_t cmSeCreate( cmCtx_t* ctx, cmSeH_t* hp, const char* device, unsigned baudRate, unsigned cfgFlags, cmSeCallbackFunc_t cbFunc, void* cbArg, unsigned pollPeriodMs );
  41. cmSeRC_t cmSeDestroy(cmSeH_t* hp );
  42. cmSeRC_t cmSeSetCallback( cmSeH_t h, cmSeCallbackFunc_t cbFunc, void* cbArg );
  43. cmSeRC_t cmSeStart( cmSeH_t h );
  44. bool cmSeIsOpen( cmSeH_t h);
  45. cmSeRC_t cmSeSend( cmSeH_t h, const void* byteA, unsigned byteN );
  46. // Make callback to listener with result of read - Non-blocking
  47. cmSeRC_t cmSeReceiveCbNb( cmSeH_t h, unsigned* readN_Ref);
  48. // Make callback to listener with result of read - Block for up to timeOutMs.
  49. cmSeRC_t cmSeReceiveCbTimeOut( cmSeH_t h, unsigned timeOutMs, unsigned* readN_Ref);
  50. // Return result of read in buf[bufByteN] - Non-blocking.
  51. cmSeRC_t cmSeReceiveNb( cmSeH_t h, void* buf, unsigned bufByteN, unsigned* readN_Ref);
  52. // Return result of read in buf[bufByteN] - Block for up to timeOutMs.
  53. cmSeRC_t cmSeReceive( cmSeH_t h, void* buf, unsigned bufByteN, unsigned timeOutMs, unsigned* readN_Ref );
  54. const char* cmSeDevice( cmSeH_t h);
  55. // Get the baud rate and cfgFlags used to initialize the port
  56. unsigned cmSeBaudRate( cmSeH_t h);
  57. unsigned cmSeCfgFlags( cmSeH_t h);
  58. // Get the baud rate and cfg flags by reading the device.
  59. // Note the the returned buad rate is a system id rather than the actual baud rate,
  60. // however the cfgFlags are converted to the same kXXXFl defined in this class.
  61. unsigned cmSeReadInBaudRate( cmSeH_t h );
  62. unsigned cmSeReadOutBaudRate( cmSeH_t h);
  63. unsigned cmSeReadCfgFlags( cmSeH_t h);
  64. cmSeRC_t cmSePortTest(cmCtx_t* ctx);
  65. //)
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif