21.1 Overview
Serversuperio's previous work has gradually laid the groundwork for the formation of loop control or cascade control, for example: the development and application of service connectors and device-driven connectors. In short, it is through various forms of Command control equipment (drive) or sensors, cloud control site or monitoring point sensor, app or other terminal control sensor, according to the sensor data acquisition control another sensor.
Here's how cloud, app, or other terminals control sensor devices (sensor control sensors are similar, see: 12. Service interface development, and bi-directional interaction with the cloud). According to the communication protocol, the structure of the scheme, do not need too much code to complete the corresponding functions. Effects such as:
21.2 structure
The control terminal initiates the control command, develops a simple proxy service with the Serversuperio service interface, interacts with the device driver through the Service connector Iserviceconnector interface, and the device driver receives the control command and sends it to the device or sensor, waiting for the confirmation message returned by the control. Return the original path to the control side.
21.3 Communication Protocols
Someone asked why the MQTT protocol is not used, and how is the protocol compatible with different devices and sensors? In the reality of China, it is clear that the level of uniform standards can not be achieved, in the case of poor economy, enterprises can not invest in replacing the original hardware equipment. Also does not conform to the principle of Serversuperio design, is to engage in protocol independence, any standard or non-standard protocol can be integrated. If you want to cross a river, fix the bridge, set up the Ropeway, and put the boat in place ... It's up to you to decide how to cross the river.
Someone asked Serversuperio what protocols were integrated? The answer is given above, and I want to say that no framework can cure all ills. From the opposite point of view, if the same as the configuration of any protocol are added, the enterprise would like to take out how much value to the reciprocal exchange, so the agreement to drive or give you to write it yourself.
The protocols we demonstrate are as follows:
21.4 Control Side
The control side includes many kinds: The cloud sends the control command to the subordinate, the app or the PC Software Connection service sends the control command and so on. Send control commands such as:
21.5 Proxy Service (Ssio service interface)
The proxy service is implemented through the Serversuperio IService interface, which uses the singleton pattern of the Serversuperio framework itself in the inheriting class to develop the proxy service, with the following code:
public override void StartService () {String devId = "Controldeviceservice"; Driver dev = new Driver (); Dev. Receiverequestinfos + = Dev_receiverequestinfos; Dev. Deviceparameter.devicename = "Control device driver"; Dev. deviceparameter.deviceaddr = 0; Dev. Deviceparameter.deviceid = devId; Dev. Deviceparameter.devicecode = ""; Dev. Devicedynamic.deviceid = devId; Dev.DeviceParameter.NET.RemoteIP = "127.0.0.1"; Dev.DeviceParameter.NET.RemotePort = 9600; Dev.DeviceParameter.NET.ControllerGroup = "localgroup"; Dev.communicatetype = communicatetype.net; Dev. Initialize (DEVID); IServer Server = new Servermanager (). Createserver (New Serverconfig () {ServerName = "control device Service", listenport=6670, Comreadtimeout = Comwritetimeout = +, netreceivetimeout = 1000, Netsendtimeout = Controlmode = Controlmode.singleton, Socketmode = socketmode.tc P, Startreceivedatafliter = False, Clearsocketsession = False, Startcheckpack Agelength = False, Checksamesocketsession = False,}); Server. adddevicecompleted + = server_adddevicecompleted; Server. deletedevicecompleted + = server_deletedevicecompleted; Server. socketconnected + = server_socketconnected; Server. socketclosed + = server_socketclosed; Server. Start (); Server. AddDevice (Dev); }
Dev. The Receiverequestinfos event is a control-driven event interface that inherits the Rundevice driver class extension in the Serversuperio framework, and the Serversuperio Singleton mode receives the data information. The Receiverequestinfos event passes the data information to the DEV_RECEIVEREQUESTINFOS function that the Proxy service subscribes to the event, if the compliance protocol standard will feed the data back to the driver's communicate interface. Code such as:
The Dev_receiverequestinfos function in the Proxy service, through the Service Connector interface Iserviceconnector, transmits the information to the appropriate device driver according to Devicecode (addr). Code such as:
The proxy service receives the result information of the device driver feedback through the Serviceconnectorcallback and Serviceconnectorcallbackerror function interfaces, If an exception occurs in the middle, the serviceconnectorcallbackerror is called, and if the Serviceconnectorcallback function is called normally, The Serviceconnectorcallback function interface is based on the corresponding relationship between the recorded command and the IO channel, and sends the result to the control side. Serviceconnectorcallback code such as:
Here there is a note that the device driver does not have the feedback control command confirmation information in the specified time, that is, the sensor does not have the feedback corresponding information. In this case, a timer detection service is added, and if there is no feedback message, it is sent to the control side for the corresponding message. Code such as:
21.6 device drivers
This device drives the sensor counterpart, interacting with each other over the data. The device-driven Runserviceconnector interface is responsible for receiving command information passed by the Proxy service Dev_receiverequestinfos (onserviceconnector) function. Code such as:
There are two points: 1. After receiving the command data, the Onsenddata function can send the data information immediately, and find the corresponding IO channel with the IP set, which is suitable for automatic control mode. 2. After receiving the command data, place it in this. In the Protocol.sendcache protocol cache, wait for the command to be issued for polling, concurrency mode.
The Isasyn parameter for the returned result object Serviceconnectorcallbackresult, if true, indicates that the result information is returned through Asyncserviceconnectorcallback callback, That is to wait for the sensor to return confirmation information, and the device driver receives and then feedback to the proxy service, if False, the description will immediately feedback to the Proxy service, applicable to the delivery of data information regardless of the interaction with the sensor is successful.
You can temporarily save the callback parameter in this function, waiting for the sensor to return the acknowledgement message and trigger the asynchronous callback to the proxy service in the communicate function. Code such as:
21.7 Demo Description
Open two Testdevice programs, one as a device sensor, one as the control end, Devicecode to be, Testdevicedriver is the device driver, loaded in the service instance, I use the self-control mode, using Testselfmain project The Controldeviceservice is a proxy service that is loaded in Testselfmain. See Engineering code for details:.
Note: The future of our big data platform, can also be issued by this mode control command to the site.
1.[serial] "C # communication (Serial and network) framework design and implementation"
2.[Open source]c# cross-platform IoT communication Framework Serversuperio (Ssio) Introduction
2. Superio (SIO) and open-source cross-platform IoT framework Serversuperio (SSIO) building a system's overall solution
3.c# Technology Roadmap for industrial IoT and Integrated system solutions (data source, data acquisition, upload and receive, ActiveMQ, Mongodb, WEBAPI, mobile app)
5.ServerSuperIO Open Source Address:
Internet of Things & Integration technology (. NET) QQ Group:54256083
Download Address:
1.c# Cross-platform IoT communication Framework Serversuperio (Ssio) Introduction
The serial | Internet of Things Framework Serversuperio Tutorial 1.4 Communication mode mechanism.
The serial | Internet of Things framework Serversuperio Tutorial 2. Configuration parameter description of the service instance
The serial | Internet of Things Framework Serversuperio Tutorial-3. Introduction to Device drivers
The serial | IoT Framework Serversuperio Tutorial-4. Develop a set of device drivers that support both serial and network communication.
The serial | Internet of Things Framework Serversuperio Tutorial-5. Polling communication mode development and considerations.
The serial | Internet of Things Framework Serversuperio Tutorial-6. Development of concurrent communication mode and matters needing attention
The serial | IoT Framework Serversuperio Tutorial-7. Self-control communication mode development and matters needing attention
The serial | IoT Framework Serversuperio Tutorial-8. Development of single-case communication mode and matters needing attention
The serial | Internet of Things Framework Serversuperio Tutorial-9. Protocol filter to solve a packet of multi-hair, sticky packets, redundant data
The serial | IoT Framework Serversuperio Tutorial-10. Two ways to continuously stream large chunks of data (e.g. files)
The serial | IoT Framework Serversuperio Tutorial-11. Implement device (drive) and device (driver) interaction and cascade control.
The serial | IoT Framework Serversuperio Tutorial-12. Service Interface development and bi-directional interaction with the cloud
The serial | Internet of Things Framework Serversuperio Tutorial-13. Custom view display interface development to meet different display requirements
The serial | Internet of Things Framework Serversuperio Tutorial-14. Description of the compounding tool, as well as device drivers, view drivers, and service instance mounts
The serial | Internet of Things Framework Serversuperio Tutorial-15. Use of the data persistence interface
The serial | Internet of Things Framework Serversuperio Tutorial-16.OPC Server usage steps
The serial | IoT Framework Serversuperio Tutorial-17. Support Real-time database, high concurrency to save survey point data
The serial | Internet of Things Framework Serversuperio Tutorial-18. Integrated OPC Client, and use steps
The serial | IoT Framework Serversuperio Tutorial-19. Device Driver and OPC client support for the persistence of MySQL, Oracle, sqlite, SQL Server
"IoT Framework Serversuperio Tutorial"-20. Network communication controller grouping to improve the load balancing capability of the interaction. v3.6.6 version released