PLC Shift applications are written in the C# programming language and use Microsoft's .NET runtime technology. This means that the exact same code can be used to target any operating system where .NET runs, including Microsoft Windows and many common Linux distributions. This also means that the same code can be used on different processor architectures, including ARM and x86.
With typical embedded systems and programs, code is written in the C or C++ programming languages, and it's usually difficult to run and test the program except on the specific hardware that it's written for. This is also true for PLC programs written in IEC-61131 languages. Additionally, C# and .NET have sophisticated automated testing frameworks. This type of functionality is simply not available in PLC programming languages or is a manual process of forcing some set of variables and logging the outputs.
In other words, using .NET makes it easier to run our applications anywhere, which makes it far easier to implement automated testing for our applications, which ultimately results in high reliability.
Automated Testing
For every application that we release, we have also written a corresponding series of tests. Because all of our applications use our automation framework, we have built software that scripts the process of setting input variables and configuration parameters, running the app, and then validating that the outputs are exactly what we expected. We run these tests as fast as possible, which means that it's possible to test how any app runs over many days in a few seconds or minutes.
Automated testing is especially valuable when we add features or make changes to an existing application. We can be assured that the changes that we made did not break any existing functionality. A summary of the test suite for the PLC Shift Gas Flow app at version 1.4 is shown below. There are 66 tests in total, and the entire test suite takes about 2.5 minutes to execute.
Test Script Overview
We use what we call a test script to actually run tests. A script is really just more code, but it allows us to do a few different things, including:
Set a test to run for a specific amount of time. This is the simulated time that a test runs for, not the actual time that it takes to run the test.
Set inputs to a specific value at a specific time.
Print values from the app to the console.
Verify that the values generated by the app match the expected value. If the values don't match, stop the test and indicate a failure.
The code below shows an example of a script for the PLC Shift Plunger Lift app. In this case, we are testing that the app correctly detects normal plunger arrival. The script does the following things:
Set the test to run for 15 minutes.
Set the value of Flow Conditions->Off Time and Shut In Conditions->On Time to 240s. Also, set the value of Plunger Condition->Plunger Exists to true. All other values for this app remain at their default values.
Set the casing, tubing, and line pressure values as shown. This isn't required for this test.
Set up asserts to verify that the control states are as expected at 2 and 242 seconds after the test is started.
Increment the plunger arrival counts at 592 seconds into the test.
Set up asserts to verify that the Plunger Arrived tag is set and the plunger arrival counts match the expected counts. These are all tested at 593 seconds into the test.
The last line actually executes the script against the app run time code. Any errors stop execution. Although the test is set up to run for 15 minutes, this test takes just under 1 second to run on our development computer.
The output generated by this test is shown below. This is almost the same information that you would see in the application's diagnostic log on a live system. Looking at the timestamps, the app thinks that the test started at 19:44, and it runs until 19:59, which matches our 15-minute run time, even though the test only actually took 1 second to run.
Gas Flow Contract Hour
Automated testing is very flexible and powerful. In the test script snippet below, the Contract Hour parameter is generated randomly for each test run. Once we know what the contract hour is, in the test we can calculate the time from the start of the test to the next contract day, and then validate that the accumulated volumes are correct at the end of the contract day and that the accumulated volumes correctly reset to 0 at the start of the new contract day. Using random values allows us to really exercise the system over a wide variety of use cases.
Gas Flow Calculation Accuracy
The Alberta Energy Regulator (AER) publishes a set of guidelines for electronic flow measurement which is known as AER Directive 17.
Section 4.3.6.2 has various test cases that electronic flow measurement devices must meet. We use our automated test framework to verify that our calculated measurements are well within the allowable range for all 15 test cases. The results are summarized below. Let us know if you want the configurations so that you can run your own tests. In all cases, the allowable deviation is +/-0.25%. The deviation is much less than this in all cases. Test case 6 with an upstream tap has the worst deviation at 0.003988718981597353%. This is still 60 times better than the allowable deviation of 0.25%.
Test Case | Tap Location | Expected Value (e3m3/24hr) | Calculated Value (e3m3/24hr) | Difference (%) |
1 | Downstream | 2.7531 | 2.7530230478354203 | 0.002795109679255792 |
1 | Upstream | 2.7478 | 2.7476657570010006 | 0.004885471977553801 |
2 | Downstream | 146.18 | 146.18036698540715 | 0.000251050353769612 |
2 | Upstream | 146.08 | 146.07530704171222 | 0.003212594665793275 |
3 | Downstream | 8575.48 | 8575.042921812765 | 0.005096836413062294 |
3 | Upstream | 8564.77 | 8564.340288784259 | 0.005017195041336986 |
4 | Downstream | 503.63 | 503.64409436615574 | 0.002798555716646303 |
4 | Upstream | 503.44 | 503.45219234453236 | 0.002421806875172007 |
5 | Downstream | 813.0 | 812.9833216251882 | 0.002051460616459751 |
5 | Upstream | 799.83 | 799.820562674861 | 0.001179916374612193 |
6 | Downstream | 14.746 | 14.74658637180739 | 0.003976480451582848 |
6 | Upstream | 14.687 | 14.687585823156827 | 0.003988718981597353 |
7 | Downstream | 1.4489 | 1.4489061369122083 | 0.0004235566435356336 |
7 | Upstream | 1.4335 | 1.4335124298504038 | 0.0008670980400306193 |
8 | N/A (AGA7) | 3770.9 | 3770.934235567103 | 0.0009078884908846425 |
Conclusion
PLC Shift applications use modern software development methodologies to ensure high reliability. We can test various operating modes, randomly generate inputs, do long-term testing, and really exercise our apps automatically. As a customer, you can be assured of quality right from the start.