home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / comm / simpcomm.frm (.txt) next >
Visual Basic Form  |  1992-07-22  |  15KB  |  313 lines

  1. Form1
  2. Form1
  3. wwwwwwwwwwwwwwp
  4. wwwwwwwwwwwwwwp
  5. Form1
  6. Timer_CheckReceiveBuffer
  7. Text_Display
  8. Courier
  9. Timer_ClearStatusMessage
  10. Command_Send
  11.     Send Text
  12. Label_StatusBar
  13. CommStateDCB
  14. CommStat
  15. COMSTAT
  16. ComID
  17.     Form_LoadI
  18. Label_StatusBar
  19. Form10
  20. ScaleWidth&
  21. ShowStatus
  22. OpenComm5
  23. ShowOpenCommError
  24. BaudRate
  25. ByteSize+
  26. Parity
  27. NOPARITY<
  28. StopBitsp
  29. ONESTOPBITX
  30. RlsTimeOutr
  31. CtsTimeOut#
  32. DsrTimeOut
  33. ModeControl
  34. XonCharY
  35. XoffChar
  36. XonLim
  37. XoffLim;
  38. peChar
  39. EofChar
  40. EvtChar
  41. SetCommState
  42. Timer_CheckReceiveBuffer
  43. Interval
  44. Enabled
  45. Truek
  46. Text_Display
  47. Command_Send_Click
  48. crlfc
  49. buffer
  50.     WriteComm
  51. ProcessCommError*
  52. Form_Unload
  53. Cancel
  54.     FlushComm
  55.     CloseComme
  56. Timer_ClearStatusMessage_Timer
  57. CaptionS
  58. Timer_ClearStatusMessage}
  59. False
  60.     ErrorCode
  61. IE_BADID
  62. messageD
  63. IE_BAUDRATEa
  64. IE_BYTESIZE
  65. IE_DEFAULT
  66. IE_HARDWARE
  67.     IE_MEMORY
  68. IE_NOPEN
  69. IE_OPEN
  70. GetCommError
  71. CE_BREAK
  72. ShowMessage
  73. CE_CTSTO%
  74. CE_DSRTO
  75. CE_DNS
  76. CE_FRAME
  77. CE_IOE
  78. CE_MODE
  79. CE_OOPS
  80. CE_OVERRUN/
  81. CE_PTO
  82.     CE_RLSDTO
  83.     CE_RXOVER
  84. CE_RXPARITY
  85.     CE_TXFULL(
  86. Timer_CheckReceiveBuffer_Timer
  87. ReadComm
  88. SelStart
  89. SelText
  90.     StatusMsg
  91. Label_StatusBar_Click
  92. Form_Click
  93. Form_LinkOpen
  94. Text_Display_Change
  95. ComStatusCode
  96. Response[
  97. DefMsgCaption
  98. decided
  99.     currently
  100. * GENERAL DECLARATIONS section of Form1*
  101. COM Device Control Block (DCB) record structure variable
  102. This is a parameter needed by the Windows SetCommState API
  103. function. 
  104. Refer to Form_Load event procedure for an example of
  105. how initialize the COM DCB
  106. COM status variable.
  107. This is a parameter needed by the Windows GetCommError API
  108. function
  109. Identifies the COM port that was opened.
  110. Used by or returned by the Windows API functions
  111. OpenComm, GetCommState, SetCommEventMask, GetCommEventMask,
  112. ReadComm, WriteComm, FlushComm, CloseComm 
  113. Form_Load
  114. * Form_Load event procedure for Form1*
  115. * This is starting point of the program.
  116. * Create the following controls with the
  117. * following CtlNames on Form1:
  118. * Controln
  119. * (Default Name)
  120.  CtlName
  121.  Notes
  122. *   Text1
  123.  Text_Display
  124.  Set the MultiLine property to True*
  125. *   Command1
  126.      Command_Send
  127.  Set caption property to "Send Text"*
  128. *   Timer1
  129.  Timer_CheckReceiveBuffert
  130. *   Timer2
  131.  Timer_ClearStatusMessaget
  132. *   Label1
  133.  Label_StatusBar
  134. * This event procedure demonstrates how to call the Windows API functions,
  135. * OpenComm and SetCommState to open the COM port.  In this example, then
  136. * COM port is opened as the following equivalent QuickBASIC OPEN COM string:
  137.  "COM1:1200,N,8,1,DS0,CS0,CD0,RS,TB2048,RB2048"
  138. Move the COM status window to the bottom of the form
  139. Show a status message indicating that the COM port is being opened
  140. Opening COM1 ...#
  141. Open COM1 with a 2K input and output buffer
  142. COM device already opened"
  143. Do you wish to use it anyway
  144. Communications Error
  145. Close the com port if the user selected Yes from the message box
  146. Close the COM port if the user decided to use it anywayd
  147. Display a message and terminate the program
  148. if the user decided not to use the COM port
  149. that is currently open
  150. Terminating application"
  151. Communications Abort
  152. Display a critical error message and terminate the program
  153. Error occurred attempting to open the COM port."
  154.   Check connection, settings and rerun the program
  155. Communications Error
  156. Set line settings for the COM port as 1200:N,8,1,CD0,CS0,DS0,RS,TB2048,RB2048c
  157. The following parameter settings represent the default settings set by calling
  158. BuildCommDCB in the Form_Load event procedure.
  159. Set parameters as 1200: N,8,1 
  160. Other possible values include 300, 2400, 4800, 9600, 19200
  161. Other possible values include 4,5,6,70
  162. Other possible values include EVENPARITY, MARKPARITY, ODDPARITY, SPACEPARITY
  163. Other possible values include ONE5STOPBITS, TWOSTOPBITSD
  164. Set timeout period for CD, CS and DS handshake lines respectively.  Values
  165. represent milliseconds.  A value of zero represents an infinite wait effectively
  166. disabling handshaking on that line.  Possible values can range from 0 to 65,535y
  167. for an unsiged integer or -32,768 to 32,767 for signed integers.
  168. Carrier detect or receive-line-signal-detect (CD or RLSD) line (CD0)
  169. Clear-to-send (CTS) line (CS0)
  170. Data-set-ready (DSR) line (DS0)
  171. The following bit flags are combined in the ModeControl field below.  Because)
  172. the following are bit fields they cannot be represented as a field of a Type ... End TypeY
  173. structurew
  174. DCB.fBinary = 1
  175.  Specify binary mode.  Setting this to zero causes an
  176.  EOF character (Chr$(26)) to signal the end of data.
  177. DCB.fRtsDisabled = 1
  178.  Disable request-to-send line (RS).  A zero value enables.
  179.  the request-to-send lineb
  180. DCB.fParity = 0
  181.  Disable parity checking.  A value of 1 enables parity checking
  182. DCB.fOutCtsFlow = 0
  183.  Disable checking of clear-to-send line for output flow control
  184. DCB.fOutxDsrFlow = 0
  185.  Disable checking of data-set-ready (DSR) line for output flow control
  186. DCB.fDummy = 0 + 0
  187.      Two bit reserved fieldd
  188. DCB.fDtrDisabled = 1
  189.  Disable the data-set-ready line (DTR).  A value of 1 enables DTR.
  190. DCB.fOutX = 0
  191.  Disable XON/XOFF during transmission.e
  192.  A value of 1 enables XON/XOFF.d
  193. DCB.fInX = 0
  194.  Disable XON/XOFF during reception.i
  195.  A value of 1 enables XON/XOFF
  196. DCB.fPeChar = 0
  197.  Disable the replace of parity error characters with the character 
  198.  contained in the PeChar field.  A value of 1 enables replacementt
  199.  of parity error characters with the character contained in then
  200.  PeChar field.
  201. DCB.fNull = 0
  202.  Received null characters are not to be discarded.  A value of 1c
  203.  specifies that null characters received will be discarded.d
  204. DCB.fChEvt = 0
  205.  Reception of the character contained in the EvtChar field doesc
  206.  not signify an event.  A value of 1 indicates that thet
  207.  reception of a character identical to the character contained
  208.  in the EvtChar field signifies and event.
  209. DCB.fDtrFlow = 0
  210.  The DTR line is not used for receive flow control.  A value of 1 
  211.  indicates that the DTR line is used for receive flow control.
  212. DCB.fRtsFlow = 0
  213.  The RTS line is not used for receive flow control.  A value of 1 
  214.  indicates that the DTR line is used for receive flow control.
  215. DCB.fDummy = 0
  216.  Reserved 
  217. 1100 0001 
  218.  Binary representationr
  219.  of the above bit settings
  220.      Hex representation of the abovee
  221.  bit settings 
  222.             DCB.ModeControl = &H83     'Based on the bit settings above
  223. Setting COM State ... #
  224. Set the COM port with the settings as indicated aboveo
  225. Error occurred during initialization of COM settings."
  226.   Check connection, settings and rerun this program"
  227. Communications Error
  228. Start the timer to continuously check the receive buffer
  229. Start the timer only if no errors occurred
  230. Set the focus on the text boxr
  231. Command_Send_Click
  232. * This event procedure demonstrates how to call the Windows*
  233. * API function WriteComm to send data out the COM port.d
  234. * Click event procedure for the command button
  235. * (CtlName: Command_Send) that causes the contents
  236. * of the text box (CtlName: Text_Display) to be sent
  237. * out the COM port.C
  238. * Status information is displayed within caption of a
  239. * label (CtlName: Label_StatusBar).i
  240. Get the data to be sent from the text box.  Note: All*
  241. of the text contained in the text box is sent.
  242. Send the contents of the output buffer out the COM port
  243. Display any communications errors that might have occurred
  244. when attempting to write to the COM port
  245. Form_Unload
  246. * This event procedure demonstrates how to call the Windows API functions*
  247. * FlushComm and CloseComm to close the COM port.
  248. * Close the COM port and end the program.M
  249. Flush the COM transmit and receive buffers.  Note: the return value represents
  250. the success of the FlushComm function call.  Zero = success; Negative = non-successs
  251. The return value is ignored in this example.
  252. Flush all characters in the transmit buffer;
  253. Flush all characters in the receive buffer
  254. Error Closing the COM Port
  255. Communications Error
  256. Timer_ClearStatusMessage_Timer
  257. * Clear the COM status window and disable the timer*
  258. ShowOpenCommError
  259. * Displays a message box for any communications error that
  260. * may have occurred while attempting to open the COM port.
  261. Invalid or unsupported ID"
  262. Unsupported baud rate"
  263. Invalid byte size"
  264. Error in default parameters"
  265. Hardware not present
  266. Unable to allocate queues"
  267. Device not open"
  268. Device already opened"
  269. Communications Error
  270. ProcessCommError
  271. * Display message boxes for any communications
  272. * errors that may occurred when attempting to read from or write to*
  273. * the COM port.  Since more than 1 error can occur when attempting
  274. * to read from or write to the COM port, several messages boxes may
  275. * be displayed.o
  276. * IMPORTANT: If an error occurs during communications, Windows locks
  277.  the COM port.  The COM port can only be unlocked byW
  278.  calling the Windows API function GetCommError.
  279. Character representing a carriage-return
  280. Find out if an error occurs.  Calling GetCommError clears*
  281. the error and causes Windows to unlock the COM port.
  282. Break condition detected
  283. Clear-to-send (CTS) timeout"
  284. Data-set-ready (DSR) timeout
  285. Parallel device is not selected"
  286. Framing error detected
  287. Device I/O error occurred"
  288. attempting to communicate with parallel device
  289. Requested mode is not supported"
  290. Out of paper on parallel device"
  291. Overrun error detected
  292. Timeout attempting to communicate with
  293. parallel device"
  294. Receive-line-signal-detect timeout
  295. Receive buffer overflow"
  296. Parity error detected"
  297. Transmit buffer full
  298. Communications Error
  299. Timer_CheckReceiveBuffer_Timer
  300. * This event procedure demonstrates how to call the Windows*
  301. * API function ReadComm to read information from the COM
  302. * port
  303. Read in up to 2K of data from the COM receive buffer
  304. Read characters waiting in the receive buffer.
  305. If characters were returned in the buffer, display them*
  306. in the text box.  The absolute value of the return value
  307. for ReadComm indicates how many characters were read from the COM.
  308. Display any errors that may have occurred reading from the COM
  309. ShowStatus
  310. * Show a COM status message at the bottom of the form*
  311. Show the message
  312. Set the timer interval to clear the message*
  313.