Serial port forwarding TCP/IP utility

Source: Internet
Author: User

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

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.