Russ McKenna

BMOV block1 block2 n using labels & arrays

9 posts in this topic

I am trying to use arrays in the ladder command BMOV and want it assigned to devices.

What I want is a string is stored on my HMI at D300 and it is 12 characters so it is really at D300, D301, D302, D303, D304. I can use DMOVE D300 D425 K5 and it will move the string. But I want to do it for a recipe where I cycle through all twelve recipes and get BMOV D300 D425 K5, then BMOVE D300 D430 D5, then BMOVE D300 D435 D5, etc.

I have attempted everthing. The problem is when I try to do BMOV myString myList[Index] K5. I have to create a data type that is used by myList so I can have each entry assigned do D425, D430 etc.

Any thoughts or hints.

Share this post


Link to post
Share on other sites

Hi, and welcome!

First of all it always helps to know the CPU type (FX/Q/iQF/iQR or similar), and the software used for your code. I've given some pointers below based on a more general approach.

I'm not sure I fully understood your data structure, but would it help to use stringmove instead of BMOV ($MOV)? Then you create an array of strings to replace "myList"? You can loop through your 12 recipes and just use for example:
Define recipeArray as an array of strings (recipeArray[0..11] Datatype:String(12))
$MOV myString recipeArray[index]

This procedure can also be achieved if you absolutely want to use BMOV instead of stringmove. Just use two-dimensional arrays for your "destination":
Define recipeArray as a two-dimensional array of words (recipeArray[0..4,0..11] Datatype:INT)
BMOV myString recipeArray[0,index]

In both examples above you will of course need a FOR-NEXT loop or a similar form of going through all the original recipes, but it looks like you've got that handled already since you're already into indexing your destination array.

Edited by kaare_t
Small typo in code

Share this post


Link to post
Share on other sites

I am using a FX5U, GS2107, GXWorks3, GTDesigner3.

I am using recipes with my string in device D300. As part of the recipe selection, I have a separate screen that list's these recipes. I have to fill this screen. So what I can do is select recipe 1 and copy D300 to D425. Load next recipe, copy D300 to D430. Each copy location is increased by 5. The challenge is having the label[index] pointing to my HMI device D425, D430, D435 based on the value of index.

How to you assign devices to an array?

Share this post


Link to post
Share on other sites

I'm still a bit in the dark about what you want to accomplish, not sure if I fully understood your problem but here is some pointers to begin with (maybe you already know about these):

14 minutes ago, Russ McKenna said:

The challenge is having the label[index] pointing to my HMI device D425, D430, D435 based on the value of index.

Is it a challenge because you don't know how to set the index? Is it a challenge because the index is coming from the HMI? Because the index will point to exactly the device you want to. If it helps, you can use a more direct indexing: Assign a value to one of the built-in indexing variables, e.g. Z1 (MOV index Z1). Then use BMOV D300 D425Z1 K5. This will move D300-D304 into (D425 + valueofindex). For example if Z1 = 0, then it will move into D425. If Z1 = 5 it will move into D430 and so on.

Regarding assigning devices to an array, if you are using labels (which it seems like you are since you're referring to labelnames), then you define arrays in the label editor. Just select "Array" in DataType and select the number of elements in the array (can also be modified later by just editing the values inside the "()").

If the above is totally off, and not helping you at all, then I have some questions that might help me understand your issue:

  1. Are you using labels (names instead of direct addressing)?
  2. Are you using Ladder, or Structured Ladder/FBD (just wondering)?
  3. Are you using the built-in functions for recipe in the GOT HMI?
  4. Do you have any scripts being executed from the GOT HMI to the PLC when selecting recipes (how do you know which recipe is selected in the PLC)?

Share this post


Link to post
Share on other sites

I am trying to use labels that assigned to a device rather than that device in the ladder logic.

I am able to use the Z1 approach. I am new to Mitsubishi and only have been to one class and still trying to get the hang of things. So yes, I am using the built in recipe functions and scripting. So i get the recipe number into D300 which is assigned to label SelectedRecipe. I use instruction MUL SelectedRecipe K5 Z1. Then use $MOV SelectedName D420Z1.

This works. SelectedRecipe is a value between 1 and 12, I want it stored first at D425 so I use D420 + 5*index. Now is there a way to make D420Z1 a label like myAddress(Index) not myValue(index). I want it stored at a location defined by myAddress(Index) or the device assigned to it.

I do appreciate the assistance. You have provided me with several new ideas that I can implement.

Share this post


Link to post
Share on other sites

I see. Labels are good, and a nice way to structure your code (in my personal opinion). The "problem" with indexing labels is that it needs to be an array. So basically, all your stored recipes must be in an array. I've always used labels so I really don't think of it as a problem. See attached pictures for an example. I've defined two global labels that are essential. The "original recipe" (moving data from this), and the "recipeArray" (this is the collection of all your recipes stored - it's an array of strings - a total of 12 strings/recipes). I've also attached a small code that shows how to use it in two different ways - it's a very small example but I hope it shows the principal. Let us know if this works for your. There are other options available. I've used labels since I started writing PLC code, since I'm from Norway we early adopted the IEC development style and we don't like to use addresses directly in the code (for a lot of reasons....). So there's almost always a solution using labels in my opinion.

Labels.PNG

 

Code2.PNG

Edited by kaare_t
Modified code picture to add two options
1 person likes this

Share this post


Link to post
Share on other sites

Thank you for your help. I have learned much.

When creating a lable like MyText, String(10)(0..11), assigned to device D425 and then I watch MyText[0], the device is D425. But the device for MyText[1] is D431. I need to create the MyText as a String(9).

My fundamental challenge came my lack of knowledge. When you create an array of a structured data type you can manually assign devices to each array and they do not have to be sequential. So when I tried the same approach I could not figure out how to get array[1] device to be set to D430. It will automatically be set by offsetting the device for array[0] by the length of the variable (5 in the case above because a string is 2x8 x length, and each register is 16). I am curious why I need it to be 9 not 10, does it start at 0-9 so it is 10. Or is there a disconnect  in the auto assignment of the devices?

Normally you don't care where things are stored and you don't want to assign devices. But I am interacting with an HMI and as far as I know it does not use common labels. The FX5U does not do this yet. 

Share this post


Link to post
Share on other sites

Hi and sorry for the late reply, got stuck with a job.

Yeah, strings and (Mitsubishi) PLC's are not the best of friends... No, it does indeed start at "1" but for some (for me unknown) reason there is some overhead when using strings which causes the string to be "-1".

Did you figure out how to do your code, or do you have further questions at the moment?

Share this post


Link to post
Share on other sites

Yeah, I got caught on a project - also completed the Simple Motion class in Vernon Hills, Illinois.

I ended up using - String(9)(0..11) as my definition, and as I stated above why not 10 but 9 works. So yes the code is working. Looking to try and have a superimposed screen switch from one image to the next using script so I can have it based on a value in a text box.

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