home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 September / CHIP_CD_1997_09_PL.iso / software / testsoft / labwind / demo.6 / main / include / rs232.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-02  |  7.5 KB  |  173 lines

  1. /*============================================================================*/
  2. /*                        L a b W i n d o w s / C V I                         */
  3. /*----------------------------------------------------------------------------*/
  4. /*    Copyright (c) National Instruments 1987-1996.  All Rights Reserved.     */
  5. /*----------------------------------------------------------------------------*/
  6. /*                                                                            */
  7. /* Title:       rs232.h                                                       */
  8. /* Purpose:     Include file for RS-232 library support.                      */
  9. /*                                                                            */
  10. /*============================================================================*/
  11.  
  12. #ifndef RS232_HEADER
  13. #define RS232_HEADER
  14.  
  15. #include "cvidef.h"
  16. #include "cvirte.h"
  17.  
  18. #ifdef __cplusplus
  19.     extern "C" {
  20. #endif
  21.  
  22. /* Escape Codes */
  23. #define SETXOFF             1       /* Simulate XOFF received      */
  24. #define SETXON              2       /* Simulate XON received       */
  25. #define SETRTS              3       /* Set RTS high                */
  26. #define CLRRTS              4       /* Set RTS low                 */
  27. #define SETDTR              5       /* Set DTR high                */
  28. #define CLRDTR              6       /* Set DTR low                 */
  29. #define RESETDEV            7       /* Reset device if possible    */
  30. #define GETMAXCOM           9       /* return highest com number   */
  31. /* RS485 only */
  32. #define WIRE_4              128     /* Set 4-wire wiring mode (0 to Scratchpad) */
  33. #define WIRE_2_ECHO         129     /* Set 2-wire, DTR echo mode (1 to Scratchpad) */
  34. #define WIRE_2_CTRL         130     /* Set 2-wire, DTR controlled mode (2 to Scratchpad) */
  35. #define WIRE_2_AUTO         131     /* Set 2-wire, TxRdy auto control (3 to scratchpad) */
  36.  
  37. /* variables */
  38. #ifdef USE_FUNCS_FOR_VARS
  39.     extern int *CVIFUNC_C _GetRs232Err(void);
  40.     #define rs232err (*_GetRs232Err())
  41. #else
  42.     extern int rs232err;
  43. #endif
  44.  
  45. /* exported functions */
  46. int CVIFUNC CloseCom(int portNo);
  47. int CVIFUNC ComBreak(int portNo, int milliSec);
  48. int CVIFUNC ComFromFile(int portNo, int handle, int maxCnt, int termCh);
  49. int CVIFUNC ComRd(int portNo, char buf[], int maxCnt);
  50. int CVIFUNC ComRdByte(int portNo);
  51. int CVIFUNC ComRdTerm(int portNo, char buf[], int   maxCnt, int termCh);
  52. int CVIFUNC ComToFile(int portNo, int handle, int   maxCnt, int termCh);
  53. int CVIFUNC ComWrt(int portNo, const char *buf, int maxCnt);
  54. int CVIFUNC ComWrtByte(int portNo, int byte);
  55. int CVIFUNC FlushInQ(int portNo);
  56. int CVIFUNC FlushOutQ(int portNo);
  57. int CVIFUNC GetComStat(int portNo);
  58. int CVIFUNC GetInQLen(int portNo);
  59. int CVIFUNC GetOutQLen(int portNo);
  60. int CVIFUNC OpenCom(int portNo, const char deviceName[]);
  61. int CVIFUNC OpenComConfig(int portNo, const char deviceName[], int baudRate, int parity,
  62.                   int dataBits, int stopBits, int iqSize,
  63.                   int oqSize);
  64. int CVIFUNC SetComTime(int portNo, double seconds);
  65. int CVIFUNC SetCTSMode(int portNo, int mode);
  66. int CVIFUNC SetXMode(int portNo, int mode);
  67. int CVIFUNC XModemConfig(int portNo, double startDelay, int maxTries,
  68.                  double waitPeriod, int packetSize);
  69. int CVIFUNC XModemReceive(int portNo, const char pathName[]);
  70. int CVIFUNC XModemSend(int portNo, const char pathName[]);
  71. int CVIFUNC ReturnRS232Err(void);
  72.  
  73. #if defined(_NI_mswin16_) || defined(_NI_mswin32_) || defined(_NI_mswin_)
  74. typedef void (CVICALLBACK *ComCallbackPtr) (int portNo, int eventMask, void *callbackData);
  75. int CVIFUNC InstallComCallback(int  portNo, int eventMask, int notifyCount,
  76.       int eventCharacter, ComCallbackPtr callbackPtr, void *CallbackData);
  77.  
  78. int CVIFUNC ComSetEscape(int portNo, int escapeCode);
  79. #endif
  80.  
  81. char * CVIFUNC GetRS232ErrorString(int errorNum);
  82.  
  83.  
  84.  
  85. /* error codes returned by RS-232 functions */
  86. typedef enum {
  87.     kRS_UnknownSysError          =  -1,
  88.     kRS_InvalidPortNum           =  -2,
  89.     kRS_PortNotOpen              =  -3,
  90.     kRS_UnknownIOError           =  -4,
  91.     kRS_InternalError            =  -5,
  92.     kRS_NoPortFound              =  -6,
  93.     kRS_CanNotOpenPort           =  -7,
  94.     kRS_OutOfMemory              =  -11,
  95.     kRS_InvalidParameter         =  -13,
  96.     kRS_InvalidBaudRate          =  -14,
  97.     kRS_InvalidParity            =  -24,
  98.     kRS_InvalidDataBits          =  -34,
  99.     kRS_InvalidStopBits          =  -44,
  100.     kRS_BadFileHandle            =  -90,
  101.     kRS_FileIOError              =  -91,
  102.     kRS_InvalidCount             =  -94,
  103.     kRS_InvalidIntLevel          =  -97,
  104.     kRS_IOTimeOut                =  -99,
  105.     kRS_OutOfRange255            =  -104,
  106.     kRS_InvalidInQSize           =  -114,
  107.     kRS_InvalidOutQSize          =  -124,
  108.     kRS_GeneralIOFailure         =  -151,
  109.     kRS_InvalidBufferPointer     =  -152,
  110.     kRS_NoAckReceived            =  -257,
  111.     kRS_MaxRetriesBeforeSend     =  -258,
  112.     kRS_MaxRetriesBeforeReceived =  -259,
  113.     kRS_UnexpectedEOT            =  -260,
  114.     kRS_CanNotReadPackNum        =  -261,
  115.     kRS_InconsistentPackNum      =  -262,
  116.     kRS_CanNotReadPackData       =  -263,
  117.     kRS_CanNotReadCheckSum       =  -264,
  118.     kRS_CheckSumError            =  -265,
  119.     kRS_PackSizeGTInQ            =  -269,
  120.     kRS_OpenFileError            =  -300,
  121.     kRS_ReadFileError            =  -301,
  122.     kRS_NoInitNegAck             =  -302,
  123.     kRS_NoAckAfterEOT            =  -303,
  124.     kRS_WriteFileError           =  -304,
  125.     kRS_NoSOHorEOT               =  -305,
  126.     kRS_TransferCancelled        =  -402,
  127.     kRS_InvalidStartDelay        =  -503,
  128.     kRS_InvalidMaxTries          =  -504,
  129.     kRS_InvalidWaitPeriod        =  -505,
  130.     kRS_InvalidPacketSize        =  -506,
  131.     kRS_CanNotReadCRC            =  -507,
  132.     kRS_CRCError                 =  -508
  133. } RS232ErrorType;
  134.  
  135. /* event Mask defines for InstallComCallback (only for Windows) */
  136. #if defined(_NI_mswin16_) || defined(_NI_mswin32_) || defined(_NI_mswin_)
  137. #define LWRS_RECEIVE    0x8000  /* notifyCount bytes in inqueue   */
  138. #define LWRS_RXCHAR     0x0001  /* Any Character received         */
  139. #define LWRS_RXFLAG     0x0002  /* Received certain character     */
  140. #define LWRS_TXEMPTY    0x0004  /* Transmit Queue Empty           */
  141. #define LWRS_CTS        0x0008  /* CTS changed state              */
  142. #define LWRS_DSR        0x0010  /* DSR changed state              */
  143. #define LWRS_RLSD       0x0020  /* RLSD changed state             */
  144. #define LWRS_BREAK      0x0040  /* BREAK received                 */
  145. #define LWRS_ERR        0x0080  /* Line status error occurred     */
  146. #define LWRS_RING       0x0100  /* Ring signal detected           */
  147. #endif
  148.  
  149. /* modes for SetCTSMode() */
  150. #define LWRS_HWHANDSHAKE_OFF                   0
  151. #define LWRS_HWHANDSHAKE_CTS_RTS_DTR           1
  152. #define LWRS_HWHANDSHAKE_CTS_RTS               2
  153.  
  154. /* status codes return through GetComStat */
  155. #define kRS_InputLost                   0x00000001
  156. #define kRS_AsynError                   0x00000002
  157. #define kRS_ParityError                 0x00000010
  158. #define kRS_OverrunError                0x00000020
  159. #define kRS_FramingError                0x00000040
  160. #define kRS_BreakSignal                 0x00000080
  161. #define kRS_RemoteXoff                  0x00001000
  162. #define kRS_RemoteXon                   0x00002000
  163. #define kRS_LocalXoff                   0x00004000
  164. #define kRS_LocalXon                    0x00008000
  165.  
  166.  
  167.  
  168. #ifdef __cplusplus
  169.     }
  170. #endif
  171.  
  172. #endif /* RS232_HEADER */
  173.