SerialData Communication

Jun 27, 2014 at 11:30am
Hello All,

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 þÿÿ þÿÿ þÿÿ þÿÿ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//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
Jun 27, 2014 at 4:09pm
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.
Jun 30, 2014 at 9:14am
Hello

Now my writetofile function is working properly i made some changes
1
2
3
4
5
6
7
8
9

void serialport::Writetofile(const tChar* pvBuffer, tInt nBufferSize)
{
tInt strInfo;
cString strLine;
strInfo = (tInt)*pvBuffer;
	strLine =  cString::Format(" %d", strInfo);
	m_oFile.WriteLine(strLine);		
}


but my data is getting save in document in vertical format i want in Horizontal way i.e
i am getting in
1
2
3
4
1
2
3
4
but i want in
1 2 3 4 1 2 3 4

So can any one let me know how can i get the same
Jun 30, 2014 at 2:52pm
What does WriteLine() look like?

Topic archived. No new replies allowed.