In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "the secondary development and application example analysis of C#". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "the secondary development and application example analysis of C#"!
Secondary development and application
Supporting secondary development is an important feature of the framework, and it is an honor to be a designer or architect to make your work widely used. No matter how many projects I have done, it is not easy to have my own representative work, and it is also very fortunate to be able to make a wide range of friends through a work. Therefore, efforts have been made to make SuperIO more stable, better support secondary development, and faster to build a communication platform.
This part mainly introduces the secondary development using SuperIO. The development process is shown below:
12.1 Project configuration
1) Select Framework4.0 for the target framework
2) the target platform generated is x86.
X86 is the target platform for all case programs. It mainly considers the compatibility of 32-bit operating system and 64 operating system.
12.2 reference related components
Reference related components in the Development package. As shown below:
12.3 build the main program
You can build your own host program by inheriting the SuperIO.UI.MainForm forms class, which is just a basic interface framework that can be extended on this basis. The built host program is shown below:
12.4 Development of device drivers 12.4.1 assumes that the communication protocol 12.4.1.1 sends and reads real-time data command protocol
The computer sends 0x61 instructions to read real-time data commands, sending a total of 6 bytes, and the checksum is the sum starting from the "slave address", excluding "Datagram header", "checksum" and "protocol end".
Send instruction data frames as follows:
Frame structure
Data header
Slave address
Instruction code
Checksum
The agreement ends.
0x55
0xAA
0x61
0x0D
Number of bytes
one
one
one
one
one
one
12.4.1.2 parsing Real-time data Protocol
After receiving the command to read real-time data, the lower computer successfully verifies and returns real-time data. The checksum is the cumulative sum starting from the "slave address", excluding "Datagram", "checksum" and "protocol end".
The received data frames are as follows:
Frame structure
Data header
Slave address
Instruction code
Flow
Signal
Checksum
The agreement ends.
0x55
0xAA
0x61
Floating point type
Floating point type
0x0D
Number of bytes
one
one
one
one
four
four
one
one
12.4.1.3 send and receive data cases
Send (hexadecimal): 0x55 0xaa 0x00 0x61 0x61 0x0d
Receive (hexadecimal): 0x55 0xaa 0x00 0x61 0x43 0x7a 0x00 0x00 0x43 0xb4 0x15 0x0d
Traffic data: 250.00
Signal data: 360.00
12.4.2 New equipment Modul
As shown below:
Add a reference to SuperIO.dll, as shown below:
12.4.3 build Protocol driver
Create two new classes: MySendProtocol and MyReceiveProtocol,MySendProtocol inherit the SuperIO.Device.DeviceSendProtocol base class, and the MyReceiveProtocol class inherits SCL.Device.DeviceReceiveProtocol.
Both MySendProtocol and MyReceiveProtocol classes are overridden (override)
The "Function61" function, the Function61 function in the MySendProtocol class completes the operation of packaging and sending commands, the Function61 function in the MyReceiveProtocol class completes the operation of parsing the data, and the FunctionXX appears in pairs in both classes, mainly for easy to remember.
You can call the DriverFunction function in the MySendProtocol instance, passing in the appropriate command, such as 0x61. The "Function61" function is automatically called as the driver interface for calling the corresponding command function. The GetSendCmdBytes function interface is encapsulated on the basis of the DriverFunction function and can also be used, but the "isbox" must be set to false, otherwise the data sent will be specially handled.
You can call the DriverFunction function in the MyReceiveProtocol instance, passing in the appropriate command, such as 0x61. The "Function61" function is automatically called as the driver interface for calling the corresponding command function. The GetAnalysisData function is encapsulated on the basis of the DriverFunction function and can also be used, but an extra layer of GetCommand function interface is called.
For more information on the code, please see DeviceDemo Project.
12.4.4 build parameter and real-time data instance classes
Two new classes are created: MyDeviceParameter and MyDeviceRTDataMyDeviceParameter inherit the SuperIO.Device.DeviceParameter class, which is used to save standby parameters, and new device parameters can be added to this class.
MyDeviceRTData inherits the SuperIO.Device.DeviceRealTimeData class, which is used to save the real-time data of the device, and can customize the real-time data of the device according to the communication protocol.
After inheriting the base class, these two classes automatically inherit the two generic functions SaveSerialize and GetSerialize. The SaveSerialize function serializes the current object into XML,GetSerialize and inverts the serialized XML to generate the object instance. The SuperIO.Device.DeviceParameter class and the SuperIO.Device.DeviceRealTimeData class inherit from the SerializeOperation class, and their interface is IserializeOperation,SerializeOperation, which is just a simple library of serialized XML operations.
If the developer wants to completely customize a data persistence file, he can inherit the IserializeOperation interface, rewrite the corresponding interface function, and customize the way to store the data.
12.4.5 Building device drivers
The sections "build Protocol driver" and "build parameters and Real-time data instance classes" are both preparations for building the running device and will be used as properties of the running device.
Create a new device class: MyDevice, which inherits from SuperIO.Device. RunDevice1 .
The developer noticed that there is also a SuperIO.Device. RunDevice class, which is an early running device class, considering platform compatibility, is still in inheritance, but the newly developed device model is not recommended to use SuperIO.Device. The RunDevice1 class. They all inherit from the IRunDevice interface.
12.5 Development of graphic display
Add references to SuperIO components.
Create a new Form form, inherit the SuperIO.Show.IGraphicsShow interface, and implement the interface function.
Parse the object through the UpdateDevice interface, and display the data after parsing the object.
12.6 Development of data export
Add references to SuperIO components.
Create a new class, inherit the SuperIO.Export.IExportData interface, and implement the interface function.
Parse the object through the UpdateDevice interface and output the formatted data.
12.7 Development of service components
Add references to SuperIO components.
Create a new class, inherit the SuperIO.Services.AppService abstract class, and implement interface functionality.
The cached data of the device can be updated through the UpdateDevice interface function.
12.8 Application of configuration tool
Manually modify the configuration file of the framework platform, the configuration information is not easy to understand, but also easy to affect the format of the configuration file, so I wrote a configuration tool "ConfigTool.exe" to mount and delete the global parameters and driver information of the framework platform.
12.8.1 Parameter configuration
Parameter configuration mainly involves: software information, installation operation, network and serial communication and other information. The configuration is shown below.
12.8.2 driver mount
The configuration tool can also mount drivers and plug-ins. Once configured, the launch framework platform can operate on them, such as the following figure, to mount device drivers:
At this point, I believe you have a deeper understanding of the "secondary development and application example analysis of C#". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.