Open source Pure C # Industrial Gateway + configuration Software (v) from the gateway to the HMI

Source: Internet
Author: User
Tags tag name

First, Intro

Before the gateway, many netizens concerned about how to implement the interface. To understand the change of the next machine variable, it is how to trigger the human-machine interface animation in one step.

This step-by-step trigger is essentially a bulk data change (DataChange) event for the variable group (s), which raises the variable (TAG) value Update (ValueChange) event, which eventually triggers an animated script (Action) of the entity. This is a chain reaction.

In short, the interface is a group called tag passengers, from the gateway to the TLV protocol of the train, to the upper station to get off, on clientservice this stage, with their own musical instruments (Itagreader) played a symphony.

Second, the core object of the connecting link: Tag

tag(tag or variable) is the core object of the whole project. The so-called core object is that it is ubiquitous, dynamic, and flowing, just like blood.

In essence, tag on the next machine, is a sensor data, a switch signal; On the upper computer, is a button, instrument panel, motor.

Tag is generated in the variable manager (tagconfig), allocated at the time of system initialization, exists in all corners of the HMI program and the Gateway Service, and their values and timestamps are constantly changing.

To the host computer designers, the use of tag name, tag data type, to the next computer designers, see the tag address, the length of the tag. For variable alarms and data archiving, you need to know the timestamp of the tag.

All tags inherit from the Itag interface. The type of tag is the type of data, with Floattag (floating point), Booltag (logical type), and integer, character type. Different types correspond to the Readxxx method of the Ireaderwriter interface.

Tag can take the initiative to read (write), or the passive refresh (Update), forced Refresh (refresh).

The Read method of the tag is to call the owning group, and finally the Readxxx method that calls the owning idriver to read the data from the slave computer. However, the main application scenario of tag is that the passive refresh triggers the ValueChanged event to drive the HMI.

Third, connection of the upper and lower machine: TLV protocol

The previous article has explained how the gateway by polling the lower machine, push the batch data to the host computer. The host computer needs to parse the pushed data stream into a bunch of changed tags to drive the entire human-machine interface and control logic.

Communication between the gateway and the host computer, I used a custom simple TLV protocol (tag-length-value), which is hosted on the socket.

This agreement consists of two parts:

    • Data push : The tag that changes at one end of the gateway is packaged, transmitted to the client, and the client is unpacked and restored to a heap of tags. The specific process is:
    1. The DataChange event of the gateway calls the SendData method to package the changed tag as an historydata array (containing the variable ID, value, timestamp);
    2. The socket converts the historydata array to a byte stream and pushes it to the client;
    3. The client's clientdriver contains a Recivedata method that restores the byte stream to an historydata array and triggers the client DataChange event;
    4. The client's DataChange event converts the historydata array to a tag array and invokes the tag's update to trigger the valuechanging and valuechanged events.
    • directive : The client actively sends instructions to the gateway, which is generally used to read, write a specific variable or a batch of variables, but also can query the historical archives, query alarm and so on. The instruction format is as follows:

Instruction Code Fctcommand: contains various commands; parameters: If all archived data is read in the time period, the start time and end time are required, and the variable ID is required to read in the variable. Return value: The gateway receives the instruction and returns the data, which is also a byte stream.   

     Public classFctcommand { Public Const byteFcthead =0xAB;//header can be encrypted, such as the header does not do anything, the client socket sends an alarm request, encapsulated in the server         Public Const byteFcthdaidrequest = -;//read historical data by variable ID         Public Const byteFcthdarequest = to;//Read all historical data in the time period         Public Const byteFctalarmrequest = +;//Read alarm data         Public Const byteFctorderchange = -;//Read Order         Public Const byteFctreset = the;//reset directives, typically used to release gateway sockets         Public Const byteFctxmlhead =0xEE;//XML Protocol         Public Const byteFctreadsingle =1;//Read single variable         Public Const byteFctreadmultiple =2;//Read multiple variables         Public Const byteFctwritesingle =5;//Write a single variable         Public Const byteFctwritemultiple = the;//Write multiple variables}

Four, Man -Machine interface Drive engine: ClientService

Client ClientService and gateway DaService the same: all have similar structure, inherited Idataserver, Ialarmserver, all from the same database load drive, group, variable, alarm:

Client-side:

 Public Sealed class Daserver:idataserver, Ialarmserver, Ihdaserver

Gateway for:

 Public class Daservice:idataexchangeservice, Idataserver, Ialarmserver

Just one more ihdaserver, with the ability to query historical data, and historical data archiving is a gateway function.

As a result,ClientService also comes with its own drive clientdriver,clientdriver also comes with its own group Clientgroup .

Note thatClientdriver is the only driver on the host computer, andClientgroup is also the only group of Clientdriver . This is because the host computer does not have to deal with a variety of sub-machine, the only thing to deal with it is the gateway itself.

Therefore, the various operating instructions of the HMI, such as press button, read archive data, query alarm, etc., eventually reflect the TLV protocol instructions sent to the gateway, and get feedback.

and the human-machine interface element animation, is from the gateway push tag, trigger valuechanged event, the subscriber of the event, is the entity corresponding to the itagreader, primitive animation behind the command.

Five, the behind-the-scenes conductor of primitive animation: Itagreader

The Itagreader interface inherits all element components, and its function is to bind the tag to the animation. First look at the structure:

     Public Interface Itagreader:itaglink    {        stringgetset;}         string [] getactions ();        Action Settagreader (string  key, Delegate tagchanged);        IListget;}    }

The Tagreadtext property is the variable expression associated with the primitive animation: shaped like a tag1*2+tag2*5>10. I implemented a custom expression compiler eval that parses the expression syntax, separating out TAG1 and Tag2. This code is in Example-windowhelper-bindingcontrol.

Next, the element component subscribes to the ValueChanged event for Tag1 and Tag2.

If the value changes, Settagreader is executed inside the event, the result of the expression is evaluated, and instructions are sent to the interface.

If tag1*2+tag2*5>10, this time tag1=1,tag2=2, satisfies the condition, eventually produces an animated script:Action. This Action can be a motor alarm, the color becomes flashing red, it can be lit a lamp, or open a valve. This is explained in detail below.

From the gateway to the HMI process:

Six, 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
    • From the gateway to the HMI
    • 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. QQ Group: 102486275

Open source Pure C # Industrial Gateway + configuration Software (v) from the gateway to the HMI

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.