home *** CD-ROM | disk | FTP | other *** search
/ TestDrive Super Store 2.3 / TESTDRIVE_2.ISO / realizer / lib / stdcomm.rlz < prev    next >
Encoding:
Text File  |  1992-09-30  |  4.2 KB  |  156 lines

  1. '***********************************************************************
  2. '    StdComm.rlz Version 1.1
  3. '
  4. '    Standard Serial Communication Library
  5. '
  6. '    Copyright ⌐ 1991-1992 Computer Associates International, Inc.
  7. '    All rights reserved.
  8. '
  9. '***********************************************************************
  10.  
  11. IF QVar(%%StdComm, _Defined) THEN
  12.     EXIT MACRO
  13. END IF
  14. %%StdComm = 1
  15.  
  16. RUN "StdError"
  17.  
  18. CommError = {"Invalid port number", "Port is already open", "Port is not open", "Cannot allocate queues", "Default parameter error"}
  19. CommError[10:12] = {"Hardware device not found", "Illegal byte size", "Unsupported baud rate"}
  20.  
  21. '*** Constants for Parity
  22.  
  23. _NoParity = 0
  24. _OddParity = 1
  25. _EvenParity = 2
  26. _MarkParity = 3
  27. _SpaceParity = 4
  28.  
  29. '*** Constants for CommQ
  30.  
  31. _CQ_BaudRate = 1
  32. _CQ_ReadBuffSize = 2
  33. _CQ_WriteBuffSize = 3
  34. _CQ_ByteSize = 4
  35. _CQ_StopBits = 5
  36. _CQ_Parity = 6
  37. _CQ_ReadPending = 7
  38. _CQ_WritePending = 8
  39. _CQ_XON = 9
  40. _CQ_CID = 10
  41.  
  42. EXTERNAL "Standard" CUSTOMCONTROLS
  43.  
  44. %%_Frm_last = FormQ(_Selected)
  45. FormNew(32700)
  46. FormSetObject(10, "StdCommClass", "", 0, 0)
  47. IF %%_Frm_last THEN
  48.     FormSelect(%%_Frm_last)
  49. END IF
  50. CLEAR %%_Frm_last
  51.  
  52. PROC CommOpen(rsPortNum, rsBaudRate, rsReadBuffSize, rsWriteBuffSize, rsByteSize, rsStopBits, rsParity)
  53.     LOCAL retval
  54.  
  55.     EXTERNAL "standard.exe" FUNC SerialOpen(INTEGER, INTEGER, WORD, WORD, INTEGER, INTEGER, INTEGER) AS INTEGER
  56.  
  57.     ECType(rsPortNum, _Real + _Scalar, 1)
  58.     ECRange(rsPortNum, 1, 4, 1)
  59.     ECType(rsBaudRate, _Real + _Scalar, 2)
  60.     ECType(rsReadBuffSize, _Real + _Scalar, 3)
  61.     ECRange(rsReadBuffSize, 1, 65535, 3)
  62.     ECType(rsWriteBuffSize, _Real + _Scalar, 4)
  63.     ECRange(rsWriteBuffSize, 1, 65535, 4)
  64.     ECType(rsByteSize, _Real + _Scalar, 5)
  65.     ECRange(rsByteSize, 7, 8, 5)
  66.     ECType(rsStopBits, _Real + _Scalar, 6)
  67.     ECRange(rsStopBits, 1, 2, 6)
  68.     ECType(rsParity, _Real + _Scalar, 7)
  69.     ECRange(rsParity, 0, 4, 7)
  70.  
  71.     rsStopBits = 2 * (rsStopBits - 1)
  72.  
  73.     retval = SerialOpen(rsPortNum, rsBaudRate, rsReadBuffSize, rsWriteBuffSize, rsByteSize, rsStopBits, rsParity)
  74.     IF retval < 0 THEN
  75.         STOP USING CommError[retval * -1], 1
  76.     END IF
  77. END PROC
  78.  
  79. PROC CommClose(rsPortNum)
  80.     LOCAL retval
  81.  
  82.     EXTERNAL "standard.exe" FUNC SerialClose(INTEGER) AS INTEGER
  83.  
  84.     ECType(rsPortNum, _Real + _Scalar, 1)
  85.     ECRange(rsPortNum, 1, 4, 1)
  86.     retval = SerialClose(rsPortNum)
  87.     IF retval < 0 THEN
  88.         STOP USING CommError[retval * -1], 1
  89.     END IF
  90. END PROC
  91.  
  92. EXTERNAL "standard.exe" FUNC SerialRead(INTEGER, POINTER, INTEGER) AS INTEGER
  93. FUNC CommRead(rsPortNum, rsNumBytes)
  94.     LOCAL buffer, n
  95.  
  96.     ECType(rsPortNum, _Real + _Scalar, 1)
  97.     ECRange(rsPortNum, 1, 4, 1)
  98.     ECType(rsNumBytes, _Real + _Scalar, 2)
  99.     ECRange(rsNumBytes, 0, 65535, 2)
  100.  
  101.     buffer = String$(rsNumBytes + 1, 0)
  102.     n = SerialRead(rsPortNum, buffer, rsNumBytes)
  103.     IF n < 0 THEN
  104.         STOP USING CommError[n * -1], 1
  105.     ELSE
  106.         RETURN Left$(buffer, n)
  107.     END IF        
  108. END FUNC
  109.  
  110. EXTERNAL "standard.exe" FUNC SerialWrite(INTEGER, POINTER, INTEGER) AS INTEGER
  111. PROC CommWrite(rsPortNum, asData)
  112.     LOCAL buffer, n
  113.  
  114.     ECType(rsPortNum, _Real + _Scalar, 1)
  115.     ECRange(rsPortNum, 1, 4, 1)
  116.     ECType(asData, _Alpha + _Scalar, 2)
  117.     
  118.     n = SerialWrite(rsPortNum, asData, Len(asData))    
  119.  
  120.     IF n < 0 THEN
  121.         STOP USING CommError[n * -1], 1
  122.     END IF        
  123. END PROC
  124.  
  125. FUNC CommQ(rsPortNum)
  126.  
  127.     FUNC WordToReal(s)
  128.         RETURN Asc(Left$(s, 1)) + Asc(Right$(s, 1)) * 256
  129.     END FUNC
  130.  
  131.     LOCAL buffer, retval
  132.     
  133.     EXTERNAL "standard.exe" FUNC SerialQ(INTEGER, POINTER) AS INTEGER
  134.  
  135.     ECType(rsPortNum, _Real + _Scalar, 1)
  136.     ECRange(rsPortNum, 1, 4, 1)
  137.     buffer = String$(22, 0)
  138.     n = SerialQ(rsPortNum, buffer)
  139.     IF n < 0 THEN
  140.         STOP USING CommError[n * -1], 1
  141.     END IF        
  142.     retval[_CQ_BaudRate] = WordToReal(Mid$(Buffer, 3, 2))
  143.     retval[_CQ_ReadBuffSize] = WordToReal(Mid$(Buffer, 5, 2))
  144.     retval[_CQ_WriteBuffSize] = WordToReal(Mid$(Buffer, 7, 2))
  145.     retval[_CQ_ByteSize] = WordToReal(Mid$(Buffer, 9, 2))
  146.     retval[_CQ_StopBits] = (WordToReal(Mid$(Buffer, 11, 2)))/2 + 1
  147.     retval[_CQ_Parity] = WordToReal(Mid$(Buffer, 13, 2))
  148.     retval[_CQ_ReadPending] = WordToReal(Mid$(Buffer, 15, 2))
  149.     retval[_CQ_WritePending] = WordToReal(Mid$(Buffer, 17, 2))
  150.     retval[_CQ_XON] = WordToReal(Mid$(Buffer, 19, 2))
  151.     retval[_CQ_CID] = WordToReal(Mid$(Buffer, 21, 2))
  152.  
  153.     RETURN retval
  154. END FUNC
  155.  
  156.