----MSCOMM32 Basic introduction of parameters
2008 year 03 month 29 Japan Saturday In the morning 11:37
MSComm Control transmits and receives data through a serial port , Provide serial communication function for application program .MSComm Control is very convenient in serial port programming , Programmers don't have to spend time understanding more complex API function , And in VC、VB、Delphi And so on . Microsoft Communications Control( hereinafter referred to as MSComm) yes Microsoft The simplification that the company offers Windows Serial communication programming ActiveX Control , It provides a simple way for application program to send and receive data through serial interface . Specifically , It provides two ways to deal with communication problems : One is event driven (Event-driven) Method , One is inquiry .
1.MSComm Control two ways to handle communication
MSComm Control provides the following two ways to handle communication : Event driven mode and query mode . 
1.1 Event driven way
Event driven communication is a very effective way to deal with serial port interaction . in many instances , Need to be informed when an event occurs , for example , There are characters in the serial port receive buffer , perhaps Carrier Detect (CD) or Request To Send (RTS) When a character on the line arrives or a change occurs . In these cases , You can use MSComm The control of OnComm Events capture and handle these communication events .OnComm Events can also check and handle communication errors . A list of all communication events and errors , Refer to the CommEvent attribute . During programming , You can go to OnComm Add your own processing code to the event handler . The advantage of this method is that the program responds in time , High reliability . Every MSComm Control corresponds to a serial port . If the application needs to access multiple serial ports , You have to use multiple MSComm Control .
1.2 A query
The query mode is essentially event driven , But in some cases , This is more convenient . After every key function of the program , It can pass the inspection CommEvent Property to query for events and errors . If the application is small , And it's self-sustaining , This approach may be preferable . for example , If you write a simple phone dialing program , There is no need to generate an event for every character received , Because the only character waiting to be received is the modem's “ determine ” Respond to .
2.MSComm Control
MSComm Control has many important properties , But first you have to be familiar with a few attributes .
CommPort Set and return the communication port number . 
Settings Sets and returns the baud rate as a string 、 Parity check 、 Data bits 、 Stop bit . 
PortOpen Set and return the status of the communication port . You can also open and close ports . 
Input Return and delete characters from receive buffer . 
Output Write a string to the transfer buffer .
Here are the descriptions of :
CommPort attribute Set and return the communication port number .
grammar : object.CommPort[value ] (value An integer value , State the port number .) 
explain : In design ,value It can be set from 1 To 16 Any number of ( The default value is 1). But if you use PortOpen Property to open a nonexistent port ,MSComm Control produces errors 68( Device invalid ).
Be careful : Must be set before opening the port CommPort attribute .
RThreshold attribute : stay MSComm Control settings CommEvent The attribute is comEvReceive And produce OnComm Before , Set and return the number of characters to receive .
grammar object.Rthreshold [ = value ](value Integer expression , The explanation is producing OnComm The number of characters to receive before the event . )
explain When the character is received , if Rthreshold Property is set to 0( The default value ) It doesn't produce OnComm event . for example , Set up Rthreshold by 1, Every character received in the receive buffer causes MSComm Control OnComm event .
CTSHolding attribute : Determine if it is possible to query Clear To Send (CTS) The state of the line sends data .Clear To Send It's a signal sent by the modem to the associated computer , Indicates that the transmission can proceed . This property is not valid at design time , Read only at run time .
grammar : object.CTSHolding(Boolean)
Mscomm The control of CTSHolding Property settings :
True      Clear To Send The line is high level . 
False     Clear To Send The line is low level .
explain : If Clear To Send The line is low level (CTSHolding = False) And super time ,MSComm Control settings CommEvent The attribute is comEventCTSTO (Clear To Send Timeout) And produce OnComm event .
Clear To Send Lines are used for RTS/CTS (Request To Send/Clear To Send) Hardware handshake . If you need to be sure Clear To Send The state of the line ,CTSHolding Attribute gives a manual query method .
Details About handshake protocol , see also Handshaking attribute .
SThreshold attribute : MSComm Control settings CommEvent The attribute is comEvSend And produce OnComm Before the incident , Sets and returns the minimum number of characters allowed in the transfer buffer .
grammar object.SThreshold [ = value ]
value Shaping expression , On behalf of the OnComm The minimum number of characters in the transport buffer before an event occurs .
explain : If set Sthreshold The attribute is 0( The default value ), Data transfer events do not occur OnComm event . If set Sthreshold The attribute is 1, When the transport buffer is completely empty ,MSComm Control OnComm event . If the number of characters in the transfer buffer is less than value,CommEvent Property is set to comEvSend, And produce OnComm event .comEvSend Event only if the number of characters and Sthreshold Cross is activated once . for example , If Sthreshold be equal to 5, Only if the number of characters in the output queue changes from 5 drop to 4 when ,comEvSend It just happened . If you've never been in the output queue better than Sthreshold More characters ,comEvSend It will never happen .

Handshake constant
constant           value           describe  
comNone       0            No handshake . 
comXonXoff    1           XOn/Xoff handshake . 
comRTS        2           Request-to-send/clear-to-send handshake . 
comRTSXOnXOff 3           Request-to-send and clear-to-send Shake hands .

OnComm constant
constant           value        describe  
comEvSend     1         Send events . 
comEvReceive 2         Receiving events . 
comEvCTS      3        clear-to-send Line change . 
comEvDSR      4        data-set ready Line change . 
comEvCD       5        carrier detect Line change . 
comEvRing     6         Ring detection . 
comEvEOF      7         End of file .

Error constant
constant              value          describe  
comEventBreak    1001    Received interrupt signal  
comEventCTSTO    1002   Clear-to-send Overtime  
comEventDSRTO    1003   Data-set ready Overtime  
comEventFrame    1004    Frame error  
comEventOverrun 1006    Port overspeed  
comEventCDTO     1007   Carrier detect Overtime  
comEventRxOver   1008    Receive buffer overflow  
comEventRxParity 1009   Parity error  
comEventTxFull   1010    The transport buffer is full  
comEventDCB      1011    Search port Device control block (DCB) An unexpected mistake in time
InputMode constant
constant                 value     describe  
comInputModeText   0    ( default ) adopt Input Property to retrieve data as text . 
comInputModeBinary 1      adopt Input Property to retrieve data in binary form .

CDHolding attribute : By inquiring Carrier Detect (CD) The state of the line determines whether there is currently a transmission .Carrier Detect It's a signal from the modem to the associated computer , Indicates that the modem is online . This property is not valid at design time , Read only at run time .
grammar object.CDHolding
Set the value :CDHolding Property is set to :
Set up     describe  
True    Carrier Detect The line is high level  
False   Carrier Detect The line is low level  
explain : Pay attention to when Carrier Detect The line is high level (CDHolding = True) And over time ,MSComm Control settings CommEvent The attribute is comEventCDTO(Carrier Detect Timeout error ), And produce OnComm event .
Be careful : It is particularly important to capture a lost transmission in the host application , For example, a bulletin board , Because callers can hang up at any time ( Give up transmission ).
Carrier Detect Also known as Receive Line Signal Detect (RLSD).
data type Boolean
DSRHolding attribute : determine Data Set Ready (DSR) The state of the line .Data Set Ready The signal is sent by the modem to the connected computer , Indicate to be ready for operation . This property is not valid at design time , Read only at run time .
grammar :object.DSRHolding
object Where represents the object expression , Its value is “ be applied to ” Objects in the list .
DSRHolding Property returns the following value :
value       describe  
True   Data Set Ready Line height  
False Data Set Ready The line is low  
explain : When Data Set Ready The line is high level (DSRHolding = True) And over time ,MSComm Control settings CommEvent The attribute is comEventDSRTO( Data preparation timed out ) And produce OnComm event . When it comes to Data Terminal Equipment (DTE) The machine writes Data Set Ready/Data Terminal Ready This property is very useful for handshake routines .
data type :Boolean

Settings attribute : Set and return baud rate 、 Parity check 、 Data bits 、 Stop bit parameter .
grammar : object.Settings[ = value]
explain : When the port is open , If value illegal , be MSComm Control has an error 380( Illegal attribute value ).
Value It consists of four settings , It has the following format :
"BBBB,P,D,S"
BBBB For baud rate ,P For parity ,D Is the number of data bits ,S For stop digits .
value The default value of is :"9600,N,8,1"

InputLen attribute : Set and return to Input Property the number of characters read from the receive buffer .
grammar object.InputLen [ = value]
InputLen Attribute syntax includes the following parts :
value Integer expression , explain Input Property the number of characters read from the receive buffer . 
explain :InputLen The default value of the property is 0. Set up InputLen by 0 when , Use Input Will make MSComm Control reads all the contents of the receive buffer .
If in the receive buffer InputLen Invalid character ,Input Property returns a zero length string (""). In the use of Input front , The user can choose to check InBufferCount Property to determine whether the required number of characters already exist in the buffer . This property is very useful when reading data from a machine whose output format is fixed length data .

EOFEnable attribute : Make sure that during the input process MSComm Control to find the end of the file (EOF) character . If you find EOF character , Will stop typing and activate OnComm event , here CommEvent Property is set to comEvEOF,
grammar :object.EOFEnable [ = value ]
EOFEnable Attribute syntax includes the following parts :
value Boolean expression , Make sure when you find EOF Character time ,OnComm Is the event activated , Such as “ Set the value ” As described in . 
value Set the value of :
True When EOF When the character is found OnComm The event is activated . 
False ( default ) When EOF When the character is found OnComm The event is not activated . 
explain : When EOFEnable Property is set to False,OnComm Control will not look for... In the input stream EOF character .

Error message (MS Comm Control )

The following table lists MSComm Control can catch errors :
value     describe  
380    Invalid property value comInvalidPropertyValue
383    Property is read-only comSetNotSupported
394    Property is read-only comGetNotSupported 
8000 Illegal operation when opening port comPortOpen
8001 The timeout value must be greater than 0 
8002 Invalid port number comPortInvalid
8003 Properties are only valid at run time  
8004 Property is read-only at run time  
8005 The port has been opened comPortAlreadyOpen
8006 The device identifier is invalid or not supported  
8007 Baud rate of the device is not supported  
8008 Invalid byte size specified  
8009 Default parameter error  
8010 Hardware not available ( Locked by other devices ) 
8011 Function cannot assign a queue  
8012 The device is not on comNoOpen 
8013 The device is on  
8014 Out of commission comm notice  
8015 Cannot set comm state comSetCommStateFailed
8016 Cannot set comm Event masking  
8018 The operation works only when the port is open comPortNotOpen 
8019 The device is busy  
8020 read comm Device error comReadError
8021 Internal error retrieving device control block for this port comDCBError

Use mscomm32.ocx Control
The script is as follows :
String ls_data
// Use COM1 port .
ole_1.object.CommPort = 1
// Set the rate to 9600, No parity ,8 Bit data , A stop bit .
ole_1.object.Settings = "9600,N,8,1"
// Read in the entire buffer .
ole_1.object.InputLen = 0

// Open the port
ole_1.object.PortOpen = True
// send out attention command
ole_1.object.Output = "ATV1Q0" + char(13)

// Waiting for data .
Do
Yield()
// from Com Port access data
ls_data += ole_1.object.Input
LOOP Until(Pos(ls_data, "OK" + char(13) + char (10)) > 0)

// towards Com Port to send data using Output Method
ole_1.Object.Output = ls_data
// Close the port .
ole_1.object.PortOpen = FALSE

PB Serial port programming information ( turn ) More articles about

  1. storysnail Of Linux Serial Programming Notes

    storysnail Of Linux Serial Programming Notes author He YiJun – storysnail<at>gmail.com The team ls Copyright Please keep this statement for reprint ! The original code contained in this document is based on Ge ...

  2. City longitude and latitude json understand SignalR Main(string[] args) And args Several ways of transmission Serial port programming port Multithreading is introduced in detail Recursion is a List&lt;T&gt;, It can be transformed into universal type according to its own needs . Sql Optimize the solution

    City longitude and latitude json https://www.cnblogs.com/innershare/p/10723968.html understand SignalR ASP .NET SignalR It's a ASP .NET ...

  3. win7 Under the system vspd Software serial port programming examples

    http://blog.csdn.net/qiusuo800/article/details/8299777 at present , I'm learning C# Basic knowledge of serial port programming class , I also found some information on the Internet , But there are some problems , Now they're based on ...

  4. Java Serial port programming example

    I recently came into contact with serial port programming , I searched the Internet for some information , By the way . It's recommended on the Internet Java RXTX Open source class library , It provides Windows.Linux Serial port and parallel port communication under different operating systems , follow GNU LGPL agreement . Look up the ...

  5. linux A serial port programming,

    According to the right linux Systematic understanding , The sequence of serial port programming is nothing more than open,read,write,close, The serial port has baud rate . Data bits and other important parameters need to be set , So you should also use the set function , Then I will take these questions to learn linu ...

  6. storysnail Of Windows Serial Programming Notes

    storysnail Of Windows Serial Programming Notes author He YiJun – storysnail<at>gmail.com The team ls Copyright Please keep this statement for reprint ! The original code contained in this document is based on ...

  7. Linux Next serial port programming 【 turn 】

    Reprinted from :http://blog.csdn.net/w282529350/article/details/7378388 /************ Statement : I only reprinted it when I saw that this article helped me a lot , but ...

  8. c# Realize serial port programming - operation LED The screen

    Serial port programming mainly uses SerialPort This class , The main implementation of the serial port to send byte array, and then dot matrix screen display related information , In fact, this function is very simple. Let's use the flow chart to show the overall idea as follows :. In fact, the whole idea is just like the flow chart . Here is an example of the whole flow chart ...

  9. C# Scanner programming 、 Bar code recognition programming information

    Scanner programming information :http://www.cnblogs.com/wubh/archive/2011/11/07/2239178.html Picture bar code identification information :http://www.codeproject ...

Random recommendation

  1. Java In depth interpretation of memory model

    Java The memory model is standardized Java How virtual machine and computer memory work together .Java A virtual machine is a model of a complete computer , So this model naturally includes a memory model —— Also known as Java Memory model . If you want to design concurrency that works well ...

  2. css Element centering method

    Several ways of centering , Use... According to circumstances : 1. The width of the parent box is known , Subbox width : div{ transform: translate(-50%,-50%); //margin-left: - Half the width of itself : positi ...

  3. Encyclopedia editor ueditor Apply notes

    Recently, we need to use a text editor in our project , Choose encyclopedia open source ueditor, Although there are some problems in the use process , But it's all solved one by one , Record the following : The project environment for development is vs2012:.net4.0: 1: Baidu js Editor , The editor loads into the project ...

  4. HW7.1

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  5. practice C And SELECT Formal non blocking IO

    ha-ha , I don't understand very well , But after all, it's all in hand , And no mistake . but select.h I don't know where to find the file , Stick it down for a record . POLL,EPOLL It feels like the code is similar , It's just that functions and system implementations are different ,,EPOLL At present, the most reasonable . Accurate positioning , The algorithm is complex ...

  6. Matlab Common operations in

    (1) Line feed operation : Add... At the end “...”, Then add enter: Sometimes multiple statements restart a line , At this time shift+enter >> 4*sin(0.3)*...8 (2) Some shortcuts : Ctrl+R Many lines are the same ...

  7. Push , How can we not understand push 4 It's a message form ?( Android piece )

    Aurora push is for App One of the platforms to provide third-party push services , It provides four message forms : notice , Custom message , Rich media and local notification . I will talk about these four kinds of news based on the official explanation and personal understanding . This article is Android piece ,iOS The entrance ...

  8. Python Introduction to reptiles 12-100 Half time yuan COS Figure crawl

    Half time yuan COS Figure crawl - Write it at the front While browsing the web today , Suddenly a nameless link guided me to the half - dimensional site https://bcy.net/ After the open , Didn't find anything interesting , The sensitivity of profession let me associate instantly c ...

  9. 20155117 Wang Zhenyu 2016-2017-2 《Java Programming 》 Week 6 learning summary

    Summary of the learning content of the textbook IO Classification of flows : According to the data object of the stream : High end stream : All streams in memory are high-end streams , such as :InputStreamReader Low end stream : All streams in external devices are low end streams , such as InputStrea ...

  10. [ translate ]60,000 In milliseconds Linux Perform performance diagnostics

    Link to the original text :http://techblog.netflix.com/2015/11/linux-performance-analysis-in-60s.html Original author :Brendan Gregg,L ...