How to make Validate.Attribute more generic w DataSource

Best practices, code snippets for common functionality, examples, and guidelines.
User avatar
Posts: 24
Joined: Tue Nov 21, 2017 12:51 pm

How to make Validate.Attribute more generic w DataSource

Post by _KK_ » Tue Nov 21, 2017 1:31 pm

Environment: A WPF-GUI is coupled at least to a PLC.
The goal for automation of testing is to write into the PLC, read the value of the PLC and compare it with the current content (value) of the GUI.
This should be made as generic as possible, so that the important values are driven from a DataSource.
Attributes are IoPath for identification of the control, value, c#DataType, TwinCatDataType and more.

The ugly thing is, that there is a lot of needed convertion because the DataType of the application and the PLC differ.
E.g.: DWORD in application is UInt32 in PLC.
The other thing is, that the GUI shows at numbers a decimal point, e.g. 12.007, 4.294.967.295

The writing and reading will be done in a "code module" and works so far.
I was not able to make the check with Validate.Attribute generic, so that every value can be checked.

My approach with items in the RxRepo:

Code: Select all



The "Variable" DSC_Caption_Int16 has a default value, e.g.5555

code in module

Code: Select all

string _DSC_Caption_Int16 = "5.555";
        public string DSC_Caption_Int16
        	get { return _DSC_Caption_Int16; }
        	set { _DSC_Caption_Int16 = value; }
Validate.Attribute(repo.Window.Text9999_Caption_any, "Caption", _DSC_Caption_Int16);

Is it a good idea to bind the module-variable with the "Variable" in the repo?
And how to do that?

Thanks in advance for an answer.



User avatar
Posts: 240
Joined: Fri Jan 09, 2015 3:24 pm

Re: How to make Validate.Attribute more generic w DataSource

Post by RobinHood42 » Thu Nov 23, 2017 3:28 pm

Did you know that you can use a regex as parameter in the Validate.Attribute() method? You might not have to do a conversion at all.
Attribute(RepoItemInfo, String, Regex)

User avatar
Posts: 24
Joined: Tue Nov 21, 2017 12:51 pm

Re: How to make Validate.Attribute more generic w DataSource

Post by _KK_ » Mon Nov 27, 2017 2:19 pm

Thanks Robin,

when I use in the Validation a RegEx so I can validate only e.g. if there numbers or letters are "in".

To make my Approach more generic I use in the repo-variable a "regex" like

Code: Select all

repoVariable   PaperRun_QualityDataMeanValueFeedAirSpeed_caption_RegEx 
with Path
So this is as desired generic for numbers.

In the Validate.Attribute I will use the repo-variable and validate against a DataDriven variable with actual value "in" _DSC_Caption_UInt32.
Maybe you remember that I wrote that the UI Shows the value with 1000er Separators.
To avoid reading/converting/Stripping I use maybe not the best way with my approach, but it works.

Code: Select all

Validate.Attribute(repo.Window.PaperRun_QualityDataMeanValueFeedAirSpeed_caption_RegEx, "Caption", _DSC_Caption_UInt32);
I know that I have to read more of documentation to find the "best practise".