SerialPort. Read (byteRead, 0, byteRead. Length);
SerialPort. DiscardInBuffer ();
String strRcv=null;
If (byteRead. Length & gt; 20)
{
For (int I=21; I & lt; 25. I++)//total 44
{
StrRcv +=byteRead [I]. ToString (" X2 ");//hexadecimal display 21-24
}
Seri_mes_reci. Text +=strRcv + "\ r \ n";
}
This is done by c # serial code to obtain the return value, returns the 44 bytes of data, one is I want to speed information,
Is a string of four bytes in strRcv corresponding hexadecimal number, how can I put it into actual speed,
The following is my of the methods used in c + +, try a feasible
Float the get;
char *p;
P=(char *) & amp; The get;
CodePudding user response:
Use MFC to do the speed of extraction, want to use c # do aVoid CMFCApplication1Dlg: : OnOncommMscomm1 ()
{
The VARIANT data;
COleSafeArray data2.
Cstrings strtemp, buffer;//, buffer2;
LONG len, I;
BYTE Inbyte [2048], temp;
//the UpdateData (TRUE);//read the edit box content
If (m_mscomm GetCommEvent ()==2)//event value of 2 signifies a character
the receive buffer{
Data=(https://bbs.csdn.net/topics/m_mscomm.GetInput);//read buffer
Data2=data;//the VARIANT type variables into ColeSafeArray type
Len=data2. GetOneDimSize (); To effectively data length////
If (len & gt; 0)
{
for (i=0; I & lt; Len. I++)
Data2. GetElement (& amp; I, Inbyte + I);//type into a BYTE array
for (i=0; I & lt; Len. I++)//converts an array type cstrings variable
{
Temp=* (char *) (Inbyte + I);//character
Strtemp. The Format (" % 2 "x, temp);//the character into temporary variables strtemp store
Strtemp. MakeUpper ();//used to convert cstrings character to an uppercase string
Strtemp. Insert (2, "");//insert Spaces between adjacent data
Buffer +=strtemp;//the string into temporary variable buffer storage
}
}
If (buffer. GetLength () & gt; 120)//44 bytes, length of 132
{
Float the get;
char *p;
Int SSS=buffer. GetLength ();
P=(char *) & amp; The get;//casting F0 FB 9 f 46
For (int ii=0; Ii & lt; 4. Ii++)
{
String pre={buffer [60 + 2 * 3]}.
String pre2={buffer [61 + 2 * 3]}.
The pre +=pre2;
//cout & lt; <"The pre:" & lt;
for (int i=0; I & lt; 2; I++)
{
The result +=((charToDigit (pre) [I]) * pow (16, 1 - I));
}
//cout & lt; <"The result:" & lt;
}
//buffer2. The Format (" % 3 "f, get);
M_edit10=get; After the get//variable for transcoding speed value
The UpdateData (FALSE);//send the data to control
}
CodePudding user response:
Heard this deliciousInt a=the Convert. ToInt32 (" 12345678 ", 16);
CodePudding user response: