I am doing SerialPort communication program where i am opening the port and reading data from port and storing in one document.
I debug my program and check that my read function is reading the data properly but when checking the document i find only unicode.
Suppose i am sending 1,2,3,4 to port i able to read same but my document showes þÿÿ þÿÿ þÿÿ þÿÿ
//My Read Function which read data from serial port
tInt serialport::Read(tVoid* pvBuffer, tInt nBufferSize)
{
tInt nBytesRead = 0;
if (m_bIsActive)
{
nBytesRead = m_oSerialDevice.Read(pvBuffer, nBufferSize);
Writetofile( pvBuffer, nBufferSize);
}
else
{
LOG_INFO("Not able to Read the Device");
}
return nBytesRead;
}
//Writetofile function which save the same data in document
void serialport::Writetofile(const tChar* pvBuffer, tInt nBufferSize)
{
tInt strOutput;
strOutput = 10;
cString strInfo;
cString strLine;
strInfo = *pvBuffer;
strLine = cString::Format(" %s", strInfo.c_str());
m_oFile.WriteLine(strLine);
}
Can any one give some idea why i am getting unicode instead of 1,2,3,4 in my document
Is 'tChar' an alias for TCHAR? What character set are you using? What character set is being transmitted? What character set is "m_oFile" expecting? I have a feeling that you are being sent multi-byte where you're expecting wide or visa-versa.