Home > Back-end >  C builder used communication protocol chat write serial port device
C builder used communication protocol chat write serial port device

Time:09-30

Is the use of wireless data transmission module of this function: need to send the data to the specified module, you can add data to address code, when the device receives the data to determine whether a address for this device address, if not discard it,

CodePudding user response:

Since be passthrough, define your own protocol, you need to manipulate a serial port, a cnComm source code, can be found on CCRUN.com, send string can use a serial port, you can define the structure in the first
Int t_ver;//version number
In t_len;//data length
Int t_station;//the target site
Int t_cmd;//command type

Data is data head + content, the receiver to get the analytical solution package, and the same Socket

CodePudding user response:

Is there a similar example

CodePudding user response:

reference 1/f, LBG response:
since be passthrough, define your own protocol, you need to manipulate a serial port, a cnComm source code, can be found on CCRUN.com, send string can use a serial port, you can define the structure in the first
Int t_ver;//version number
In t_len;//data length
Int t_station;//the target site
Int t_cmd;//command type

Data is data head + content, the receiver to get the analytical solution, and the Socket is no difference between



Have a similar example?

CodePudding user response:

reference 1/f, LBG response:
since be passthrough, define your own protocol, you need to manipulate a serial port, a cnComm source code, can be found on CCRUN.com, send string can use a serial port, you can define the structure in the first
Int t_ver;//version number
In t_len;//data length
Int t_station;//the target site
Int t_cmd;//command type

Data is data head + content, the receiver to get the analytical solution, and the Socket is no difference between


I am using tcomm

CodePudding user response:

You now hardware level protocol, it is a serial port communication protocol, this according to the ordinary set to go on both ends of the RS232 communication, as to the communication protocol of application layer, the best, according to the definition of your business from, however, the vast majority of application layer communication protocol is this structure:

 
Struct MYHEADER
{
Unsigned int Bytes; Indicate the number of bytes of Data in the Data//
Unsigned char Data [1].//this Data is longer, according to the business plan
};


In this way, the sender and the receiver can clearly know that the number of bytes, each transmission communication can naturally out of synchronization,
Every time the receiver, receiving, can be divided into two steps, first receive only 4 Bytes, this is the Bytes, said how many Bytes of data coming back, and then continue to receive Bytes Bytes of data, receiving, after the completion of the just received data into the business process,

CodePudding user response:

reference 5 floor CCED136 reply:
hardware level agreement, you now is a serial port communication protocol, the end according to the ordinary RS232 communication Settings, as to the communication protocol of application layer, the best in your business from the definition, however, the vast majority of application layer communication protocol is this structure:

 
Struct MYHEADER
{
Unsigned int Bytes; Indicate the number of bytes of Data in the Data//
Unsigned char Data [1].//this Data is longer, according to the business plan
};


In this way, the sender and the receiver can clearly know that the number of bytes, each transmission communication can naturally out of synchronization,
Every time the receiver, receiving, can be divided into two steps, first receive only 4 Bytes, this is the Bytes, said how many Bytes of data coming back, and then continue to receive Bytes Bytes of data, receiving, after the completion of the just received data into business processing,


Then I through different communication protocols are in place to decide who sent this message, this how

CodePudding user response:

refer to 6th floor qq_28007971 response:
Quote: refer to the fifth floor CCED136 reply:

You now hardware level protocol, it is a serial port communication protocol, this according to the ordinary set to go on both ends of the RS232 communication, as to the communication protocol of application layer, the best, according to the definition of your business from, however, the vast majority of application layer communication protocol is this structure:

 
Struct MYHEADER
{
Unsigned int Bytes; Indicate the number of bytes of Data in the Data//
Unsigned char Data [1].//this Data is longer, according to the business plan
};


In this way, the sender and the receiver can clearly know that the number of bytes, each transmission communication can naturally out of synchronization,
Every time the receiver, receiving, can be divided into two steps, first receive only 4 Bytes, this is the Bytes, said how many Bytes of data coming back, and then continue to receive Bytes Bytes of data, receiving, after the completion of the just received data into business processing,


That I want through different communication protocols to determine who the message is sent, the how


In fact, I said the structure of the above, is a universal for communication structure, also can saying is the vast majority of communication protocol has the structure), according to you, in fact this structure to continue to expand again:
 
//agreement head
Struct MYHEADER
{
Unsigned int Bytes; Indicate the number of bytes of Data in the Data//
Unsigned int Protocol;//agreement no.
Unsigned char Data [1].//this Data is longer, according to the business plan
};

//assume that your situation is like this:
//when the Protocol=1, the packet is sent to A device, the actual communication structure assumption is that
Struct MYDEVICEA
{
Unsigned int Bytes; Indicate the number of bytes of Data in the Data//
Unsigned int Protocol;//agreement no.
Unsigned int Code;//carry data: code
Unsigned char Name [20].//carry data: name
Unsigned char Data [1].//this Data is longer, according to the business plan
};

//when Protocol=2, the packet is sent to B equipment, the actual communication structure assumption is that
Struct MYDEVICEB
{
Unsigned int Bytes; Indicate the number of bytes of Data in the Data//
Unsigned int Protocol;//agreement no.
Unsigned char FileName [MAX_PATH];//carry data: want to read the file name
Unsigned int StartPosition;//read starting position
Unsigned int ReadLength;//to read the number of bytes
};