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.4KB

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