C # uses SerialPort and chart controls for simple waveform plotting

Source: Internet
Author: User

First look at the final:

The main realization function is to send the serial data sent over the waveform display

Note: This example is the serial Port debugging assistant and virtual serial VSPD software analog serial port to send data, detailed description see below

Description
The SerialPort ReadByte () method is used to synchronously read a byte from the System.IO.Ports.SerialPort input buffer.

The chart control's spline is a graph that connects points with a smooth curve.


Several code block descriptions:

(1)

  private void Searchandaddserialtocombobox (SerialPort myport, ComboBox mybox)        {            string Buffer;            Mybox.Items.Clear ();            for (int i = 1; i <; i++)            {                try                {                    Buffer = "COM" + i.tostring ();                    Myport.portname = Buffer;                    Myport.open ();                    MYBOX.ITEMS.ADD (Buffer);                    Myport.close ();                }                Catch                {}}}        
This code function is to find the available serial port and add it to the ComboBox drop-down option. The principle is to test whether the serial port is available, generally speaking, computer 1-20 is enough, if more than 20, can be modified.

(2)

private void Serialport1_datareceived (object sender, Serialdatareceivedeventargs e)        {            byte[] data_receive = New Byte[3];            Data_receive[0] = (byte) serialport1.readbyte ();            DATA_RECEIVE[1] = (byte) serialport1.readbyte ();            DATA_RECEIVE[2] = (byte) serialport1.readbyte ();            Textbox1.appendtext (Data_receive[0]. ToString () + "");            Textbox1.appendtext (Data_receive[1]. ToString ());            Textbox1.appendtext (Data_receive[2]. ToString () + "\ r \ n");            Series. Points.addy (Data_receive[0]);  /* int data_receive = Serialport1.readbyte ();              Textbox1.appendtext (data_receive. ToString () + "");              Series. Points.addy (data_receive); */        }

This code is to display the serial port data in the chart table, where the code needs to be based on their actual transmission of the data to be modified, not difficult, TextBox control can be displayed, if the source resources (the end of the article) with the serial debugging assistant as a send without modification.

I use the Serial debugging assistant each time sent over the single byte will automatically add line at the end of "\ r \ n", so I read three times to display the first way to record data, serial debugging assistant when sending remember to check the hex send, each send a byte.

SOURCE Download: http://download.csdn.net/detail/u012342996/9513760

(Note: The resource has a serial debugging assistant, but no vspd,vspd self-Baidu download can be)




The SerialPort ReadByte () method is used to synchronously read a byte from the System.IO.Ports.SerialPort input buffer.

C # uses SerialPort and chart controls for simple waveform plotting

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.