Form1 Form1 wwwwwwwwwwwwwwp wwwwwwwwwwwwwwp Form1 Timer_CheckReceiveBuffer Text_Display Courier Timer_ClearStatusMessage Command_Send Send Text Label_StatusBar CommStateDCB CommStat COMSTAT ComID Form_LoadI Label_StatusBar Form10 ScaleWidth& ShowStatus OpenComm5 ShowOpenCommError BaudRate ByteSize+ Parity NOPARITY< StopBitsp ONESTOPBITX RlsTimeOutr CtsTimeOut# DsrTimeOut ModeControl XonCharY XoffChar XonLim XoffLim; peChar EofChar EvtChar SetCommState Timer_CheckReceiveBuffer Interval Enabled Truek Text_Display Command_Send_Click crlfc buffer WriteComm ProcessCommError* Form_Unload Cancel FlushComm CloseComme Timer_ClearStatusMessage_Timer CaptionS Timer_ClearStatusMessage} False ErrorCode IE_BADID messageD IE_BAUDRATEa IE_BYTESIZE IE_DEFAULT IE_HARDWARE IE_MEMORY IE_NOPEN IE_OPEN GetCommError CE_BREAK ShowMessage CE_CTSTO% CE_DSRTO CE_DNS CE_FRAME CE_IOE CE_MODE CE_OOPS CE_OVERRUN/ CE_PTO CE_RLSDTO CE_RXOVER CE_RXPARITY CE_TXFULL( Timer_CheckReceiveBuffer_Timer ReadComm SelStart SelText StatusMsg Label_StatusBar_Click Form_Click Form_LinkOpen Text_Display_Change ComStatusCode Response[ DefMsgCaption decided currently * GENERAL DECLARATIONS section of Form1* COM Device Control Block (DCB) record structure variable This is a parameter needed by the Windows SetCommState API function. Refer to Form_Load event procedure for an example of how initialize the COM DCB COM status variable. This is a parameter needed by the Windows GetCommError API function Identifies the COM port that was opened. Used by or returned by the Windows API functions OpenComm, GetCommState, SetCommEventMask, GetCommEventMask, ReadComm, WriteComm, FlushComm, CloseComm Form_Load * Form_Load event procedure for Form1* * This is starting point of the program. * Create the following controls with the * following CtlNames on Form1: * Controln * (Default Name) CtlName Notes * Text1 Text_Display Set the MultiLine property to True* * Command1 Command_Send Set caption property to "Send Text"* * Timer1 Timer_CheckReceiveBuffert * Timer2 Timer_ClearStatusMessaget * Label1 Label_StatusBar * This event procedure demonstrates how to call the Windows API functions, * OpenComm and SetCommState to open the COM port. In this example, then * COM port is opened as the following equivalent QuickBASIC OPEN COM string: "COM1:1200,N,8,1,DS0,CS0,CD0,RS,TB2048,RB2048" Move the COM status window to the bottom of the form Show a status message indicating that the COM port is being opened Opening COM1 ...# Open COM1 with a 2K input and output buffer COM device already opened" Do you wish to use it anyway Communications Error Close the com port if the user selected Yes from the message box Close the COM port if the user decided to use it anywayd Display a message and terminate the program if the user decided not to use the COM port that is currently open Terminating application" Communications Abort Display a critical error message and terminate the program Error occurred attempting to open the COM port." Check connection, settings and rerun the program Communications Error Set line settings for the COM port as 1200:N,8,1,CD0,CS0,DS0,RS,TB2048,RB2048c The following parameter settings represent the default settings set by calling BuildCommDCB in the Form_Load event procedure. Set parameters as 1200: N,8,1 Other possible values include 300, 2400, 4800, 9600, 19200 Other possible values include 4,5,6,70 Other possible values include EVENPARITY, MARKPARITY, ODDPARITY, SPACEPARITY Other possible values include ONE5STOPBITS, TWOSTOPBITSD Set timeout period for CD, CS and DS handshake lines respectively. Values represent milliseconds. A value of zero represents an infinite wait effectively disabling handshaking on that line. Possible values can range from 0 to 65,535y for an unsiged integer or -32,768 to 32,767 for signed integers. Carrier detect or receive-line-signal-detect (CD or RLSD) line (CD0) Clear-to-send (CTS) line (CS0) Data-set-ready (DSR) line (DS0) The following bit flags are combined in the ModeControl field below. Because) the following are bit fields they cannot be represented as a field of a Type ... End TypeY structurew DCB.fBinary = 1 Specify binary mode. Setting this to zero causes an EOF character (Chr$(26)) to signal the end of data. DCB.fRtsDisabled = 1 Disable request-to-send line (RS). A zero value enables. the request-to-send lineb DCB.fParity = 0 Disable parity checking. A value of 1 enables parity checking DCB.fOutCtsFlow = 0 Disable checking of clear-to-send line for output flow control DCB.fOutxDsrFlow = 0 Disable checking of data-set-ready (DSR) line for output flow control DCB.fDummy = 0 + 0 Two bit reserved fieldd DCB.fDtrDisabled = 1 Disable the data-set-ready line (DTR). A value of 1 enables DTR. DCB.fOutX = 0 Disable XON/XOFF during transmission.e A value of 1 enables XON/XOFF.d DCB.fInX = 0 Disable XON/XOFF during reception.i A value of 1 enables XON/XOFF DCB.fPeChar = 0 Disable the replace of parity error characters with the character contained in the PeChar field. A value of 1 enables replacementt of parity error characters with the character contained in then PeChar field. DCB.fNull = 0 Received null characters are not to be discarded. A value of 1c specifies that null characters received will be discarded.d DCB.fChEvt = 0 Reception of the character contained in the EvtChar field doesc not signify an event. A value of 1 indicates that thet reception of a character identical to the character contained in the EvtChar field signifies and event. DCB.fDtrFlow = 0 The DTR line is not used for receive flow control. A value of 1 indicates that the DTR line is used for receive flow control. DCB.fRtsFlow = 0 The RTS line is not used for receive flow control. A value of 1 indicates that the DTR line is used for receive flow control. DCB.fDummy = 0 Reserved 1100 0001 Binary representationr of the above bit settings Hex representation of the abovee bit settings DCB.ModeControl = &H83 'Based on the bit settings above Setting COM State ... # Set the COM port with the settings as indicated aboveo Error occurred during initialization of COM settings." Check connection, settings and rerun this program" Communications Error Start the timer to continuously check the receive buffer Start the timer only if no errors occurred Set the focus on the text boxr Command_Send_Click * This event procedure demonstrates how to call the Windows* * API function WriteComm to send data out the COM port.d * Click event procedure for the command button * (CtlName: Command_Send) that causes the contents * of the text box (CtlName: Text_Display) to be sent * out the COM port.C * Status information is displayed within caption of a * label (CtlName: Label_StatusBar).i Get the data to be sent from the text box. Note: All* of the text contained in the text box is sent. Send the contents of the output buffer out the COM port Display any communications errors that might have occurred when attempting to write to the COM port Form_Unload * This event procedure demonstrates how to call the Windows API functions* * FlushComm and CloseComm to close the COM port. * Close the COM port and end the program.M Flush the COM transmit and receive buffers. Note: the return value represents the success of the FlushComm function call. Zero = success; Negative = non-successs The return value is ignored in this example. Flush all characters in the transmit buffer; Flush all characters in the receive buffer Error Closing the COM Port Communications Error Timer_ClearStatusMessage_Timer * Clear the COM status window and disable the timer* ShowOpenCommError * Displays a message box for any communications error that * may have occurred while attempting to open the COM port. Invalid or unsupported ID" Unsupported baud rate" Invalid byte size" Error in default parameters" Hardware not present Unable to allocate queues" Device not open" Device already opened" Communications Error ProcessCommError * Display message boxes for any communications * errors that may occurred when attempting to read from or write to* * the COM port. Since more than 1 error can occur when attempting * to read from or write to the COM port, several messages boxes may * be displayed.o * IMPORTANT: If an error occurs during communications, Windows locks the COM port. The COM port can only be unlocked byW calling the Windows API function GetCommError. Character representing a carriage-return Find out if an error occurs. Calling GetCommError clears* the error and causes Windows to unlock the COM port. Break condition detected Clear-to-send (CTS) timeout" Data-set-ready (DSR) timeout Parallel device is not selected" Framing error detected Device I/O error occurred" attempting to communicate with parallel device Requested mode is not supported" Out of paper on parallel device" Overrun error detected Timeout attempting to communicate with parallel device" Receive-line-signal-detect timeout Receive buffer overflow" Parity error detected" Transmit buffer full Communications Error Timer_CheckReceiveBuffer_Timer * This event procedure demonstrates how to call the Windows* * API function ReadComm to read information from the COM * port Read in up to 2K of data from the COM receive buffer Read characters waiting in the receive buffer. If characters were returned in the buffer, display them* in the text box. The absolute value of the return value for ReadComm indicates how many characters were read from the COM. Display any errors that may have occurred reading from the COM ShowStatus * Show a COM status message at the bottom of the form* Show the message Set the timer interval to clear the message*