Converting binary to ascii string - CompactLogix v32

rupej

Member
Join Date
Sep 2014
Location
NC
Posts
967
Have an unusual one here, guys...

I have a remote machine that is sending my 1769-L33ER five 16-bit integers that represent 10 ASCII characters. Each 8-bit half of the integers (byte) contains the value of one ascii character in binary.

I have to unpack this by converting each byte into an ascii character, and then assemble the characters into a readable string.


I don't see any particularly helpful instructions in Studio 5000. My first thought is to brute force this with boolean logic to convert the bytes to integers, then generate a lookup table for converting the integers to ASCII.

Does anyone have any recommendations for a cleaner way to do this? Thanks!
 
Last edited:
This should be very simple, with nothing more complex than a COP or CPS instruction to the .Data[x] portion of a STRING datatype tag.

You might need to swap bytes, depending on the order they come in. Easy when they're packed into an INT.

And you might have to figure out the intended .LEN of the string, if it's not fixed.
 
Ha, shame on me for not searching here first...

Thanks Doc & Ken, that's exactly what I needed!
 
In this day it is not that unusual or is it that difficult
You just need to take things one step at a time.

You say that it information is receiver as an ASCII string 10 character long
When that a place to start but with received ASCII strings you have leading and trailing characters that you need to deal with.
You need to look at the manual of the transmitting devise to see what they are. There will be at least 1 character for each I would expect there to be at least 3 leading characters and 1 or more trailing.
The leading and trailing characters define the valid data you want without them you would have no way of knowing where to start

The first thing you need to do is copy the received string to string tag, don’t forget to also enter the string tag length in the correct field.
Next you need to pull out the characters you want using the ASCII Find function ( FIND ) and the ASCII MID ( COPY ) function
Then you need to convert the extracted string to DINT tag using the ASCII STOD (String To DINT)function from there the data is in correct format to use in your program I usually do this in a sub program called when needed.
It takes a little practice but you will get the hang of it.
 

Similar Topics

Good Morning all, I am reading a serial string in Beckhoff twincat from an RS232 motion sensor. My problem is that the motion sensors...
Replies
3
Views
3,070
hi everybody! I only know how to convert Binary to BCD with some instruction with plc. EX: [ BCD K10 D0 ] convert 10 decimal to BCD in D0 registry...
Replies
5
Views
3,952
We have an AB 1395 drive controlled by a PLC-5/40 via RIO. We are developing a monitoring computer using RSView32. This computer will poll the...
Replies
12
Views
7,870
Does anyone know how to convert from a decimal number to a true binary output. For example convert the number 15 to 1111 and then be able to turn...
Replies
9
Views
14,751
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
208
Back
Top Bottom