String conversion question

Contr_Conn

Member
Join Date
Sep 2003
Location
Ohio
Posts
2,576
Need a little help. All below is for Logix PLC.

I have an array of integers named INT[20], size may be different using 20 as an example.
I need to put these integers sequentially in the string named STR

Looks simple right?
COP INT[0] STR.DATA[0] 40
MOV 40 STR.LEN

Now the tricky part: the operation above will pack String in “Little-Endian” byte format:
Lo[0], Hi[0], Lo[1], Hi[1]…

The string I need is “Big-Endian” byte format:
Hi[0], Lo[0], Hi[1], Lo[1]…
The only way I found is a loop something like this:

Loop001.jpg



Small correction - Source B in LES should be 19 ;)

Any ideas for a simple solution?
Thanks.
 
Last edited:
I don't think you can make it much simpler.

But you could use a DINT array to cut the number of loops in half. And the copy to the string could be done outside the loop, eliminating the MUL and INT_temp and index2.
 
DINT array is a good idea:
copy INT array to DINT first and do 2 conversions in one loop.
I'll try it tomorrow.

The only problem I see INT array size can be ODD
and as small as 1 word. Largest size 125 Integers.
 
ST may be better here, but it will not make it short.
I think I have no way to avoid a loop.
Question is how to make this loop most efficient.

I am using ControlLogix and ST is available in my RSlogix5000 package ;)
But this sample should be available for all users and not every package included ST.
 
That sort of code should never fail or need modifying so put it in an ST, no-one should ever need to access it for maintainance.
Regards Alan Case
 
SLC500 SWP instruction will swap low and high bytes in multiple words, say, 40 at a time.

Am I correct understanding that CLX swap instruction can handle only one word at a time? If so, this looks like a major step back...
 

Similar Topics

Hi All, I am having trouble converting a real to string and keep it to 2 decimal places. I'm sure its a simple solution. Any help is appreciated
Replies
2
Views
281
I am working on calculating a checksum value for a command that is to be sent from an Allen-Bradley CompactLogix PLC to a Mass flow controller...
Replies
2
Views
4,316
I have a Cognex 8050 barcode scanner and I am trying to pull recipes from this information. The recipes are in different locations in the string...
Replies
19
Views
3,718
hi, I am trying to convert a string value to int but it is not working and I cannot figure out why. I have a string which is constantly...
Replies
10
Views
10,172
Hello All Im using a FESTO PLC with Codesys. I have a string, named "Program1", which Im trying to convert to a datatype of Word. Im not...
Replies
4
Views
12,494
Back
Top Bottom