-
June 10th, 2009, 02:47 PM
#1
trying to send hex data over serial port.
Hi,
I am using the following code to send hex data over the serial port:
int str[4] = {0xFF, 0xFF, 0xFF, 0xFF};
BSTR bstr = SysAllocString((OLECHAR*)str);
VARIANT var;
ZeroMemory(&var, sizeof(VARIANT));
var.vt = VT_BSTR;
var.bstrVal = bstr;
Then the WriteFile is: BOOL Write(VARIANT* byteval) { WriteFile(hComm, byteval, sizeof(byteval), &iBytesWritten, NULL); }
Now, I am using a sniffer to check the data I am sending. For some reason data (08 00 00 00) in hex is getting sent. I have chaged the values in str. But whatever the value is in str, I am getting the same data, 0x08 being sent over the serial port.
Please help me to solve this problem. I am stuck here for hours!
Thanks in advance!
-
June 10th, 2009, 03:06 PM
#2
Re: trying to send hex data over serial port.
Why all the overhead with VARIANT and BSTR (and even int[4] for that matter).
Just send the data:
Code:
unsigned char str[4]={0xFF,0xFF,0xFF,0xFF};
DWORD iBytesWritten;
WriteFile(hComm, str, 4, &iBytesWritten, NULL);
-
June 10th, 2009, 03:35 PM
#3
Re: trying to send hex data over serial port.
Hi hoxsiew,
you are so correct!! Why didn't I think of this simple solution!!!
thanks a lot for your help! The program is now working correctly.
kajarigd
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|