Inconsistent " \ " character output


Recommended Posts

Okay, this baffles me. I've installed a ProXR relay card and can communicate with it perfectly using the Device Configurator. I can open and close relays using "req\25408" and 000 (008 turns on, 000 turns off). The commands work in either ASCII or NULL protocol. (The parentheses used above were not used in the Output String.)

Here's the responses captured by the Comm Monitor:

Tx: req\25408

Rx: U

Tx: req\25400

Rx: U

I created a button called Relay and used the following Quick Sequence to turn on the relay:

Device.ProXR.Write("req\2548")

Now, here's the weird part - When I execute the button, the Comm Monitor shows the following:

Tx: req\\254\8

Note the doubled slashes! And of course, no response from the card.

When I repeated the same command over the Output String (through the Monitor function of the Device Configurator), using the Send button, I get relays popping and working commands and responses:

Tx: req\25408

Rx: U

Tx: req\25400

Rx: U

Why on earth would the Sequence send double slashes? See screen captures attached.

New_Picture.bmp

New_Picture__4_.bmp

Link to comment
Share on other sites

The monitor window works differently than script. The monitor window itself converts the \xxx notation to the ascii equivilent. When you do write() it uses the string without any modification, so to generate a non-keyboard ascii value, you have to use chr():

Device.ProXR.Write("req" + chr(254) + "8")

Link to comment
Share on other sites

No worries. Also, if you need to send a lot of binary values, its often easier to use chra:

device.proxr.write("req" + chra({254,8}))

Probably not needed when only doing 2 values, but if you had a whole bunch, its much easier (and faster executing) than using a bunch of chr()'s. There is an equivalent asca() for doing the opposite, which is useful when processing incoming binary values.

Link to comment
Share on other sites

Wow. 'chra' works like a charm. Thank you! I'm elated - this is the first piece of equipment that I've controlled using DF, and I can't stop giggling whenever I hear the relays do their thing.

Can you give me an example of the 'asca()' function, please?

Link to comment
Share on other sites

Let's say you had a string containing a bunch of binary characters:

global string x = chr(8) + chr(238) + chr(129) + chr(212)

(of course you'd use chra() instead of all those chr()'s). Typically this would be coming in on a serial port, not formed up like I did. So its a string with 4 characters and you now need to parse those binary values. You could use string manipulation functions like mid() but its much easier to do:

private in = asca(x)

asca() will return an array containing the ascii values of each character (asc() just does one character). So, in ends up being {8,238,129,212}, thus the corollary of chra(). Now you can just index into in to get the ascii values, so lets say the 2nd and 3rd characters were a binary encoded short integer you needed to get the value of. Then its just in[1] * 256 + in[2] (assuming big endian)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.