MSCOMM control properties

xiaoxiao2021-03-06  20

The attribute of the MSCOMM control (must be familiar with several -commport: settings and return to the communication port number; setting: set and return data transfer rate, parity, data bits, stop bits) in the form of strings; portopen: Settings and Returns the status of the communication port, or close the port; INPUT: returns and deletes the character from the received buffer; OUTPUT: set a string to the transfer buffer) 1) CommPort property void setcommport (short nnewvalue); Short getcommport () This property is set and returned to the serial port number, and Windows will use the serial port and external communication. When designing, NNewValue can be set to any number of 1 to 16 (the default is 1). However, if you open an unsaved port with the Portopen property, the MSCOMM control generates an error 68 (if the device is invalid). Note: You must set the CommPort property before opening the port. 2) Settings attribute void settings (LPCTSTR LPSZNEWVALUE); String getSettings (); This property is used to set and return data transfer rate, parity, data bits, stop bit parameters. When the port is open, if the Value is illegal, the MSCOMM control generates an error 380 (illegal attribute value). The LPSZNewValue is represented by string, consists of four set values, and there is a format: "BBBB, P, D, S" BBBB is the data transfer rate, P is parity, D is the data bit, s stop bit . Value's default is: "9600, N, 8, 1", the legal value of the data transmission rate can be 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 115200 12800, 25600. The parity value can be set to any of the table below. Set Value Description E E-Volume (EVEN) M Number Calibration (MARK) N - None Check (NONE) O odor test (ODD) Space check (Space) data bit data can be 4, 5, 6, 7,8. The number of stops can be 1, 1.5, 2. Note: The communication connection can only take effect only when the settings attribute value of the two parties of the communication. 3) Handshaking Attribute This property is used to set or return the hardware handshake protocol, that is, the internal protocol set between the PC and the communication device to control the flow rate. The attribute value can be set to any of the following table.

Set value value Description Comnone 0 default value, no handshake protocol ComxonxOff 1 XON / XOFF Handshake COMRTS 2 RTS / CTS Handshake COMRTSXONXOFF 3 RTS / CTS and XON / XOFF Handshake can be 4) Rthreshold property Void setRTHRESHOLD (Short nnewvalue); Short GetRTHRESHOLD (); Set the number of characters to receive and returned before the MSCOMM control sets the COMMEVRRECEIVE and generates ONCOMM. Here NNEWVALUE is a short type parameter indicating the number of characters to receive before generating an ONCOMM event. When the character is received, if the RTHRESHOLD property is set to 0 (the default value), the ONCOMM event will not be generated. Otherwise, this property is a threshold. When the number of bytes of the buffer reaches or exceeds the value, the ONCOMM event is generated, for example, set RTHRESHOLD 1, and the receive buffer receives each character will cause the MSCOMM control to generate ONCOMM. event. 5) CTSHOLDING Attribute Void SetctSholding (Bool BNewValue); Bool getctSholding (); its property setting value is shown in the table below. Set value function Description True CTS line The high level FALSE CTS line is a low level This property determines whether data can be sent by querying the status of the CTS line. The CTS is a signal that the modem is sent to the connected computer, indicating that the transfer can be performed. This attribute is invalid when designing, is read-only at runtime. If the CTS line is a low level (CTSHOLDING = FALSE) and timeout, the MSCOMM control sets the COMMEVENT attribute to COMEVENTCTSTO (CLEAR TO Send Timeout) and generates ONCOMM Master. The CTS line is used for RTS / CTS hardware handshake. If you need to determine the state of the CTS line, the CTSHOLDING attribute gives a manual query method. 6) Sthreshold attribute void setsthreshold (short nnewvalue); short getsthreshold (); MSCOMM control Sets the COMMEVENT property to COMEVSEND and generate an oncomm event, set and return the minimum number of characters allowed in the transfer buffer. Here NNewValue is Short type data, which represents the minimum number of characters in the transport buffer before the ONCOMM event is generated. If the sthreshold property is 0 (default), the data transfer event does not generate an ONCOMM event. If the STHRESHOLD attribute is 0, the MSCOMM control generates an ONCOMM event when the transfer buffer is fully empty. If the number of characters in the transfer buffer is less than Value, the Commmevent property is set to COMEVSEND and generates an ONCOMM event. The COMEVSEND event is activated once when the character number is crossed in the character. For example, if STHRESHOLD is equal to 5, COMEVSEND occurs only when the number of characters from 5 in the output queue will occur. If there is no character than these characters in the output queue, the COMEVSEND event will never happen. 7) InputMode property Void setInputMode (long nnewvalue); long getInputMode (); Interview property is used to set or return the type of transfer data. The value and basic meanings are shown in the following table. Set value value Description CominputModeText (Default) 0 Retrieved Data by INPUT Property COMININPUTMODEBINARY 1 Remove data in binary in binary by input attribute

8) Inputlen attribute void setInputlen; short getInputlen (); this property is used and returned to the number of characters read from the received buffer. NNewValue is a SHORT type value, indicating that the INPUT number of characters read from the received buffer. The default value of the Inputlen property is 0. When INPUTLEN is set to 0, use INPUT will enable the MSCOMM control to read all content in the receiving buffer. If the Inputlen characters are invalid in the receiving buffer, the input property returns a zero-length string (""). Before using Input, the user can select Check the InbufferCount property to determine if there is a number of characters in the buffer. This attribute is very useful when reading data from the output format for the machine. 9) InBuffersize Attribute Void SetBuffersize (Short NnewValue); Short getinbuffersize (); InBuffersize property is used to set or return the size of the input buffer, the default is 1024 bytes. 10) InbufferCount property Void setinbuffercount (short nnewvalue); short getinbuffercount (); InBufferCount property is used to return the number of bytes of the words read within the input buffer, which can be cleared by this attribute value to clear the receiving buffer. 11) Input attribute Variant GetInput (); INPUT Attribute represents a string of characters from the receive buffer to read the data received in the buffer. The attribute value is a Varian type variable. This attribute is not available when the port is not open, and it is read-only at runtime. Note: When the inputmode property value is 0 (text mode), the variable contains String type data. When the inputMode property value is 1 (binary mode), the variable contains BYTE type array data. 12) Portopen Attribute Void SetPortopen (Bool BNewValue); Bool getPortopen (); Portopen property is used to open or close the port. If BNewValue is set to True, you can turn the port when it is set to FALSE. In general, open the port at the beginning of the program and turn off the port at the end of the program. When the application terminates, the MSCOMM control will automatically turn off the serial port. Determine the COMMPORT property to adjust the correct port number before opening the port. Moreover, the user's serial device must support settings in the settings property. If the hardware device does not support some settings in the settings attribute, the hardware work may not be correct. 13) Outbuffersize attribute void setBuffersize; Outbuffersize property is used to set or return the size of the send buffer, the value is a plastic expression, indicating the number of bytes of the transfer buffer, the default value of 512 bytes. The bigks the send buffer setting, the smaller the memory you can use. However, if the send buffer is too small, the buffer will overflow unless the handshake protocol is used. 14) OutbufferCounter Properties Void setBuffersize; short getoutbuffersize (); OutbufferCounter property is used to return the number of bytes sent in the transmit buffer, which can be empty by setting the attribute 0 to empty the buffer. 15) Output attribute void setput (const variant & newvalue); Output property is used to write data streams to the send buffer. The attribute is a Variant variable. This property is not available when the port is not open, just written at runtime. Note: Output properties can send text data or binary data.

When you transfer text data, the character data should be placed in a Variant variable; when transmitting binary data (ie byte transfer), the byte type data should be placed in a Variant type variable. If you usually send an ANSI string to your application, you can send it in text. If the data contains embedded control characters, NULL characters, etc., it must be transmitted as binary. 16) Commevent Attribute short getcommevent (); if an error or event occurs during the communication, the ONCOMM event will be triggered and its property value is changed. The Commevent property value reflects an error or event type, and the communication is designed to perform the same operation based on this attribute value. This attribute is not available when the port is not open, and it is read-only at runtime. The set value of the communication error and the communication event is shown in two tables. Communication Error Setting Value Setting Value Description COMEVENTBREAK 1001 Receive Interrupt Signal COMEVENTSTO 1002 CTS Timeout ComeventDSRTO 1003 DSR Timeout COMEVENTFRAME 1004 frame error, hardware detects an error, the format of both parties is inconsistent, this error comeventoverrun 1006 Port speed. A character is not read by the hardware before the next character arrives. This character is lost. COMEVENTCDTO 1007 data detection timeout COMEVENTRXOVER 1008 Receive buffer overflows COMEVENTRXPARITY 1009 parity error comeventtxful1 1010 Transmission buffer overflow, indicating that the output buffer is full, no longer Characters Output to Buffer COMEVENTDCB 1011 Retrieval Port, Unexpected Error Communication Event Setpoint When Device Control Block (DCB) Description COMEVSEND 1 Send Event. The contents of the send buffer less than the value of the value specified by STHRESHOLD 2 receive events. The number of characters in the receiving buffer reaches the RTHRESHOLD value. The event will continue to generate before the data is removed, and the process of receiving data can be written. Comevcts 3 CTS line change COMEVDSR 4 DSR line Change COMEVCD 5 CD Change COMEVRING 6 Ringing Detection ComeVeOf 7 File End. The file end (ASCII code 26) character appears in the receiving data

17) DTRENABLE attribute void setdtrenable (Bool BNewValue); BOOL getdtrenable (); DTRENABLE Attribute determines if the DTR line is used in communication, and DTR is a signal sent to the modem when the computer indicates that the computer is waiting for data transmission. 18) RTSenable Attribute Void SetrtSenable; Bool getSenable (); RTSenable property determines if the RTS line is valid. In general, the RTS signal is sent by the computer to the connected modem, and the request is allowed to send data. 19) Eofenable Attribute Void Seteofenable (Bool BNewValue); Bool getEofenable (); EOFENABLE Attribute determines if the MSCOMM control is looking for file end (EOF) characters during the input. If you find an EOF character, you will stop entering and activate the oncomm event. At this time, the commevent property is set to COMEVEOF. Here BNewValue is a Boolean expression, determine whether the ONCOMM event is activated when the EOF character is found. When BnewValue sets the value true, the ONCOMM event is activated when the EOF character is found. Otherwise, when the value value is set to False (default), the EOF character finds that the ONCOMM event is not activated. Note: When the Eofenable property is set to False, the ONCOMM control will not look for an EOF character in the input stream. 20) CDHOLDING attribute void setcdholding (Bool BNewValue); Bool getCDHolding (); Determine whether there is transmission in the current state of the CD line. The CD is a signal from the modem to the connected computer, indicating that the modem is online. This attribute is invalid when designing, is read-only at runtime. The setting value of the property is: When BNewValue is True, the CD line is high; when BNewValue is false, the CD line is low. Note When the CD line is a high level (CDHOLDING = True), the MSCOMM control sets the COMMEVENT property to COMEVENTCDTO (CD timeout error), and generates an ONCOMM event. Note: It is especially important to capture a lost transfer in the host application, such as a bulletin board, because the caller can hang (abandon the transmission). CD is also known as Receive Line Signal Detect (RLSD). 21) DSRHOLDING attribute void setdsrholding (Bool BNewValue); Bool getdsrholding (); determine the status of the DSR line. The DSR signal is sent from the modem to the connected computer, indicating the work preparation. This attribute is invalid when designing, is read-only at runtime. When the DSRHOLDING property is returned to TRUE, it means that the DSR line is high, and when FALSE is returned, the DSR line is low. When the DSR line is high-speed (dsRholding = true) timeout, the MSCOMM control sets the COMMEVENT attribute to COMEVENTDSRTO (data ready timeout) and generates an ONCOMM event. This property is intended when writing the DTE (DATA Terminal Equipment) machine. Author: blindpoint Home: www.blindpoint.net

转载请注明原文地址:https://www.9cbs.com/read-44375.html

New Post(0)