Serial communication with hexadecimal commands

Recommended Posts


I am trying to communicate with a third party product and it requires that I send it commands using hexadecimal. I have build a custom serial protocol (Quick > Device config...) and that seems to work when I send one command via Comm Monitor. But, when I make a channel with the I/O type selected from the protocol I built, the command sent has additional slashes between each byte (see attached image, the line with the blue arrow is what I sent, the yellow highlighted line is the response and everything else is caused by the channel I made).

I believe there is something missing or wrong with my Poll or probably the I/O I made in the protocol, this is the error that I get normally (every second):


C1136 Timeout: Poll Line 20: Poll Line 28: time2 Line 1
04/02/24 16:45:16.604
C1136 Timeout: Poll Line 20: Poll Line 28: time2 Line 1
04/02/24 16:45:17.615
C1136 Timeout: Poll Line 20: Poll Line 28: time2 Line 1

And, here is the protocol I made, Poll is the same but I included it anyways - all the other functions are empty:

private string time_now = Poll("\x02\x81\xD4\xD5\x03",3)
// co2 = Delete (co2,0,3)
return (time_now)


private string time_now2 = Poll("\x02\x81\xD4\xD5\x03",3)
// co2 = Delete (co2,0,3)
return (time_now2)


private string time_now3 = Poll("\x02\x81\xD4\xD5\x03",3)
// co2 = Delete (co2,0,3)
return (time_now3)

function Poll(string out, until)
// this function will poll the port with given string and read
// the response until the given character.  Returns NULL (empty)
// if there is an error

if (argc < 2)
   throw("Invalid number of parameters")
private string in
   // lock the port
   if (!LockPort())
      throw("Unable to lock port")
   // clear anything pending
   // output our string
   // and read until the eol:
   in = ReadUntil(until) 
   // release the port
   // and return the response
   // error occured
// return NULL to indicate error.  This should never happen
// because of the throw() statement above


As you can see I tried various ways to setup the I/O types. The functionality I am trying build is the ability to send settings to the product, but also continuously retrieve status of different operating conditions (for example temperature measurement). Thank you for the support and time in advance!

Link to comment
Share on other sites

A couple of key notes before I start:

1) hexadecimal is a loaded term.  Hexadecimal is just another way of representing a number.  So, 15 (base 10 / decimal) and 0x0F (base 16 / hex) are the exact same number and you can use either in DAQFactory IF, and that's a big IF, the device actually wants numbers (i.e. binary) and not an ASCII representation of numbers.  If it wants an ASCII representation then the ASCII string "15" and the ASCII string "0F" are not the same and you have to use "0F".

2) the \ notation, i.e. \x0F only works in the comm monitor.  It does not work in the write() function and therefore it won't work in the poll() function (which uses write).  You instead have to build up your string using chr(), or chra()

Besides those two points I can't say more without seeing the documentation to know if the device expects numbers or ASCII representations of numbers.  If you can type


in the comm monitor and get the desired result, then it expects numbers and is binary protocol.

I will also say this: user protocols are probably being deprecated (and don't work in 20.1+) and therefore I suggest writing sequences to perform the polling instead.  You can copy the poll() function if you want to help you, though you will have to specify the full device name for functions like write(), readUntil(), and purge().  It is also much easier to debug in a sequence.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.