Open-source cross-platform IOT communication framework ServerSuperIO, integrated into the NuGet Package Manager, and Demo instructions, iotnuget

Source: Internet
Author: User

Open-source cross-platform IOT communication framework ServerSuperIO, integrated into the NuGet Package Manager, and Demo instructions, iotnuget

Iot involves various devices, sensors, various data sources, and protocols, and it is difficult to unify these Protocols. Therefore, a structural framework is required to solve these problems. SSIO is a combination of the development stages of the times and the actual situation.

Various data information, such:

Solution, used in combination with SiO2:

I. SSIO features

  • The lightweight and high-performance communication framework is suitable for multiple application scenarios, including polling mode, automatic control mode, concurrency mode, and Singleton mode.
  • It is not only a communication framework, but also a coordination mechanism for device drivers, IO channels, and control mode scenarios.
  • Supports protocol drives and standard and custom protocols can be written according to specifications.
  • Supports sending data caches, command cache resends, and priority-based sending.
  • Supports protocol filters, filters data by rules, and supports custom filtering through interfaces.
  • Supports receiving data caches to cache data that does not match the filter and splice the data received next time.
  • Allows you to schedule devices by device command priority to ensure that drivers with advanced commands are sent in a timely manner.
  • Supports one device driver, and supports both the serial port and network communication modes to monitor IO channel data.
  • Supports one device driver and TCP Server and TCP Client for network communication.
  • Multiple devices can share the same I/O channel for communication.
  • Supports timed cleanup of time-out network I/O channels.
  • The display view interface is supported to meet different display requirements.
  • Supports service component interfaces to customize the OPC Service, 4-20mA output, LED dashboard display, SMS service, and multi-function gateway service.
  • You can create multiple service instances to split different services.
  • Supports cross-platform deployment and runs on Linux and Windows systems.

Ii. SSIO released to the NuGet Platform

Iii. Search for SSIO

4. Install SSIO

V. Demo)

Demo: https://github.com/wxzz/ServerSuperIO/tree/2.0

1. Client (Send File)

 

Static void SendFile () {if (! System. IO. file. exists (_ file) {Console. writeLine ("the file does not exist:" + _ file); return;} FileStream fs = null; try {Console. writeLine ("Start Transmission>"); string fileName = DateTime. now. toString ("yyMMddHHmmss") + ". txt "; int bufferSize = _ sendBufferSize; byte [] sendBuffer = new byte [bufferSize]; fs = new FileStream (_ file, FileMode. open, FileAccess. read, FileShare. read); long length = fs. length; int count = 0; Stopwatch wat Ch = new Stopwatch (); watch. start (); while (length> 0) {int sendNum = fs. read (sendBuffer, 0, sendBuffer. length); byte [] package = GetDataPackage (fileName, sendBuffer, sendNum); count + = _ tcpClient. client. send (package, 0, package. length, SocketFlags. none); length-= sendNum; float percent = (fs. length-length)/(float) fs. length) * 100366f; Console. writeLine ("passed:" + percent. toString ("0.00") + "% ");} Watch. Stop (); Console. WriteLine ("transfer completed! Total: "+ count. toString () + ", time consumed:" + watch. elapsed. totalSeconds. toString (CultureInfo. invariantCulture);} catch {throw;} finally {if (fs! = Null) {fs. close (); fs. dispose () ;}} static byte [] GetDataPackage (string fileName, byte [] sendBuffer, int sendNum) {byte [] sendPackage = new byte [sendNum + 24]; sendPackage [0] = 0x35; sendPackage [1] = 0x35; string code = "0001"; byte [] codeBytes = System. text. encoding. ASCII. getBytes (code); Buffer. blockCopy (codeBytes, 0, sendPackage, 2, 4); byte [] fileBytes = System. text. encoding. ASCII. getBytes (fileName); Buffer. blockCopy (fileBytes, 0, sendPackage, 6, 16); Buffer. blockCopy (sendBuffer, 0, sendPackage, 22, sendNum); sendPackage [sendPackage. length-2] = 0x33; sendPackage [sendPackage. length-1] = 0x33; return sendPackage ;}

 

2. Device Drivers

// Device Driver public class ReceiveFileDriver: RunDevice {private Dynamic _ Dyn; private Parameter _ Parameter; private Protocol _ Protocol; public ReceiveFileDriver (): base () {_ Dyn = new Dynamic (); _ Parameter = new Parameter (); _ Protocol = new Protocol ();} public override void Initialize (int devid) {this. protocol. initDriver (this, new FixedHeadAndEndReceiveFliter (TransFileDriver. protocol. head, TransFileDr Iver. protocol. end); // initialize the protocol driver} // omitting ......} // protocol-driven, and data processing public class Command: ProtocolCommand {public Command () {} public override string Name {get {return "writefile ";}} public override object Analysis (byte [] data, object obj) {try {// count + = data. length-24; // Console. writeLine (count. toString () + "," + data [0]. toString () + "," + data [data. length-1]. toString (); string path = Path. combine (Environment. CurrentDirectory, "rev"); if (! System. IO. directory. exists (path) {System. IO. directory. createDirectory (path);} string fileName = System. text. encoding. ASCII. getString (data, 6, 16); path = Path. combine (path, fileName); using (FileStream fs = new FileStream (path, FileMode. openOrCreate, FileAccess. write, FileShare. write) {fs. seek (fs. length, SeekOrigin. current); byte [] content = new byte [data. length-24]; Buffer. blockCopy (data, 22, content, 0, content. length); fs. write (content, 0, content. length); fs. flush () ;}} catch {return-1;} return 0;} public override byte [] Package (string code, object obj) {throw new NotImplementedException ();}}

3. Host Program

Static void Main (string [] args) {ReceiveFileDriver dev = new ReceiveFileDriver (); dev. deviceParameter. deviceName = "Device 4"; dev. deviceParameter. deviceAddr = 0; dev. deviceParameter. ergonomic code = "0001"; dev. deviceParameter. deviceID = 0; dev. deviceDynamic. deviceID = 0; dev. deviceParameter. NET. remoteIP = "127.0.0.1"; dev. deviceParameter. NET. remotePort = 9600; dev. communicateType = CommunicateType. NET; dev. initialize (0); IServer server = new ServerFactory (). createServer (new ServerConfig () {ServerName = "receive file service", ListenPort = 6699, NetReceiveBufferSize = 2048, ControlMode = ControlMode. self, SocketMode = SocketMode. tcp, DeliveryMode = DeliveryMode. deviceCode, StartReceiveDataFliter = true, ClearSocketSession = false,}); server. addDeviceCompleted + = server_AddDeviceCompleted; server. deleteDeviceCompleted + = server_DeleteDeviceCompleted; server. start (); server. addDevice (dev); while ("exit" = Console. readLine () {server. stop ();}}

Vi. Experiment results

 

In the past two days, nearly 3 GB of data is provided, which provides excellent stability and scalability.

 

 

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

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.