dado
Posts: 6
Joined: Wed Apr 19, 2006 3:25 pm

Problem with 0x00 in ActiveX SerialT. OnRead (C++)

Sat May 27, 2006 6:31 pm

Hi Franson support team,

it seems to me that ActiveX SerialTools respond erroneusly to 0x00 character.

When I was tracing data received in my code:

void CModbusTestDlg::OnRead(VARIANT* Data)
{
_bstr_t bstr(*Data);
LPCWSTR wstr = (LPCWSTR) bstr;
WCHAR* wcptr = (WCHAR*) wstr;
...


On data sent from terminal:
0x02 0x03 0x04 0x00 0x1B 0x00 0x19 0x78 0xFE
Result received in OnRead was:
0x0002 0x0003 0x0004 0x0000 0xF00D 0xBAAD 0xABAB 0xABAB 0xABAB

Obviously something bad after 0x00!
I changed the first 0x00 to 0x07 and sent from terminal:
0x02 0x03 0x04 0x07 0x1B 0x00 0x19 0x78 0xFE
Result received in OnRead was:
0x0002 0x0003 0x0004 0x0007 0x001B 0x0000 0xABAB 0xABAB 0xABAB

Again something bad after 0x00!
Finally I changed the second 0x00 to 0x07 and sent from terminal:
0x02 0x03 0x04 0x07 0x1B 0x07 0x19 0x78 0xFE
A received good message in OnRead was:
0x0002 0x0003 0x0004 0x0007 0x001B 0x0007 0x0019 0x0078 0xFFFE

Please check!

Best Regards

Dado

j.schrijver
Posts: 5
Joined: Wed Jun 18, 2008 12:17 pm

RE: Problem with 0x00 in ActiveX SerialT. OnRead (C++)

Thu Jun 26, 2008 1:46 pm

I'm encountering the same problem.
I've solved it using this very dirty solution:

void CTestXPDlg::OnDataFromPort(VARIANT* Data)
{
BYTE *pbyte = (BYTE *)(((VARIANT *)Data->ppdispVal)->ppdispVal);
long size = (long)(*(pbyte-4));
//pbyte points to start of data
//size is the number of bytes

//etc...
}



Best regards,
John.

Return to “SerialTools”