Home > Software engineering >  VC/MFC read many groups from the serial number, how to screen a few of these sets of data
VC/MFC read many groups from the serial number, how to screen a few of these sets of data

Time:09-24

Received many sets of data, each set of data is 8 hexadecimal number together, such as one group is 99, 66 1 a 22 33 21 00 this data, I now need to extract the data in each group in fourth, five, six of the three Numbers, and these three number addition of a new decimal number and prints, how should the whole,

CodePudding user response:

Understanding through transport protocol, to ensure that the received data packet correctly
Then define a structure,
Typedef struct _tagGpData_t
{
Uchar uByte [8].
} GPDATA;
The rest of the almost similar with
PGp GPDATA *=(GPDATA *) pRecv;//points to the data set buffer
Int (pGp newData=https://bbs.csdn.net/topics/-> uByte [4] <16) + (pGp -> uByte [5] <8) + (pGp -> uByte [6]);

CodePudding user response:

Didn't know what's going on, I want to be a serial real-time data is read and drawing software, need among the several groups of data

CodePudding user response:

reference 1st floor zgl7903 response:
understanding through transport protocol, to ensure that the received data packet correctly
Then define a structure,
Typedef struct _tagGpData_t
{
Uchar uByte [8].
} GPDATA;
The rest of the almost similar with
PGp GPDATA *=(GPDATA *) pRecv;//points to the data set buffer
Int (pGp newData=https://bbs.csdn.net/topics/-> uByte [4] <16) + (pGp -> uByte [5] <8) + (pGp -> uByte [6]);



Don't understand, can speak in detail, please

CodePudding user response:

reference chenghaha2014 reply: 3/f
Quote: refer to 1st floor zgl7903 response:

Understanding through transport protocol, to ensure that the received data packet correctly
Then define a structure,
Typedef struct _tagGpData_t
{
Uchar uByte [8].
} GPDATA;
The rest of the almost similar with
PGp GPDATA *=(GPDATA *) pRecv;//points to the data set buffer
Int (pGp newData=https://bbs.csdn.net/topics/-> uByte [4] <16) + (pGp -> uByte [5] <8) + (pGp -> uByte [6]);


Don't understand, please speak in detail

That you tell me, what you currently do first step?

CodePudding user response:

reference chenghaha2014 reply: 3/f
Quote: refer to 1st floor zgl7903 response:

Understanding through transport protocol, to ensure that the received data packet correctly
Then define a structure,
Typedef struct _tagGpData_t
{
Uchar uByte [8].
} GPDATA;
The rest of the almost similar with
PGp GPDATA *=(GPDATA *) pRecv;//points to the data set buffer
Int (pGp newData=https://bbs.csdn.net/topics/-> uByte [4] <16) + (pGp -> uByte [5] <8) + (pGp -> uByte [6]);



Don't understand, please speak in detail


Great god mean, on the serial port communication, you should have your own application layer protocols, such as the other side is how the data according to the format to send to you, so you can know to want to data in which position,
Even if no application protocol, when you read data from serial port, always call ReadFile (), the parameters of the function of not need you to specify a receive buffer, and you receive the data is eight in the form of a set of such, then can be directly on the object cache area address location to extract data can ah, such as buffer [3 + I * 8] + buffer [4 + I * 8] + buffer [5 + I * 8]

CodePudding user response:

In fact is very simple,
BYTE buf []={99 00 66 1 a 10 22 33 21};//will receive a number in the buf
int a;
Char * pa=(char *) & amp; a;//converts a address byte pointer
Pa [1]=buf [4];//you determine a good receiving byte order relation between the order of 0 bytes and is the lowest, the byte 3 is the highest, if your code is not hexadecimal form, the need to buf [I] is converted to hexadecimal form
Pa [2]=buf [5];
Pa [3]=buf [6].
Pa [4]=0;

//to this, a value is the value of 4 ~ 6 bytes

CodePudding user response:

"Compiler principle" reference of lexical analysis and the finite state automata,

CodePudding user response:

Temporary use, use serial assistants receive, save into TXT, make it in Excel, can also draw pictures

CodePudding user response:

Char pszRev [1024]={0};
DWORD dwRead (0), dwSend (0);
While (1)
{
If (p - & gt; ReadData (pszRev, 1000, dwRead))//receiving data
{
Int Data3=atoi (pszRev + 3);//get the third data
Int Data4=atoi (pszRev + 4);//get a fourth data
Int Data5=atoi (pszRev + 5);//get the fifth data
//their processing
}
}
  • Related