Use C # Serial programming to send data under vspm

Source: Internet
Author: User

I. Because I don't have a serial port in this notebook, I will first talk about a software, vspm

Introduction: [Reference from: http://developer.51cto.com/art/200908/146713.htm]

----------------------------------------------

Because there is no serial port hardware on hand, I found a vspm virtual serial port software on the Internet, which is said to be free of charge. : Http://www.skycn.com/soft/30517.html

I didn't know how to use it at the beginning. I found out and finally succeeded.

After installation, the working mode should be: vspm runs in server mode, supports the client mode device, and then uses the virtual serial port of the Device Detector resume. (If you choose to create a default serial port, the software will automatically help you establish four virtual serial ports) Then you will add a virtual serial port to select com2, select the IP address of the listener: 192.168.1.111,

The client-mode device tries to connect to this port: 8099 after the port is set up: select this serial port, and then select the menu bar:

Check the connection of the device and enter the IP address 192.168.1.111 selected when adding the device. The selected port is:

8099 click "reconnect". This window does not reflect the following:

But the rightmost column of the serial port in the main window: last operation:

Serial Port: com2 is not enabled.

----------------------------------------------

II. C # Serial Port

Create a project, right-click "add reference", and select "Microsoft. VisualBasic" under the. NET tab"

Form1.cs [design]

Form1.cs

Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. text; using system. windows. forms; namespace windowstest {public partial class form1: FORM {system. io. ports. serialPort com; Public form1 () {initializecomponent (); myinit ();} void myinit () {Microsoft. visualBasic. devices. computer Pc = new Microsoft. visualBasic. devices. computer (); COM = new system. io. ports. serialPort ("com2"); COM. open ();} private void button#click (Object sender, eventargs e) {/* data written to the serial port in the text box */COM. writeline (textbox1.text );}}}

Save debugging run

Error: Visual Studio cannot start debugging. Please generate a project and try again, or set the outputpath and assemblyname attributes accordingly to point them to the correct location of the target assembly.

Right-click Project, clear, and regenerate"

Error: "com2" not found"

Don't worry. virtual serial ports are not configured.

PS: If you have a serial port on your desktop, you can directly change com2 to COM1, And you can proceed;

Iii. Running

Set vspm

Select the com2 port, "virtual serial port and device management", and "track the serial port data"

Run the applet and enter hello

Click "show"

OK. Data is successfully sent through the serial port. After the full text is complete, if a problem occurs when receiving the data, it will not be written> _ ^

References:

Http://cao416451347ming.blog.163.com/blog/static/1154556162011374393975/

Http://developer.51cto.com/art/200908/146713.htm

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.