backslash in a string

rghill76

Guest
R
I am working with a SLC5/05, RSLogix6 and a Linx6200 Printer. The printer accepts commands in ASCII code sent out as strings. I am trying to send out parameters to the printer but I need some backslashes to separate my data or the printer will not accept it.

ex, I need to make the number 250 dec (FAh) to look like \FA\00

ST130:0 = "0"
ST130:1 = "0"
ST130:2 = "F"
ST130:3 = "A"

Using ACN I can bring them together, but is there any way to get the backslashes in there? What I would like to do is to have

ST130:4 = "\".

Any help would be much appreciated.
 
The ASCII code for "\" is 92 decimal, 5C hex. I don't know your unit, but most devices that can send ASCII will let you enter the actual ASCII code for the character instead of the character itself. For example, that is often the way a carriage return (ASCII code 13 decimal) is entered. Look in your manual's help.
 
I tried entering \5C as a string and it changed it to \\

When I use the ACN command it creates

\\FA\\00

The linx printer ignores the command because the number of bytes recieved was incorrect.

If I manually set it to \FA\00 then the command is accepted

ex ACN \FA , \00 = \FA\00

If I enter a string such as \1B\01 the length of the string is 2
but if I enter \\1B\\01 the length is 6
 
The wonderful Wacky World of ASCII

1. You can definately do what you want in the string file but it isn't intutively obvious how to do it.

2. You need to better define exactly what your device needs to see.

The confustion is that a standard convention for typing in 8 bit ascii codes is to precede a 2-digit hex number with a backshash so since the ascii code for a capital letter A is 41 hex (65 decimal) it can be represented as \41
Note that this is ONE character or 8 bits...

Now.... AB for some reason, in its string data file display sometimes displays the actual ascii character (for instance, if you type in \41 it will display an A) and sometimes displays the coded format (for instance if you type in a null character as \00 it will display \00) and sometimes displays things in yet another format for instance when you want a carriage return you type in \0D and it will display ^M banghead


So, the real question is do you want The two character string represented by the hex codes \FA\00

or the 6 character string represented by the hex codes:
\5c\46\41\5c\30\30 (note: \46 = "F" and \41 = "A") Note that this will display as "\\FA\\00" in the ST data file dispaly because the slash character (one character) will display as "\\" but you can use the length number as a clue as to what is really going on.

or something else??????
 
I need the Two character string represented by \FA\00

The full command that the Linx printer will be looking for is:

\1B^B^C\FA\00\1B^C

The \FA\00 needs to be user configurable through a panelview. The operator will enter a number like 208d or 2418d and the software needs to break this down and send out the string.

\1B^B^C is a start command and \1B^C is a finish command

If the operator enters 208d: \1B^B^C\D0\00\1B^C
If the operator enters 2418d: \1B^B^C\72\09\1B^C

I have got it as far as breaking down the numbers and placing them into individual strings

ex: 2418d --> ST130:0 = 0
ST130:1 = 9
ST130:2 = 7
ST130:3 = 2

Rob
 
Well, you may want to kick yourself when you hear the answer but you can simply do a MOV or COP to get what you want into the string.

If you destination is, for instance ST130:2, and the number entered in the panelview is in N7:10 you can do:

MOV N7:10 ST130:2.1

and there you go. The reason is that the SLC stores all integers in 16 bit words. When the operator types in the decimal word, it automatically gets translated into binary/hex for storage. Try to look at an integer file with an ascii radix as shown below.

Give that a try and you should be almost there

both.jpg
 
I needed to do the exact same thing to a Zebra printer.
Instead of figuring out how to send the \, I changed the code that the printer was expecting to a ^.
The Zebra has a definable parameter for it's control code separator.
You may try that...
 
Thanks a lot guys, the MOV command worked like a charm. One thing not stated is that you need to MOV 2 STX:Y.LEN in order for the data to show up. A couple of AEX commands and an ACN and I have my data in the proper order. Again, thank you guys for your prompt responses.

Rob
 
Yes rghill76 I wasn't sure on the exact address/sub-address for the string in the MOV but it seems you figured it out.

What it looks like you are needing is a null terminated single character (your \FA\00).

When you do the MOV, the full 16 bits are moved so the 250d the operator enters looks like 00FAx and gets put into the string that way. There is a neat trick to get the \FA part shifted to the high side. You could try a bit shift 8 bits to the left which would work but there is a bit too much overhead in a bit shift for my liking in this application. Then I remembered in assembly (ugh) it was often easier to shift left 1 bit than doing a multiply by 2. (yes, if you shift a binary number left by 1 bit it is the same as multiplying by 2).

But it doesn't stop there. When you shift left, it's like multiplying by a power of 2. Shift left 2 bits is the same as multiplying by 2^2 or 4, shift 3 = multiply by 2^3 or 8... Shift left 8 is the same as multiplying by 2^8 or 256. Of course, the converse of this is also true... If you want to shift the bits 8 places left then you can multiply by 256!

You can use this trick to avoid having to juggle characters in the string. If you multiply by 256 the number becomes FA00x and will get transfered to the string as \FA\00 which is what you need. *IMPORTANT* Note, for this to work, you have to set the math overflow selection bit S:2/14 in the processor status file and you will also have to unlatch S:5/0 the Overflow Trap Bit (Minor Error Bit) before the end of the program to avoid a processor fault.
 

Similar Topics

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...
Replies
6
Views
2,877
What does the backslash and a selected program do in 5k st? I though it was a getter/setter for another program's local tags, much like # in...
Replies
3
Views
1,393
All, I am trying to reset timers when a Work Order change occurs. The Work Order comes in as a string and I am comparing it to a tag...
Replies
2
Views
67
Hello, I am using studio 5000 pro and am trying to figure out the structured text. Here's my scenario: An operator scans a barcode, the barcode...
Replies
15
Views
281
I am creating a global object in FTView SE 13. I want to have a string read from the PLC and display (in this case the tagname). So lets say...
Replies
4
Views
184
Back
Top Bottom