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

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

Function VariantFromBytes
Code:
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).

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


Forum Jump:


Users browsing this thread: 1 Guest(s)