Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Serial Data Output Problem
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?

Copy      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
Yes, skips 0x00. Also, the variant then contains string (BSTR). To send binary data, it should be ARRAY(byte).

Function VariantFromBytes
Copy      Help
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).

;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
link to NETCommOCX
Free serial port activex control
Thanks Gintaras for that great little code!! Works as expected now.

Forum Jump:

Users browsing this thread: 1 Guest(s)