C # serial Test

Source: Internet
Author: User

Software and code grid download Https://pan.baidu.com/s/1dFrE1pv#list/path=%2F

Explanation of the problem:

namespaces: Using System.IO.Ports;

1.serialPort can call the components of the system directly, or write it yourself. It is best to write your own method inside, otherwise the cross-interface is not good to call.

2.serialPort has a default property, give it a serial port can be used directly later. It is better to use enumerations to pass the parameters over.

3. Process: Assignment, judging status, opening, transmitting/receiving, closing.

4. Send: Write; receive send;

5. The most difficult thing is to receive. Receive the data through the SerialPort datareceived and get the error message by SerialPort error.

If you do not use a control and customize the Privite SerialPort se=new SerialPort (); Ser. DataReceived + = new Serialdatareceivedeventhandler (ser_datareceived);

Write down ser. DataReceived + = Double-click tab and then automatically write a void Ser_datareceived (object sender, Serialdatareceivedeventargs e) method;

6. Each buffer has a data system will call datareceived, write a method in it, first pass the data to txt above and then call this method, intercept the string to judge the message and then process the message. However, because the control is created by the main thread, there is an invalid inter-threading operation: From the thread that is not creating the control; Microsoft Documentation: Https://msdn.microsoft.com/en-us/library/ms171728.aspx.

1. Use the delegate. 2 Use BackgroundWorker.

C # serial Test

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.