Implement Serial Communication Using Activex

Source: Internet
Author: User

 

 

For implementationYou can use APIs to implement Windows serial communication, but it is inconvenient. You can also use the Active control.

 

InsertThe Active control Microsoft comm contronl (MSComm ).

 

SComm control attributes

 

MSComm control attributes

 

Commp ORT: Set the serial port number. Type: short: 1-comm1 2-comm2.

 

Settings: sets the serial communication parameters, type CString: B-baud rate P-parity (N-no verification,

E-even verification, O-odd verification) D-byte valid bits S-Stop bits.

 

PortOpen: set or return the serial port status. Type: BOOL: True-enable FALSE-Disable.

 

InputMode: sets the format for reading data from the receiving buffer, type long: 0-Text 1-Bin.

 

Input: Read the data type VARIANT from the receiving buffer.

 

InBufferCount: number of bytes in the receiving buffer; Type: short.

 

InBufferSize: the size of the receiving buffer. Type: short.

 

Output: write data to the sending buffer. Type: VARIANT.

 

OutBufferCount: number of bytes in the sending buffer; Type: short.

 

OutBufferSize: size of the sending buffer; Type: short.

 

InputLen: Specifies or returns the number of bytes read from Input. Type: short.

 

CommEvent: Serial Port event, type: short.

 

Program example

 

Serial Port Initialization

 

If (! M_comm.GetPortOpen ())

 

M_comm.SetPortOpen (TURE );/* Open the serial port

 

M_comm.SetSettings ("4800, n, 8, 1 ");/* Set serial port Parameters

 

M_comm.SetInputMode (0 );/* Set the TEXT buffer input mode

 

M_comm.SetRthresHold (1 );/* The OnComm () event is triggered every time one character is received.

 

Receive data

 

M_comm.SetInputLen (1 );/* Read one character each time

 

VARINAT V1 = m_comm.GetInput ();/* Read characters

 

M_V1 = V1.bstrval;

 

Sending character

 

M_comm.SetOutput (COlevariant ("Hello");/* Send "Hello"

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.