indigo Posted April 2 Share Posted April 2 Hi, 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): Quote 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: U,cts_protocol I,time,0,input,numeric private string time_now = Poll("\x02\x81\xD4\xD5\x03",3) // co2 = Delete (co2,0,3) return (time_now) ENDIO I,time2,1,input,string private string time_now2 = Poll("\x02\x81\xD4\xD5\x03",3) // co2 = Delete (co2,0,3) return (time_now2) ENDIO I,time3,2,output,string private string time_now3 = Poll("\x02\x81\xD4\xD5\x03",3) // co2 = Delete (co2,0,3) return (time_now3) ENDIO F,Poll,0 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") endif private string in try // lock the port if (!LockPort()) throw("Unable to lock port") endif // clear anything pending Purge() // output our string Write(out) // and read until the eol: in = ReadUntil(until) // release the port UnlockPort() // and return the response return(in) catch() // error occured UnlockPort() throw() endcatch // return NULL to indicate error. This should never happen // because of the throw() statement above return(NULL) 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! Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted April 3 Share Posted April 3 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 \x02\x81\xD4\xD5\x03 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.