Read Serial Port data [modified]
-
Hi i am using vc++ 6.0 MSCOMM for serial communication i have to read data(4 bytes) and display from serial port. ex: data format is 88 84 10 02 (4 bytes data from port) C6 1E 10 02 (Received Data) but i have to display 88 84 but i am getting C6 and 1E. my code is: VARIANT data; BSTR k; static char dbuff[4]; int dcount=0; CString data; if(m_mscom.GetCommEvent()==2) // Receiving data from port { data=m_mscom.GetInput(); k=data.bstrVal; dbuff[dcount] = char (k[0]); dcount++; if(dcount == 4) { dcount=0; data.Format ("%02X%02X%02X%02X",(unsigned char)dbuff[0],(unsigned char)dbuff[1],(unsigned char)dbuff[2],(unsigned char)dbuff[3]); } } please help what is the wrong in my code, thanks in advance,please give me one example how use BYTE to read the data -- Modified Sunday, January 9, 2011 11:06 PM
-
Hi i am using vc++ 6.0 MSCOMM for serial communication i have to read data(4 bytes) and display from serial port. ex: data format is 88 84 10 02 (4 bytes data from port) C6 1E 10 02 (Received Data) but i have to display 88 84 but i am getting C6 and 1E. my code is: VARIANT data; BSTR k; static char dbuff[4]; int dcount=0; CString data; if(m_mscom.GetCommEvent()==2) // Receiving data from port { data=m_mscom.GetInput(); k=data.bstrVal; dbuff[dcount] = char (k[0]); dcount++; if(dcount == 4) { dcount=0; data.Format ("%02X%02X%02X%02X",(unsigned char)dbuff[0],(unsigned char)dbuff[1],(unsigned char)dbuff[2],(unsigned char)dbuff[3]); } } please help what is the wrong in my code, thanks in advance,please give me one example how use BYTE to read the data -- Modified Sunday, January 9, 2011 11:06 PM
The values 0x88 and 0x84 are the characters ê and ä from the extended ASCII table. Seeing how these characters are changed but the lower ones (from the 128 character ASCII table) are not, it would appear these characters get translated somewhere to another code page; most likely either on the sender's side or in the data.Format call.
-
Hi i am using vc++ 6.0 MSCOMM for serial communication i have to read data(4 bytes) and display from serial port. ex: data format is 88 84 10 02 (4 bytes data from port) C6 1E 10 02 (Received Data) but i have to display 88 84 but i am getting C6 and 1E. my code is: VARIANT data; BSTR k; static char dbuff[4]; int dcount=0; CString data; if(m_mscom.GetCommEvent()==2) // Receiving data from port { data=m_mscom.GetInput(); k=data.bstrVal; dbuff[dcount] = char (k[0]); dcount++; if(dcount == 4) { dcount=0; data.Format ("%02X%02X%02X%02X",(unsigned char)dbuff[0],(unsigned char)dbuff[1],(unsigned char)dbuff[2],(unsigned char)dbuff[3]); } } please help what is the wrong in my code, thanks in advance,please give me one example how use BYTE to read the data -- Modified Sunday, January 9, 2011 11:06 PM
You should not be using either
CString
orchar
for your data input, unless you can guarantee that it will be ASCII characters. Use aBYTE
type to ensure that your data is presented as received and not converted on the way.I must get a clever new signature for 2011.