Serialization | Iot framework ServerSuperIO tutorial-11. Implement device (driver) and device (driver) interaction and cascade control. Note: the conversation between device-driven simulation gold 3 and Putin, serversuperio

Source: Internet
Author: User

Serialization | Iot framework ServerSuperIO tutorial-11. Implement device (driver) and device (driver) interaction and cascade control. Note: the conversation between device-driven simulation gold 3 and Putin, serversuperio

1. C # Introduction to cross-platform Iot communication framework ServerSuperIO (SSIO)

Serialization | Iot framework ServerSuperIO tutorial 1.4 communication modes and mechanisms.

Serialization | Iot framework ServerSuperIO tutorial 2. service instance configuration parameters

Serialization | Iot framework ServerSuperIO tutorial-3. Device Driver Introduction

Serialization | Iot framework ServerSuperIO tutorial-4. For example, you can develop a device driver that supports both serial and network communication.

Serialization | Iot framework ServerSuperIO tutorial-5. Polling communication mode development and precautions.

Serialization | Iot framework ServerSuperIO tutorial-6. concurrent communication mode development and precautions

Serialization | Iot framework ServerSuperIO tutorial-7. Self-control communication mode development and precautions

Serialization | Iot framework ServerSuperIO tutorial-8. single-instance communication mode development and precautions

Serialization | Iot framework ServerSuperIO tutorial-9. protocol filter to solve multiple packet-related, sticky packet, and redundant data

Serialization | Iot framework ServerSuperIO tutorial-10. Two Methods for continuous transmission of large data streams (such as files)

 

Contents

11. implement cascade control between devices (drivers) and devices (drivers)... 2

11.1 overview... 2

11.2 device linker... 2

11.3 scenario hypothesis... 3

11.4 device driver development and precautions... 3

11.5 host program service instance configuration considerations... 5

11.6 running effect... 6

11. Achieve cascade control between devices (drivers) and devices (drivers)
11.1 Overview

In Iot construction, data collection is the foundation and control is the purpose. These are two fundamental elements. When collecting device data, if the real-time data of the device is abnormal, is there any linkage between other devices? That is to say, when a device encounters an exception, it needs to perform linkage control on another device to avoid greater risks.

In this case, not only must a device be jointly controlled, but also the control results should be fed back to the abnormal device. An exception, linkage, control, and feedback closed loop is formed for the purpose of monitoring and control.

11.2 device linker

The Device Driver Interface of IRunDevice inherits the device linker interface of IDeviceConnector to enable two-way interaction between the device driver and the device driver, and realize data transmission and Command Control. The interface is defined as follows:

Public interface IDeviceConnector {// <summary> // sub-branch device connector /// </summary> /// <param name = "fromDevice"> sender of information transmission </param> /// <param name = "toDevice"> destination of information transmission, and the contained data information </param> /// <returns> </returns> object RunDeviceConnector (IFromDevice fromDevice, IDeviceToDevice toDevice ); /// <summary> // callback function of the device connector, write the callback processing result /// </summary> /// <param name = "obj"> </param> void DeviceConnectorCallback (object obj ); /// <summary> /// if the operator encounters an exception, returns the result of this function /// </summary> /// <param name = "ex"> </param> void DeviceConnectorCallbackError (Exception ex ); /// <summary> // connector event, initiator // </summary> event DeviceConnectorHandler DeviceConnector; /// <summary> /// interface for event confirmation /// </summary> /// <param name = "fromDevice"> </param> /// <param name = "toDevice"> </param> void OnDeviceConnector (IFromDevice fromDevice, IDeviceToDevice toDevice );}

Through the definition of this interface, we can know the starting end of information transmission triggered by the OnDeviceConnector event. It will pass the information to the rundeviceconneinterface function of the device driver of the receiving information end. After the rundeviceconnefunction is executed, the result data is returned to the DeviceConnectorCallback interface function of the sender device driver. If an exception occurs during the execution of RunDeviceConnector by the receiver device driver, the DeviceConnectorCallbackError interface function of the initiator device driver is called, the entire process has ended.

11.3 scenario hypothesis

The name of Device Driver No. 0 is Jin San, and that of Device Driver No. 1 is Putin. After Jin San learned about the Korean aunt Park event,Q: Why are you not finishing the class ?. Putin replied: Don't you think this is the real Korean drama? Silly boy. Jin san said: ao is really a fool!Complete information transfer throughout the process.

11.4 device driver development and precautions
Public override void Communicate (ServerSuperIO. communicate. IRequestInfo info) {byte [] cmds = this. protocol. getCommand (info. data); CommandArray cr = (CommandArray) cmds [0]; dynamic obj = this. protocol. driverAnalysis <byte []> (cr. toString (), info. data, info. bigData); if (obj! = Null) {if (cr = CommandArray. realTimeData) {_ deviceDyn. dyn = (Dyn) obj; OnDeviceRuningLog ("normal communication"); Console. writeLine (">>> simulate control command start"); this. onDeviceConnector (new FromDevice (this. deviceParameter. deviceID, this. deviceParameter. deviceCode, this. deviceParameter. deviceAddr, this. deviceParameter. deviceName), new DeviceToDevice ("1", this. deviceParameter. deviceName + "Q: Why are you not finishing school? ", Null, null ));}}}

2. After receiving the information, Putin parses the information and returns the meaning (result ). The Code is as follows:

Public override object RunDeviceConnector (IFromDevice fromDevice, IDeviceToDevice toDevice) {Console. WriteLine (toDevice. Text); // output data from other devices. Return this. DeviceParameter. DeviceName + "A: Do you think this is the real Korean drama? Kiddie ";}

3. After receiving the response from Putin, Jin San points the finger at o. The Code is as follows:

Public override void DeviceConnectorCallback (object obj) {Console. writeLine (obj. toString (); // outputs the returned result Console. writeLine (this. deviceParameter. deviceName + "said: ao is really good enough! "); Console. WriteLine (" >>> simulate control command end ");}

Note: DeviceConnectorCallbackError is not used to return the interface function when an exception occurs.

11.5 host program service instance configuration considerations

This is implemented in self-control mode, and the device driver does not actively send data. The Code is as follows:

Static void Main (string [] args) {DeviceSelfDriver dev1 = new DeviceSelfDriver (); dev1.DeviceParameter. deviceName = "golden 3"; dev1.DeviceParameter. deviceAddr = 0; dev1.DeviceParameter. deviceID = "0"; dev1.DeviceDynamic. deviceID = "0"; dev1.DeviceParameter. deviceCode = "0"; dev1.DeviceParameter. COM. port = 1; dev1.DeviceParameter. COM. baud = 9600; dev1.DeviceParameter. NET. remoteIP = "127.0.0.1"; dev1.DeviceParameter. NET. remotePort = 9600; dev1.CommunicateType = CommunicateType. NET; dev1.Initialize ("0"); DeviceSelfDriver dev2 = new DeviceSelfDriver (); dev2.DeviceParameter. deviceName = "Putin"; dev2.DeviceParameter. deviceAddr = 1; dev2.DeviceParameter. deviceID = "1"; dev2.DeviceDynamic. deviceID = "1"; dev2.DeviceParameter. deviceCode = "1"; dev2.DeviceParameter. NET. remoteIP = "127.0.0.1"; dev2.DeviceParameter. NET. remotePort = 9600; dev2.CommunicateType = CommunicateType. NET; dev2.Initialize ("1"); IServer server = new ServerManager (). createServer (new ServerConfig () {ServerName = "Service 1", ComReadTimeout = 1000, ComWriteTimeout = 1000, NetReceiveTimeout = 1000, NetSendTimeout = 1000, ControlMode = ControlMode. self, SocketMode = SocketMode. tcp, StartReceiveDataFliter = true, ClearSocketSession = false, StartCheckPackageLength = true, CheckSameSocketSession = false, DeliveryMode = DeliveryMode. deviceCode,}); server. addDeviceCompleted + = server_AddDeviceCompleted; server. deleteDeviceCompleted + = server_DeleteDeviceCompleted; server. start (); server. addDevice (dev1); server. addDevice (dev2); while ("exit" = Console. readLine () {server. stop ();}}
11.6 Running Effect

1. Images

1. [serialization] C # communication (Serial Port and network) Framework Design and Implementation

2. [Open Source] C # cross-platform Iot communication framework ServerSuperIO (SSIO) Introduction

2. Overall system construction solution using SuperIO and open-source cross-platform Iot framework ServerSuperIO

3. C # technical route of industrial IoT and integrated system solutions (data sources, data collection, data upload and receiving, ActiveMQ, Mongodb, WebApi, and mobile App)

5. ServerSuperIO Open Source Address: https://github.com/wxzz/ServerSuperIO

Internet of Things & integrated technology (. NET) QQ Group:54256083

Note: The latest original code has not been released yet. The tutorial is completed and updated synchronously.

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.