First, Intro
First of all thanks to the blog Park: The first article, the first open source project, is hit. Can see, most of the project traffic from the blog park, the code farm, the reputation ^ ^ ^.
The park friends gave me a lot of support, and put forward very good suggestions for improvement. Now added screen resolution Adaptive and OPC server can be CLSID and ProgID adaptive loading function. Screen Adaptive This is a common problem, because before the standard hardware, a lift, a lazy to ignore.
Just 10 days ago, I was a rookie who clicked on GitHub. How to edit the Readme file is now available for sale.
The first time I uploaded a warehouse to GitHub, I downloaded the discovery without any exe,dll,bak files! Change the Ignore file. In a word, gig, all kinds of embarrassment.
But there are friends to cheer, I do not shallow, to akinori in generous.
Second, How to add a new driver
I updated the DLL folder: Added Libnodave.dll, Libnodave.net.dll, SiemensPLCDriver.dll. This SiemensPLCDriver.dll,
Is the Siemens S7 series PLC driver (including source code, in program). please synchronize or re-download the latest version first .
The Libnodave Open Source Library (Https://github.com/netdata/libnodave) is said to have been made by the German great God from Siemens. A previous year, a word: Can fix the driver is Daniel.
I found the Libnodave, the package after the successful implementation of the Siemens 200PLC Communication, very encouraged, but also become the starting point of the project.
Open the Variable manager tagconfig, click Register, double-click the "Path" box and locate the SiemensPLCDriver.dll in the DLL folder.
If it appears in the list below, tick, click Register, generally will prompt success.
At this point, the right-click tree node s1-> parameter settings, you will see that the S7 Ethernet protocol has become an option.
In fact, a series of actions, that is, the information that drives the DLL, has been written to the database Registermodule table.
This table provides the basic information for the system service reflection -Loaded driver: The location of the load, the class name, and the description so that it can be instantiated as a specific driver class.
There is a Adddriver method in Daserver , that is Activator. CreateInstance loads the driver and converts it to idriver.
The biggest advantage of using reflection loading is that users can implement a driver themselves, or refer to a third-party driver and register with Tagconfig without having to change the source code.
Third, How to implement a new driver
- Driver Interface Specification
[Description("S7 Ethernet Protocol")]
Public Sealed class Siemenstcpreader: iplcdriver, imultireadwrite
As I mentioned in the previous article,Iplcdriver is an interface implemented by all PLCs. Imultireadwrite is the interface that a subordinate machine must implement to support bulk read and write.
Because PLC has the connectivity, can read and write, while the Siemens protocol also supports bulk read and write.
The Connect method in Siemenstcpreader is the encapsulation of the CONNECTPLC method in the Libnodave.
The Dispose method is to release libnodave unmanaged resources.
Readbytes, ReadInt32, Readbit, Readfloat, Writefloat, and so on, is the implementation of the Ireaderwriter interface. That is, read and write alone.
The ReadMultiple and WriteMultiple method is the implementation of Imultireadwrite interface, and also the encapsulation of bulk reading and writing methods in Libnodave.
This Description property descriptor, which is reflected as a driver descriptor after registration, is stored in the database.
- Why bulk Read and write, how to achieve
The purpose of bulk reading and writing is to improve performance.
Many people always take C #,. NET's so-called performance to say things. First of all, I think. NET performance is excellent. The key is how you write.
Most of the performance impact is not the language, the framework, but IO. The performance cost of IO is often 10 times times, a hundredfold, or even a thousand of thousands of languages.
In the process of PLC communication, the request roundtrip is a performance bottleneck. Because most lower-order computers do not support subscription-release (push) mode, they can only be used on a periodic polling basis.
Since it is polling, if a lot of variables, if read and write one by one, reading 1000 variables to poll 1000 times, a round trip at least dozens of milliseconds, the efficiency of the staggering, also occupy a large number of resources of the PLC. It's not working.
But if you want to be able to read 1000 variables at a time, take into account that the variables may be discontinuous and scattered.
Therefore, it is important to analyze the distribution of variables, similar to express delivery, customers, although distributed in various communities, but not as drunk as aimless delivery, but according to the distribution of customers, the implementation of the most optimized route selection.
The result of the collation is that all the variables to be read and written are divided into blocks, each block cannot exceed the PDU of the PLC. Try to minimize the number of round trips, one read in the largest chunk, contains the most variables.
The function of splitting and organizing variable chunks is the realization of Plcgroup 's Updatepduarea function. But I'm just doing a simple address induction here, and I'm not doing the optimal solution. The optimal algorithm must be present, but it may not be too large for the current method.
Four, the following plan
Write a series of posts to clarify the architecture and principles. Roughly as follows:
- Gateway-Layer Interface Overview
- Communication principle of the upper and lower machine
- How to implement a device driver
- How to design elements
- VS plug-in modules and principles
- Archive modules and file formats
- How to extend a feature
- Configuration Variable Expression implementation
GitHub Address: Https://github.com/GavinYellow/SharpSCADA. Welcome you to make valuable comments and suggestions!
Open source Pure C # Industrial Gateway + configuration Software (iii) Add a new driver: Siemens S7