Keywords: SerialPort to TCP/IP, serial, remote serial debugging
I began to learn from the Vckbase VC + +, without him I will not progress so quickly, has been trying to give vckbase contribute to something, just today is free, on the earlier write a serial port to TCP/IP program sent up, I hope to learn a little bit of serial programming for beginners to help.
The biggest flaw of the program:
Windows to the hardware-driven interface are abstracted and standardized, the serial port is no exception, most of the equipment can be stored through the file Operation API storage control, such as: CreateFile, ReadFile, WriteFile, in fact, very simple. There is a SerialPort class written on the Internet is not bad, I directly to use, only made a small change to meet my requirements. The original class can only send and receive one Byte at a time, as needed I changed to a byte, need to focus on the point is that when sending and receiving multi-byte data, the correctness and integrity of the data need to ensure that, because the serial protocol standard is defined in the physical layer and the data link layer, for example, if you send 512 Byte, received is not necessarily the correct byte, so you have to make the relevant check to ensure correctness, or may not be a complete copy of the byte, but a number of times to collect all the data, then we need to define the relevant structure to ensure the integrity of data transceiver. These details are related to the serial drive implementation, readers are interested in, you can view the relevant documents. In this application, there is no protection of this problem, in view of a small amount of data sent and received (Byte), and only their own test products, so write is not rigorous, the data to send and receive the ideal for a one-time correct send and receive, I hope you can pay attention to.
The overall structure of the program:
Program features are implemented as follows:
Client < ———— > (ctcpsocket) Transfer (Cserialport) < ———— > Serial devices
For each ctcpsocket and Cserialport to be managed with a CITEM structure, multiple connection forwarding pairs can be configured in the configuration file.
The main classes in the program are: Cserialport, Ctcpsocket, CItem. Data received from the serial port can be forwarded to the data sockets and debug sockets, and can be written to the log document.
Figure A program displays entries