How do I scale data within a register-based PLC and sample the scaled data?

How do I scale data within a register-based PLC and sample the scaled data?
none 0.0 0

Hi,

My question is, is there a way to put a minimum value as a limit, to get printed on the excel document.

Let say my sensor gives me values from 0 to 30, but I want 7 to be my minimum value printed out in the excel files, even if I get a value lower than 7 I need this to be the minimum value printed on the excel file.
Would this need to be done with a macro or is there another way to do so.

Thanks

Hi @gary14,

This is a great question, I think that in this scenario it would be best to use either a Macro or a Macro subroutine. A subroutine is a special type of Macro that can be applied to a register-based device like a Modbus TCP/IP device during tag creation. Subroutines can convert values that are read or written into an object that utilizes this tag. Here is an example:

  1. Within my project I have a Modbus TCP/IP device:
    Note: This is considered a “register-based” device because devices that conform to this protocol use addressing in the format of [Some place in memory] - [some number] like 4x-1 and 0x-1. A tag-based device uses symbolic addressing like "Motor[0].rpm.
    image

  2. To perform the scaling that you described, I’ll create a Macro subroutine. To do this, I’ll select the “Project” tab and click “Macro”:

  3. Within the following menu, click “Library”:
    image

  4. When prompted, click “New”:
    image

  5. Configure the scaling logic. The declaration of “short” after the keyword “sub” defines what this function will return. The name of this function is called “Scale” and it has one parameter called “param”:
    image

  6. Click “Compile” and “Save” when finished:

  7. Navigate to the “Data Sampling” object and within the “Data” menu click “New”:

  8. Click the “Add tag” button to create a new tag:

  9. Configure the name and address and enable “Conversion/calculation”. Within this section ensure that the data type matches what is returned by the subroutine (e.g., short is a signed integer) and then select the “Scale” subroutine from the “Read conversion” list:

  10. Click “Ok” when finished and the scaled conversion tag will be added to the “Data” menu:

  11. Finish configuring the “Data Sampling” object and then download the project. You will notice that the data sampling object now records the scaled value:

Note: Please consider the following recommendation:

Would this solution work within your application?

Brendon,

This is amazing, I will start working on my program changes, I will let you know how it goes after I do the changes and do some testing, if I get stuck on something I will let you know .

Thanks !

1 Like

Brendon,
I already have have the user defined tags for the value I want to convert I only need to add the subroutine to the conversion/calculation area.

So I have 3 different tags that I want to set 7 as their minimum printed value.

Do I need to create 3 different sub macros for each one of can I use just one for all 3?

Thanks

Brendon,

When I try to compile my program I keep getting the same error message.

Any ideas ?

@gary14,

My apologies for the delay, the same subroutine can be used for all 3 addresses. Additionally the failure during compilation is likely due to an incorrect data type set within the data sampling object. As an example:

  1. If you configure the following tag:

  2. The data type set within the data sampling object must match the defined data format:

Brendon,

I double checked all the data types and even created a new tags and data sampling object, thinking that would fix it.

But no success.

The only way I was able to be able to “fix” the error was when I moved the bottom tag in my DATA window (tag flow ml/m) all the way to the top and I stopped getting that error.

Any ideas what might of caused it or if this might be a bug with easybuilder pro ?

I was not able to replicate a similar issue on my end. When you have time, can you please advise the following information so that I can re-test this issue:

  • What version of EasyBuilder Pro are you using within your application?
  • Can you post an image of the configuration of your Modbus tag and subroutine?

*Easy Builder Pro version 6.08.01.350

  • I’ve attached the pictures let me know if you need additional information.



Hi @gary14,

My apologies for the delay and thank you for the information! We will investigate this issue and report back with our findings. I will let you know if we require any additional information.

Hi @gary14,

Our factory has identified the source of this issue and will patch this in a later version. At this time, please use the following solution:

  1. Ensure that the first element in the “Data format” dialog is a non-conversion tag:

Thank you for reporting this to our team!

1 Like

Glad I could be of help :smile: