Serialization | Iot framework ServerSuperIO tutorial-15. Use of the data persistence interface. Appendix: Release and version update instructions ., Serversuperio

Source: Internet
Author: User
Tags influxdb

Serialization | Iot framework ServerSuperIO tutorial-15. Use of the data persistence interface. Appendix: Release and version update instructions ., 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)

Serialization | Iot framework ServerSuperIO tutorial-11. Implement device (driver) and device (driver) interaction and cascade control.

Serialization | Iot framework ServerSuperIO tutorial-12. Service Interface Development and bidirectional interaction with the cloud

Serialization | Iot framework ServerSuperIO tutorial-13. Custom View display interface development to meet different display requirements

Serialization | Iot framework ServerSuperIO tutorial-14. Introduction to preparation tools and mounting of device drivers, view drivers, and service instances

 

ServerSuperIO 3.2 update description:

1. added the IDataPersistence data persistence interface to store device parameters and real-time data in multiple forms. Currently, only Xml serialization is supported. Later, MongoDB, influxdb, and real-time databases (similar to PI) are supported.
2. added the r preparation parameters ComNullInterval and NetNullInterval. In polling mode, the interruption interval is when the serial port and network I/O channel are empty.

:Http://pan.baidu.com/s/1c1ZZLOO

Update description address: http://www.bmpj.net/thread-36-1-1.html

 

Contents

15. Use of the data persistence interface... 2

15.1 overview... 2

15.2 define the IDataPersistence data persistence interface... 2

15.3 use the IDataPersistence data persistence interface... 5

15. Use of the data persistence Interface  
15.1 Overview

Before ServerSuperIO 3.2, device data only supports Xml serialization. If you store data in other ways, you can only write persistent operations in the device driver, which in essence loses the modular flexibility. The data persistence interface is added later than version 3.2 to facilitate the storage of device parameter data and real-time data in multiple forms. version 3.2 only supports Xml serialization, later support for MongoDB, influxdb, and real-time databases (similar to PI)

15.2 define the IDataPersistence data persistence Interface

1.Interface Definition

Any data storage method can inherit the IDataPersistence interface. The specific code is as follows:

public interface IDataPersistence
    {
        /// <summary>
        /// connect data source
        /// </ summary>
        void Connect ();

        /// <summary>
        /// select data object
        /// </ summary>
        /// <param name = "devid"> </ param>
        /// <param name = "objType"> </ param>
        /// <returns> </ returns>
        object Select (string devid, Type objType);

        /// <summary>
        /// insert data object
        /// </ summary>
        /// <param name = "devid"> </ param>
        /// <param name = "obj"> </ param>
        void Insert (string devid, object obj);

        /// <summary>
        /// update data object
        /// </ summary>
        /// <param name = "devid"> </ param>
        /// <param name = "obj"> </ param>
        void Update (string devid, object obj);

        /// <summary>
        /// delete the data object
        /// </ summary>
        /// <param name = "devid"> </ param>
        /// <param name = "obj"> </ param>
        void Delete (string devid, object obj);
 
        /// <summary>
        /// determine if it exists
        /// </ summary>
        /// <param name = "devid"> </ param>
        /// <param name = "obj"> </ param>
        /// <returns> </ returns>
        bool Exist (string devid, object obj);
}

2.Interface implementation form

 If you use MongoDB, influxdb, and real-time databases, You can inherit the IDataPersistence interface. The following uses Xml to store data as an example. The Code is as follows:


public class XmlPersistence:IXmlPersistence
    {
        public void Connect()
        {}

        public object Select(string devid, Type objType)
        {
            string path = GetSavePath(devid,objType);
            return SerializeUtil.XmlDeserailize(path, objType);
        }

        public void Insert(string devid, object obj)
        {
            string path = GetSavePath(devid,obj.GetType());
            SerializeUtil.XmlSerialize(path, obj);
        }

        public void Update(string devid, object obj)
        {
            this.Insert(devid, obj);
        }

        public void Delete(string devid,object obj)
        {
            string path = GetSavePath(devid,obj.GetType());
            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }
        }

        public bool Exist(string devid, object obj)
        {
            string path = GetSavePath(devid, obj.GetType());
            return System.IO.File.Exists(path);
        }
        ......
    }
15.3 use the IDataPersistence data persistence Interface

The device driver developed by the ServerSuperIO framework involves two types of data: device parameters and real-time data. Both types of data correspond to the base classes: DeviceParameter and DeviceDynamic. Each device driver may correspond to different device parameters (coefficients, etc.) and real-time data (temperature, humidity, traffic, etc.) because different hardware devices and sensors are involved. You can inherit two base classes: DeviceParameter and DeviceDynamic. Both of these base classes have the InitDataPersistence (IDataPersistence dataPersistence) interface to implement different persistent data storage interfaces and perform Save, Load, and Delete operations.

The specific definition method is as follows:

public class DeviceDyn:DeviceDynamic
{
        public DeviceDyn() : base()
        {
             this.InitDataPersistence(new XmlPersistence());
        }

        public override string GetAlertState()
        {
            throw new NotImplementedException("No alarm message");
        }

        public float Flow{set;get;} }

Use the following code:

DeviceDyn dyn = new DeviceDyn ();
  dyn.Save (); // Save
  dyn.Load (); // add
  dyn.Delete (); /// Delete

Note: this. InitDataPersistence () does not perform this operation. By default, XmlPersistence is used for data persistence.

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.