Familiar with serial programming should be difficult .. Net is easier, and no nonsense. Let's get started.
1. virtual serial port Software
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, and supports client-mode devices.
Then use the virtual serial port of the Device Detector resume. (If you choose to create the default serial port, the software will automatically create four virtual serial ports for you)
Then, the virtual serial port is added.
Select com2 for the serial port and the IP address of the listener: 192.168.1.111. The client-mode device tries to connect to this port: 8099.
After the device is created, select the serial port, and then select the menu bar: Check the connection of the device. Enter the IP address 192.168.1.111 selected when the device is added. The selected port is 8099.
Click "reconnect". This window does not reflect the following information: But the rightmost column of the serial port in the main window: the last operation: the serial port: com2 is not opened.
2.. Net serial port operations
Since the serial port: com2 is not enabled, we need to first open the serial port to connect to it with the virtual software (I did not notice it at first, it took several hours ).
Add reference: Microsoft. VisualBasic
Use the following to traverse serialportnames and obtain all serial ports
Microsoft. VisualBasic. devices. computer PC = new Microsoft. VisualBasic. devices. Computer ();
Foreach (string s in PC. Ports. serialportnames)
{
This. combobox1.items. Add (s );
}
Then, the displayed serial port name comname is used to obtain the operation object. You can enable this serial port:
System. Io. Ports. SerialPort COM = new system. Io. Ports. SerialPort (comname );
Com. open ();
After opening it, you can connect it with the virtual software. Use the following message to send the information, and the virtual software will receive it.
Send data to the serial port:
Com. writeline (this. textbox1.text );
Of course, data can also be accepted:
Com. Readline ()
Here is to receive a line of data, You need to press enter after the virtual software input (that management interface input is, there is no echo, then press Enter ).
Other operations are self-transparent, or refer to the following keywords: The my namespace in VB. NET, how to use the my keyword of VB. NET in C #
Of course, it is disabled:
Com. Close ();
Virtual serial port software and test operations: