Posts: 14
Threads: 6
Joined: Jul 2006
I'm trying to output some data over serial with NETCommOCX. However I can't send 0x00 or 0 through it. I'm guessing that it's a NULL character and QM may skip it?
In the code below, the output only shows 0x52 and 0x80, but no 0x00 or 0xd2. Help?
typelib NETCommOCX {4580EBBB-FE3D-45CF-8543-600A62B38A73} 1.4
NETCommOCX.NETComm x._create
VARIANT d = "[0x52][0x80][0x00][0xd2]"
BSTR portsettings
x.CommPort = 3
x.Settings = portsettings
x.PortOpen = TRUE
x.Output = d
x.PortOpen = 0
Posts: 12,028
Threads: 139
Joined: Dec 2002
Yes, skips 0x00. Also, the variant then contains string (BSTR). To send binary data, it should be ARRAY(byte).
Function
VariantFromBytes
;/
function $bytesHex VARIANT&v
;Stores binary data into VARIANT variable.
;bytesHex - binary data as hex string.
;v - variable that receives the data as ARRAY(byte).
;EXAMPLE
;VARIANT d
;VariantFromBytes "52 80 00 d2" d ;;store binary data of 4-bytes length
str s.decrypt(8 bytesHex)
ARRAY(byte) a.create(s.len)
memcpy &a[0] s s.len
v.attach(a)
Posts: 12,028
Threads: 139
Joined: Dec 2002
Posts: 14
Threads: 6
Joined: Jul 2006
Thanks Gintaras for that great little code!! Works as expected now.