Iot framework ServerSuperIO (SSIO) updates and host programs and configuration tools are added.

Source: Internet
Author: User

Iot framework ServerSuperIO (SSIO) updates and host programs and configuration tools are added.

I. Update content

1. Modify * Server class and inheritance relationship.
2. added the IServerProvider interface inheritance of IRunDevice.
3. Fixed the possible exceptions caused by adding a COM device driver.
4. Fixed exceptions that may occur when data is sent over the network.
5. Complete the protocol driver.

6. Modify the protocol driver interface.
7. Modify the protocol command interface.
8. Fixed the exception BUG in the case of protocol commands and abstract basic classes.

9. added the Protocol Interface GetPackageLength to make data interaction more flexible.
10. Fixed some bugs.
11. Optimize the code.

Ii. Use of the GetPackageLength Interface

The main application scenario of this interface is: when the Protocol has a command for sending data length requests, for example, the command for sending data packet length to the server first, and then sending the actual data packet information after the return is determined. When connecting to send large data blocks, such as file content and serialized content, the content may contain the header and tail of the protocol, which may affect the integrity of the data packets. It is mainly used for interactive large continuous data block content.

1. Interface Parameters

/// <Summary> /// obtain the length of the data to be received. If the received data is smaller than the returned value, continue to receive the data until it is greater than or equal to the returned length. If the received data times out, the received data is directly returned. /// </Summary> /// <param name = "data"> received data </param> /// <param name = "channel"> IO channel, return confirmation data </param> /// <param name = "readTimeout"> return read data timeout interval </param> /// <returns> </returns> public abstract int GetPackageLength (byte [] data, IChannel channel, ref int readTimeout );

2. Interface Usage

(1) set configuration parameters

IServer server = new ServerFactory (). createServer (new ServerConfig () {ServerName = "Service 1", SocketMode = SocketMode. tcp, ControlMode = ControlMode. loop, CheckSameSocketSession = false, StartCheckPackageLength = true, // enable the detection packet length NetReceiveBufferSize = 20 ,});

(2) interface code

Public override int GetPackageLength (byte [] data, IChannel channel, ref int readTimeout) {if (data = null | data. length <= 0) return 0; readTimeout = 2000; if (CheckData (data) {try {int length = BitConverter. toInt32 (new byte [] {data [3], data [4], data [5], data [6]}, 0); byte [] okBytes = System. text. encoding. ASCII. getBytes ("OK"); int num = channel. write (okBytes); if (num> 0) {Console. writeLine ("returned data");} return length;} catch (Exception) {return 0 ;}} else {Console. writeLine ("verification error"); return 0 ;}}

3. Add the Host Program (ServerSuperIO. Host)

Static IServerFactory _ serverFactory = null; static void Main (string [] args) {Console. foregroundColor = ConsoleColor. green; ConsoleUtil. setConsoleCtrlHandler (new ConsoleUtil. controlCtrlDelegate (HandlerRoutine), true); bool success = true; Console. writeLine ("initializing the service program ...... "); IObjectBuilder builder = new TypeCreator (); _ serverFactory = new ServerFactory (); try {GlobalConfig gc = GlobalConfigTool. Load (); foreach (ServerSuperIO. config. server serverCfg in gc. servers) {IServer server = _ serverFactory. createServer (serverCfg. serverConfig); server. addDeviceCompleted + = server_AddDeviceCompleted; server. deleteDeviceCompleted + = server_DeleteDeviceCompleted; server. start (); _ serverFactory. addServer (server); foreach (Config. device devCfg in serverCfg. devices) {try {IRunDevice runDev = builder. bu IldUp <IRunDevice> (devCfg. assemblyFile, devCfg. instance); runDev. deviceParameter. deviceID = devCfg. deviceID; runDev. deviceDynamic. deviceID = devCfg. deviceID; runDev. communicateType = devCfg. communicateType; runDev. initialize (devCfg. deviceID); if (server. addDevice (runDev )! = DevCfg. DeviceID) {Console. WriteLine ("add device:" + devCfg. DeviceID + "failed! ") ;}} Catch (Exception ex) {Console. writeLine (ex. message); continue ;}}} catch (Exception ex) {success = false; Console. writeLine (ex. message);} if (success) {Console. writeLine ("service initialization completed");} while ("exit" = Console. readLine () {_ serverFactory. removeAllServer (); break;} private static bool HandlerRoutine (int ctrlType) {if (ctrlType = 0 | ctrlType = 2) {_ serverFactory. removeAllServer () ;}return false ;}}

4. Add a configuration Tool (ServerSuperIO. Tool)

1. Add services, such:


 

2. Add devices, such:


 

3. Click the tree menu to modify the configuration attributes.


 

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 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

 


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.