Sign in to follow this  
Followers 0
paulcoverley@sky.com

serial input string

9 posts in this topic

Hi 

I'm quite new to plc but very new to mitsubishi.

 

I have an input string eg G+002.7 which represents a weight.

I wish to take in the input string then move/convert to int omitting first char,

 

On other plc's i have been able to use a modifier like d200[2] then the no of chars.

How do i achieve this in gx works3

 

Any feedback gratefully recieved

 

Paul

 

Share this post


Link to post
Share on other sites

will this string always start with "G" ?  If so, Change your HMI input to be Float input and just add the G as a prefix visually

If not, then a block move (BMOV) starting at the second register of your string address would drop the first characters. 

Edited by WattUp
if not answer.

Share this post


Link to post
Share on other sites

Hi , thanks for your reply - to provide a bit more info please see below images of prog and registers.

From the results recd I'm only interested in D201-D203, however i will need to pick up to + sign ie the 2nd byte of d200.

I want to use the +2307.4 in calculation as a signed integer.

 

Any further feed back greatly appreciated

 

Many thanks

 

Paul

 

prog.PNG

regview.PNG

Share this post


Link to post
Share on other sites

OH going from ASCII String to numbers... not sure that happens without some ASCII lookup table 

 

What control do you have on that the input field / method?  It would be better fix the data source than write a algo to convert

Share this post


Link to post
Share on other sites

I don't speak ladder but in ST I would do it like this.
Maybe that helps.

Greetings
Dave

P.S. If you need INT not REAL (with one decimal place) you can add this at the end.
nResult := REAL_TO_INT(rResult * 10.0);

String_To_Real.jpg

Edited by Dave W.

Share this post


Link to post
Share on other sites

This function does exist, and its EVAL

 

Quote

 

Function

(1)   Converts character string stored in the area starting from the device number designated by image1728.gif to 32-bit floating point type real number, and stores result at device designated by (2)   The designated character string can be converted to 32-bit floating point type real number data either in the decimal point format or the exponent format.

 

 

You will have to clear that "G" with a XOR "FF00" D200 first

Share this post


Link to post
Share on other sites

the masking operation need to use AND, not XOR...

XOR with 0xFF would change 'G' (value 0x47) to value 0xB8 which is not what you want. in fact one may probably want this value to be a non-zero since zero may be seen as end of string. so space character would likely be safe choice... (setting that would need an OR instruction)

1 person likes this

Share this post


Link to post
Share on other sites

OH yeah of course good catch.  I don't know why XOR was in my head.. 

Share this post


Link to post
Share on other sites
10 hours ago, WattUp said:

don't know why XOR was in my head

Do much machine language programming?  XORing a register with itself is an efficient way to zero it in many architectures, mainly because no constant needed in the instruction stream.

Not so much for PLCs.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0