Micrologix 1400 send value as ASCII via Modbus TCP

ASF

Lifetime Supporting Member
Join Date
Jun 2012
Location
Australia
Posts
3,921
Hi all,

Question straight up: if I have a micrologix 1400 with a value of 1234 in register N7:0, how can I convert that value to ASCII values and store it in N7:1 and N7:2? i.e. N7:1 should have the ASCII data for "12" and N7:2 should have the ASCII data for "34".

Context, and more information...

I've been left in a tight spot by being told "yes, our product can do that" until I've ordered it and found that it can't. Long story short, now I need to send a numerical value from a Micrologix 1400 to a Modbus TCP device, but the number has to be sent as ASCII characters.

From the information I've got, each modbus register holds two characters. I need to send a 4 digit number to registers 40002 and 40003.

The number I want to display is in F8:11. The first thing I'll do is move it into an N register to remove the decimal place (not required here). Let's I move it into N7:0, and it's value is 1234.

So then I have to convert this value into ASCII characters and store it in, say N7:1 and N7:2.

Once I've done that, from my reading of the ML1400 reference manual, I just have to set up a MSG instruction to do a Modbus write to register 40002 from N7:1 with a length of 2. I've not set up a MSG instruction for Modbus TCP before, so any tips or gotchas with regard to this part of the project would be appreciated as well :)

Anyhow, appreciate any tips or tricks, especially with getting the data into the right format!
 
Look up the reference for the AIC instruction, which converts an Integer to an ASCII String.

The characters of the integer value string will be packed two at a time into the string's Data section.

ST9:0.Data[0] holds characters 1 and 2
ST9:0.Data[1] holds characters 3 and 4
and so on.

I tend to copy the values of ST9:0.Data[x] into Integer data tables first to have a look at them either in hex or ASCII format.
 
Thanks Ken, that's the instruction I was looking for. I'll have to copy them back into N registers anyway to be able to send them in a MSG instruction - although I seem to be stuck there too. My syntax is COP ST9:0.DATA[0] #N7:1 4, and I get the error "address must be specified to the element level". It's unhappy with how I've addressed the source string, but it's exactly how you've typed it above, and I can't think of any other way to address it...
 
EDIT: I think you don't need the ".data[0]". I think you only need to specify "ST9:0". If that does not work, try CPW instead of COP. I can't test this right now, but I have found that the ML1400 is more picky about data types matching with the regular COP and also the Length parameter may not behave as it does with other SLC series.

Failing those two ideas, you may have stumbled across a limitation with the ML1100/1400 that I seem to recall reading about here by another member.
 
Last edited:
CPW does the trick! Thanks Paul :)

Hopefully everything goes smoothly with the Modbus TCP messaging side of things, if not, I guess I'll resurrect this thread in a few weeks ;)

Cheers!
 
*bump*

Well almost everything went according to plan. The only thing that didn't is that as well as the value I needed to send, I had to send some other ASCII characters to make it display correctly. This was all fine, except that one of the ASCII characters was lower case. Initially I just manually typed the ASCII characters into a String, and then tacked the other value on the end and stored it in another string. But for some reason every time I put my lower case value into the string it would make it upper case. In the end I had to bypass the string altogether, use the internet to convert the ASCII characters to hex, manually enter them into 12 sequential N registers as hex, and then add my value that I wanted to send into the next couple of N registers. When I do this, and then view the N registers with Radix ASCII, it displays the lower case characters correctly.

It works, but I'm mystified as to why the String data type won't play nice with my lower case letters. Anyone seen this before?
 

Similar Topics

Hello, I have problem with Modbus MSG. When i use ladder logic like this (which worked for other projects): I got timeout error on every even...
Replies
5
Views
3,932
I have a Micrologix 1400 and I want to send ASCII data over ethernet to print a barcode in a Zebra printer. The model of the printer is GX420t...
Replies
28
Views
25,882
I am trying to send a control z out of port 0 on a micrologix. ASCII. How would one complete such a task. Thanks Jim
Replies
13
Views
4,548
I'm using a SLC typed write from the ControlLogix5572 to the MicroLogix 1400, with path: 2, (MicroLogix IP). The ControlLogix equipment has a...
Replies
0
Views
86
Hi, I am working with a Micrologix 1400 model 1766-L32BXB. With no input wires connected to the “in12” thru “in19”, I am getting 24 volts while...
Replies
4
Views
221
Back
Top Bottom