Home > Net >  First-time C Builder, questions about serial distributed hex, every brother for help
First-time C Builder, questions about serial distributed hex, every brother for help

Time:09-29

Background: new to c + + Builer work reasons, read a little bit before, the basis of c code is on a developer to do, he did not use serial port controls, but do it himself a communication module, can support Telnet and serialport, he do a serial port to send if only supports the string to send, now send the new demand is on my side hexadecimal array (should be this meaning), don't know how to modify, as follows:
I use serial debugging assistant send data is: 02 03 03 02 November 11



I want to also implement distributed in the code and "03 02 02 November 11 03" the hexadecimal array? Don't know how to modify it, I wish to consult everybody, in this first thank you ~
On this to serve all my points, although few points
This is the part of sending:
Bool TEST_RunSend (CTestObj * pThis, AnsiString STR)
{
PThis - & gt; M_asErrorMsg="send_";
Bool flag;
CRegex regex.
AnsiString asNewString;
STD: : vector VecResult;
STD: : string strRegex;
STD: : string sendstr;
STD: : string the strError;
AnsiString asTemp;
AnsiString asScan;
Bool bReplaceIP=false;
//whether to obtain replacement in the command IP
AsTemp=pThis - & gt; M_pConfig - & gt; GetValue (REPLACE_CMD_IP);
If (asTemp. IsEmpty ())
{
BReplaceIP=false;
}
The else
{
BReplaceIP=atoi (asTemp c_str ());
}

STR=GetValue (" send ", STR);
//parsing command to remove some formats operator
Sendstr=fnParseString (pThis - & gt; M_pConfig, STR). C_str ();
If (sendstr=="NULL")
{
Sendstr="";
}
//replace command of IP - IPTS_QA_005
If (bReplaceIP)
{
AnsiString asRegex="(\ \ d + \ \.) (\ \ d + \ \.) (\ \ d + \ \.) (\ \ d +)";
AsNewString. Printf (" \ \ 1 \ \ 2 \ \ d "3%, pThis - & gt; M_stBrdInfo. UlTestBrdIndex);
Regex. FnRegReplace (sendstr. C_str (), asRegex. C_str (), asNewString. C_str (), sendstr, strError);
}
If (sendstr=="InfoScan")
{
AsScan=asScanInfo;
Sendstr="attd setmac" + STD: : string (asScan. C_str ());
}
//send instructions
Sendstr=fnChangeHex (sendstr c_str ()). The c_str ();
Flag=pThis - & gt; M_communication. FnSendString (sendstr, 500, FormMain - & gt; M_bSendDataByChar, strError);
Here is a function fnSendString function
Bool CCommunication: : fnSendString (const STD: : string& StrSend, const unsigned long ulTime, bool bSendByChar, STD: : string & amp; The strError)
{
M_hMutex WaitForSingleObject ((HANDLE), INFINITE);
STD: : string strSendAdd=strSend + "\ r \ n";
Return m_pCommuBase - & gt; FnSendData (strSendAdd c_str (), strSendAdd. The size (), ulTime, strError);
The strError="communication base class didn't create";
ReleaseMutex ((HANDLE) m_hMutex);
return false;
}
Here is a function fnSendData
Bool CCommuSerial: : fnSendData (const char * pbData, const unsigned long ulDataLen, const unsigned long ulTime, STD: : string & amp; The strError)
{
//callback function called
if (0 !=m_pfnCommCallBack)
{
M_pfnCommCallBack ((unsigned long) pbData, m_ulCallBackParam2);
}
If (1!=m_sComPort)
{
Int iSend=sio_write (m_sComPort (char *) pbData, ulDataLen);
If (0 & gt;=iSend)
{
The strError="sending data (";
The strError +=pbData;
The strError +="failure";
return false;
}
return true;
}
return false;
}

CodePudding user response:

Extern PACKAGE AnsiString __fastcall IntToHex (int Value, int who);
Extern PACKAGE AnsiString __fastcall IntToHex (__int64 Value, int who);

The Description

IntToHex converts a number into a string containing the number 's hexadecimal (base 16) representation. The Value is the number to convert. Who are the minimum number of hexadecimal who to return.

-- -- -- -- -- --
AnsiString: : printf
Sets the value of the AnsiString given a format string and its arguments.

Int __cdecl printf (const char * format,... );

The Description

Use printf to set the value of the AnsiString given a standard c + + format specifiers. Pass the values to any arguments in the format specifiers as additional parameters following the format parameter. This method returns the length of the final formatted string.

-- -- -- -- -- --
AnsiString __fastcall operator + (const AnsiString& RHS) const;

The Description

The friend function returns an AnsiString belong The concatenation of strings LHS and RHS.

The method returns an AnsiString belong The concatenation of this AnsiString and RHS.
  •  Tags:  
  • C#
  • Related