MicroLogix 1100 and backslash in string

shawn_75

Member
Join Date
Apr 2010
Location
KY
Posts
432
I am having a problem writing a string containing backslashes into an ST:9 file of an ML1100. I have the serial port set to ASCII and am sending data out as hex. For example, I can type "\FF\01\00\00\00\00\01" directly into the file using RSLogix 500 and it accepts it. Looking at the data it is transmitting using a serial port monitor, it is also correct. The backslashes are required in order to have the ML1100 treat it as hex and not send the ASCII equivalent. When I try to write the same data to ST:9/x using Ignition, the ST:9/x populates with "\\FF\\01\\00\\00\\00\\00\\01" even when the data displays correctly inside Ignition as "\FF\01.......and so on" The Python code in Ignition requires me to use double backslashes. I've tried many different ways in Python to send the backslashes and still get doubles in the ML1100. After that, I thought I'd try to concatenate the string together inside the ML1100. The problem there is that the ML100 won't store a single backslash in a ST:9 location for me to concatenate onto the front of each byte. It will store a double backslash.

Any ideas on how I can either write to the ST:9 location with single backslashes or how I can get the ML1100 to concatenate a single backslash onto another string?

Thanks!

Shawn
 
Last edited:
I'm guessing that you are writing TO ST:9 with ASCII. Just write the hex values as numbers. Each position in the ML100 string can be 00 to FF hex, write that directly, not its ASCII representation.
 
Also, what you have happening in Ignition is that sending a double backslash sends an ASCII backslash character, while you are really needing to send the hex value. In those cases, you need a '\x' instead of a double backslash.

example '\xFF\x01\x00\x00\x00\x00\x01'

It's also worth noting (after checking it out an a SLC 5/05) is that some of the characters may show up as control characters. \01 is ^A, as an example.
 
Thank you both, but I'm still not quite there.

The final string is a calculated value based on mouse movement. This string is to control a ptz camera. The final byte is a checksum. I am doing all of the math as integer. I am converting integer to hex as follows for all the integers prior to assembling the string. Example:

Code:
event.source.Data1HEX = hex(event.source.Data1PanSpd)[2:].zfill(2)

This gives me a string of the hex value with two placeholders.

After I've converted to hex, I am assembling the string. All values are 2 digit hex.

Code:
STX = event.source.STX
CamNumHEX = event.source.parent.getComponent('Camera number input').CamNumStr
Command1HEX = event.source.Command1HEX
Command2HEX = event.source.Command2HEX
Data1HEX = event.source.Data1HEX
Data2HEX = event.source.Data2HEX
ChecksumHEX = event.source.ChecksumHEX

finalstring = "\x" + STX + "\x" + CamNumHEX + "\x" + Command1HEX + "\x" + Command2HEX + "\x" + Data1HEX + "\x" + Data2HEX + "\x" + ChecksumHEX

event.source.parent.getComponent('Text Field 1').text = finalstring

This displays each byte in the text box with a space between them and without any backslashes visible.

When I write to the ST:9 address, it shows up as (in the first example) "\00FF\0001\0000\0000\0000\0000\0001"

Where are the extra zeroes coming from?

This is using Ignition 7.1.2.

Shawn
 
Last edited:
Well... no, not really. :)

The "\x" by itself is a hex value \x00, since there was nothing specified. So what you see is exactly what's in the string. \00 then 'FF' (as a string) then another \00, etc.

What you are trying to do is convert a hex string (or a bunch of hex strings) into a "byte string". It gets a little more complicated.

This is what I came up with:

Code:
def HexToByte( hexStr ):
    """
    Convert a string hex byte values into a byte string. The Hex Byte values may
    or may not be space separated.
    """ 
    bytes = []

    hexStr = ''.join( hexStr.split(" ") )

    for i in range(0, len(hexStr), 2):
        bytes.append( chr( int (hexStr[i:i+2], 16 ) ) )

    return ''.join( bytes )

hexString1="FF 00 01 4A 6F 72 64 61 6E"
hexString2="FF00014A6F7264616E"

bytes = HexToByte(hexString2)
system.tag.write("pathToTag", bytes)
EDIT: Alternatively, I think you can import binascii. I seem to remember being able to use with Jython 2.1:
Code:
import binascii

STX = event.source.STX
CamNumHEX = event.source.parent.getComponent('Camera number input').CamNumStr
Command1HEX = event.source.Command1HEX
Command2HEX = event.source.Command2HEX
Data1HEX = event.source.Data1HEX
Data2HEX = event.source.Data2HEX
ChecksumHEX = event.source.ChecksumHEX

finalstring = binascii.unhexlify(STX + CamNumHEX + Command1HEX + Command2HEX + Data1HEX + Data2HEX + ChecksumHEX)

2015-12-09_7-31-13.jpg
 
Last edited:
Thank you!

I went with the binascii solution as that was the quickest to implement. Works great.

:site:
 

Similar Topics

I am currently backing a Micro Logix 1100 and no-one seems to have the file for me to upload from. Is there a way for me to upload the project off...
Replies
15
Views
487
I am trying to set up a read message in a MicroLogix1100 to read the value of a DINT in a ControlLogix5561. I have successfully set up a message...
Replies
2
Views
179
Hello, I have an existing application that has a Powerflex 700 with a 20-COMM-E adapter controlled by a Micrologix 1100 via Ethernet. The setup...
Replies
6
Views
1,175
I have a MicroLogix 1100 and it's capable of ac or dc output voltages. What I don't know is how I'm supposed to tell the 1100 to use dc for the...
Replies
13
Views
1,384
I’m new to plc programming and very new to HMIs. So this is what I have done so far: I bought a micrologix 1100, I used bootP to set the up...
Replies
17
Views
1,660
Back
Top Bottom