CSerial.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /******************************************************************************
  2. |* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  3. |* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  4. |* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  5. |* PARTICULAR PURPOSE.
  6. |*
  7. |* Copyright 1995-2005 Nero AG. All Rights Reserved.
  8. |*-----------------------------------------------------------------------------
  9. |* NeroSDK / NeroRobo
  10. |*
  11. |* PROGRAM: CSerial.h
  12. |*
  13. |* PURPOSE: Interface for different serial ports
  14. ******************************************************************************/
  15. /* Compatibility class for serial port access.
  16. * Note that 'serial port' refers to all interfaces like USB, COM, LPT receiving data sequentially
  17. * This class is pure virtual. */
  18. #ifndef CSERIAL_H
  19. #define CSERIAL_H
  20. #include <windows.h>
  21. /* The following enum defines different port types supported by Nero.
  22. * Do not change the order of these constants as their values may be stored
  23. * in configuration profiles */
  24. /* NOTE: currently (Nero 6.6) only serial (COM) port is implemented by Nero. */
  25. typedef enum
  26. {
  27. PORT_SERIAL = 0,
  28. PORT_PARALLEL = 1,
  29. PORT_USB = 2,
  30. PORT_BRAVO = 3
  31. } SerialPortType;
  32. #define CSERIALTIMEOUT_NONE 0
  33. #define CSERIALTIMEOUT_INFINITE -1
  34. class CSerial
  35. {
  36. public:
  37. virtual ~CSerial() {};
  38. /* TRUE: everything ok
  39. * FALSE: error */
  40. virtual BOOL OpenPort() = 0;
  41. /* Returns number of bytes read/written or -1 in case of an error.
  42. * Will return 0 if no bytes could be read until the timeout was reached.
  43. * Input:
  44. * buffer: buffer being read into/ written from
  45. * iBytes: number of bytes to read/write
  46. * timeout: maximum time the operation should take in ms */
  47. virtual int ReadData(char *buffer, int iBytes, int timeout = CSERIALTIMEOUT_NONE) = 0;
  48. virtual int WriteData(const char *buffer, int iBytes, int timeout=CSERIALTIMEOUT_NONE) = 0;
  49. /* Flush buffers. Warning! All characters in the buffer will be lost
  50. * forever. However, this is necessary to get the lines into a defined
  51. * state before sending e.g. a command */
  52. virtual void FlushInput() = 0;
  53. virtual void FlushOutput() = 0;
  54. /* TRUE: everything ok
  55. * FALSE: error */
  56. virtual BOOL ClosePort() = 0;
  57. /* Return type of serial port */
  58. virtual SerialPortType GetPortType() = 0;
  59. /* Return the port number of this port on the current system */
  60. virtual int GetPortNum() = 0;
  61. /* Create a serial connection of specified type.
  62. * The port number starts counting from 1 (e.g. COM1,COM2,... LPT1,LPT2,...) */
  63. static CSerial *CreateInterface(SerialPortType type, int iPortNum, const char *cpPrinterName = NULL);
  64. /* Those methods will create specific types of serial connections.
  65. * They're invoked by the method above.
  66. * Note that in contrast to above method, this method will always return
  67. * a new serial port object and not a sharing proxy */
  68. static CSerial *CreateCOMPortInterface(int iPortNum,int iBaudRate);
  69. /** Dummy implementation for USB. Much to do!!! Not implemented yet. */
  70. static CSerial *CreateUSBPortInterface(int iPortNum,int iBaudRate);
  71. static CSerial *CreateBravoInterface(const char *cpPrinterName);
  72. };
  73. #endif // CSERIAL_H