encoded decimal greater than 128 in ascII

mparodi91

Member
Join Date
Aug 2021
Location
buenos aires
Posts
7
Hello everyone!,
I am having a problem encoding decimals to ASCII, I need to store all 256 decimal characters (0-255) but ASCII encoded in Sting format.
the need arises from wanting to establish serial communication between the PLC (micrologix 1400) and a Liquid Control IQ controller that handles ASCII, so when receiving and sending messages I need to know which node it belongs to. For this particular case, by default the controller has the address 250, that is, I am going to have to read that message.

The conversion is done with a MOV, where in the integer N7 I store the product between 256 and the decimal number that corresponds to the ASCII symbol. Then I concatenate the address of the string of the new value, with the address of the string where I am assembling the chain.
The first image shows the aforementioned.
N7: 0 = 126 * 256 = 32256,
N7: 1 = 65 * 256 = 16640,
N7: 2 = 55 * 256 = 14080,


Now when I want to do the same methodology to represent those greater than 128, I count to find the complement -> ((X-128) * 256) -32768
using the same program, I reloaded the values ​​into the N7 file with the following reasoning

N7: 0 = (250-128) * 256-32768 = -1536,
N7: 1 (144-128) * 256-32768 = -28852
N7: 2 = (160-128) * 256-32768 = -246576
As seen in the second photo, the conversion adds symbols. I tried to extract a part of the string to rebuild the message, but could not find the solution
I have been reading previous threads, but the truth is that none of them addresses characters greater than 127
This is my first job as a professional, any help will do, thank you very much in advance!

RSLogix 500_1.jpg RSLogix500_2.JPG
 
N.B. the length of string ST11:1 is 4; those are not extra symbols. I think your code may be doing exactly what you want.

\90 is the multiple-character entity RSLogix 500 Pro uses to represent i.e. display the single character from encoding ISO-8859-1 (or perhaps Windows-1252) at codepoint 144 (decimal) = 0x90 (hexadecimal)

\A0 is the multiple-character entity RSLogix 500 Pro uses to represent i.e. display the single character from encoding ISO-8859-1 (or perhaps Windows-1252) at codepoint 160 (decimal) = 0xA0 (hexadecimal)

Cf. https://en.wikipedia.org/wiki/ISO/IEC_8859-1#Code_page_layout and https://en.wikipedia.org/wiki/Windows-1252#Character_set

P.S. ASCII is 7-bit. So strictly speaking, that device is not using ASCII, no matter what its manual may claim. Although to be fair the term "8-bit ASCII" is not uncommon, and usually means something like ISO-8859-1, Windows-1252, etc. I am not saying Logix cannot do what you want, I am only saying that calling it ASCII, instead of looking at the 8-bit bytes, will at best be irrelevant, and at worst bring confusion.
 
Last edited:
Also, rather than CODEPOINT*256 for CODEPOINT values 0-127, and (CODEPOINT-128)*256-32768 for CODEPOINT values 128-155, you might find it quicker to simply do something like this

Code:
BST AND CODEPOINT 127 N7:0 NXB MUL N7:0 256 N7:0 NXB XIC CODEPOINT/7 N7:0/15 BND
for any CODEPOINT value, 0-255.
 
Hello, I am writing again because I have the problem that, once I receive a string with values ​​greater than 128, I cannot form the decimal again.

I thought of the program as, once I receive the string (which I assemble for testing), extract the elements and move it to auxiliary addresses, and finally perform the count to obtain the decimal, but the problem is that when extracting a part from the string and move it to an integer, I don't get the numbers I expected
again to save code I write 2 integers 132 and 147 in the following addresses and clarification,
at N7: 0 -31744 (((132-128) * 256) -32768) = -31744
N7: 1 -27904 -> (((147-128) * 256) -32768) = - 27904
As can be seen in the attached image, at the address N7: 2 I put the integer that the program returns, which is 24064, and N7: 3 I place the other integer that the program returns, which is -15360.


Thank you all

ASC a DEC.JPG
 
Rung 0003 updates ST9:3 and N7:2 and ST9:4 and N7:4, from ST9:1, when B4:0/9 has a rising edge.


Rung 0002 updates ST1:1, but we don't see the conditions when Rung 0002 executes.


So if Rung 0002 executes on a scan and puts new values in ST9:1, but Rung 0003 does not see a rising edge on B3:9 after that, then the values in ST9:3 and N7:2 and ST9:4 and N7:4 will be stale and unrelated to the latest values in ST9:1.
 
Row 0002 concatenates ST9: 1 with ST9: 0 and stores it in ST9: 1. In N7: 0 and N7: 1 I load the values ​​with which, through MOV, to arm the chain.

The line 0003 I extract from ST9: 1 (chain already armed) the elements at Bit level, and as destination other 2 strings (auxiliaries). then I move them to integer addresses to do the count.

the conditions of each row, I put them with a NO and ONS to simulate a single scan cycle.

Adj. the program ,

Thank you !
 
1) Are you doing this on an emulator?

2) The CPT formula to calculate N7:1 on Rung 0001 of program file LAD 4 is
Code:
 ( ( N7:0 - 128 ) * 256 ) - 32767
Which suggests N7:0 is an ASCII code between 128 and 255, but N7:0 is -31744 (8400h)

3) Program file LAD 4 is never executed.
 
Last edited:
(0) I do not know what the problem was in Post #5, but the fact that ST9:1 1-character strings were not AEXed correctly into ST9:3 and ST9:4 is the start of the problem, and hides/precedes the problems in the CPT formulae in Rungs 0004 and 0005 of LAD 2. I did not have that problem when I ran the the code and triggered the steps in the correct order: B3:0/2; /6; /0; /9; /4; /7.

(1) The CPT instruction on Rungs 0004 and 0005 looks like this:
CPT N7:4 ( ( N7:4 + 32767 ) | 256 ) + 128
Preceded by [ADD N7:4 1 N7:4], which combine with the [+ 32767] to effect [+ 32768] or actually [+ -32768].

(2) Anyway, I am pretty sure that CPT instruction should look like this:
CPT N7:4 ( ( N7:4 + 32767 ) / 256 ) + 128
N.B. the bold red | (bit-wise OR) has become a / (DIVide).

(3) Although what you are looking for, for the whole rung, is this:
XIC B3:0/4 ONS B3:0/5 BST MOV ST9:3.DATA[0] N7:4 NXB XIC N7:4/15 OTE B3:0/15 NXB AND N7:4 32512 N7:4 NXB DIV N7:4 256 N7:4 NXB XIC B3:0/15 OTL N7:4/7 BND

(3.1) Alternates are
XIC B3:0/4 ONS B3:0/5 BST MOV ST9:3.DATA[0] N7:4 NXB DIV N7:4 256 N7:4 NXB AND N7:4 255 N7:4 BND
and
XIC B3:0/7 ONS B3:0/8 BST MOV ST9:4.DATA[0] N7:5 NXB SUB N7:5 -32768 N7:5 NXB DIV N7:5 256 N7:5 NXB ADD N7:5 128 N7:5 BND
(3.1.1) the former is universal and works whether bit 7 of the character is 1 or 0 and has a range of 0-255; the latter requires bit 7 of the character to be 1 and has a range of 128-255.

(4) In the attached .ZIP, there are two programs: one has the suffix _drbitboy; the other has the suffix _drbitboy_test.

(4.1) Both have replaced the CPT instructions with multiple rungs of atomic instructions, because my MicroLogix 1100/RSLogix Lite environment does not have the CPT statement.

(4.2) _drbitboy.RSS/.pdf implements the equivalent of the incorrect CPT instruction in item (1) above, and gives incorrect results in N7:4 and N7:5, although it does put correct values in ST9:3 and N7:2, and in ST9:4 and N7:3.

(4.3) _drbitboy_test.RSS/.pdf implements the correct code from item (3) above, which puts correct values in N7:4 and N7:5.

xxx.png
 
Last edited:
1-si , lo estoy emulando . y los resultados son las cadenas del archivo ST9 .

2- si , la cuenta la hice en un papel y cargue el resultado( ((N7: 0 - 128) * 256) - 32768 ). Como este pequeño codigo lo estoy usando para resolver el problema que describi al inicio , no queria determe en hacer la cuenta con bloques porque en otro scrip me funciona.

Si , en N7:0 almaceno ese numero y al moverlo al ST9:0.DATA[0] aparece la codificacion ASCII . Esta fue la forma que encontre para convertir un decimal en ASCII de 8 bits.

3- Si , ese Lad no tiene ningun sentido , lo deberia de haber borrado !
 
lo siento, no hablo español

1-yes, I'm emulating it. and the results are the strings from the ST9 file.

2- yes, I made the account on paper and loaded the result (((N7: 0 - 128) * 256) - 32768). As I am using this little code to solve the problem that I described at the beginning, I did not want to stop to do the account with blocks because in another script it works for me.

Yes, in N7: 0 I store that number and when I move it to ST9: 0.DATA [0] the ASCII encoding appears. This was the way I found to convert a decimal to 8-bit ASCII.

3- Yes, that Lad doesn't make any sense, he should have deleted it!
 
sorry, I forgot to translate it

1-yes, I'm emulating it. and the results are the strings from the ST9 file.

2- yes, I made the paper count and loaded the result (((N7: 0 - 128) * 256) - 32768). As I am using this little code to solve the problem you describe at the beginning, I did not want to stop counting with blocks because in another script it works for me.

Yes, in N7: 0 I save that number and when I move it to ST9: 0.DATA [0] the ASCII encoding appears. This was the way I found to convert a decimal to 8-bit ASCII.

3- Yes, that Lad doesn't make any sense, he should have deleted it!
 
here is a simpler approach to extract a character's ASCII code to the low byte of a 16-bit INT: concatenate the one character to a 1-character string containing a null character. See Rungs 0004 and 0005: ST9:2 is the 1-char null string; note that the character has already been AEX/extracted into ST9:3 or ST9:4 in Rung 0002.
 

Similar Topics

Hi all, Can anyone help with configuration machine with MODICON M241 controller? Specifically, it's about .cfg files in the usr / Cfg directory...
Replies
1
Views
1,529
All, I am working on an PLC controlled vessel, but the PLC program has been protected by code by the maker of the program Is there any suggestion...
Replies
0
Views
1,463
Hi, I am using the vHMI AB ethernet communication DLL and when I read floats, it keeps it in the IEEE-754 32 bit form. So when the PLC has 1835.19...
Replies
1
Views
1,737
In S7/TIA Portal, is there a function to round a real to a specified number of decimal places? e.g. If I have 22.519432 and I want to round it to...
Replies
16
Views
1,929
I am using a Micro 850E PLC (the new one with implicit messaging capability) to drive a Kinetix 5100 servo drive. The error code number on the...
Replies
7
Views
1,727
Back
Top Bottom