Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the knowledge points of C# communication framework

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what are the knowledge points of the C# communication framework". In the daily operation, I believe that many people have doubts about the knowledge points of the C# communication framework. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions about "what are the knowledge points of C# communication framework?" Next, please follow the editor to study!

1.1 the nature of communication

Communication is the transmission of information, which is divided into one-way information transmission and two-way information transmission. Broadcasting with a loudspeaker is an one-way message transmission, and a phone call is a two-way message transmission.

One-way information transmission is relatively simple, only need to send data to the information receiver in real time, regardless of whether the information arrives or not, and whether it is processed after arrival. This information transmission method is suitable for application scenarios that do not require high data integrity, such as collecting data from temperature sensors. However, if there are more data sources or sensors, the concurrency problem should be taken into account. With the development of Internet technology, the concurrency problem can be well solved.

Two-way information transmission is relatively complex, which involves not only the problem of sending data, but also a series of interactive problems such as information handshake, data supplementary transmission and so on. If the two-way information transmission must be divided into the client and the server, it also involves which party initiates the information transmission, the client actively sends data to the server, and the server receives the data and then processes it; however, sometimes the server does not want to receive the data from the client, and the client can return the corresponding data according to the command only after the server sends the request command to the client. In the two-way communication with the hardware, it also involves the problem that the carrier channel is half-duplex and full-duplex, half-duplex can only send data from A to B or B to An at the same time, and only one-way data transmission; full-duplex is that A sends data to B, while B can also send data to A, and sending and receiving data can be carried out simultaneously. This kind of information transmission method is suitable for application scenarios that require high data completeness.

Whether it is one-way information transmission or two-way information transmission, it involves transmission protocol, coding mode and data verification. Transport protocol is a data format that can be encapsulated and parsed and can understand each other. It is a way of data specification, which can use standard protocols, such as Modbus, XMPP, AMQP, MQTT, etc., and can also use custom protocols. With the transport protocol, encoding methods are also involved in the transmission process, such as GBK, UTF, ASCII, which may also be encrypted on the basis of coding to ensure the security of the data. For the sake of the completeness and parsability of the data packet, but also to increase the check of the data, generally use more check method for CRC. The purpose of transmission protocol, coding and data verification is only one: to prevent data from being interfered with or maliciously tampered with in the process of transmission, resulting in unexpected consequences for data processing. To make an analogy, if a Chinese speaks Putonghua and a foreigner speaks American English, the grammar is different and the coding format is different, resulting in incomprehension of words and words. If he is mistaken for swearing, he may even have a fight.

Now basically is the object-oriented development mode, new out an object, after the attribute of the object is assigned, the object is directly passed to the interface function to send data. This mode of operation makes developers pay more attention to the business level, thus masking a lot of technical details, such as serialization, protocol, coding, byte stream operation and so on.

However, SuperIO maintains the operation of the underlying byte stream (byte []) and pays more attention to communication framework, data protocol, data cache, data processing flow, device driver, plug-in, secondary development and so on. Because in the era of the Internet of things, we will face many data sources, including various sensors, mobile phones, PC, smart hardware, traditional embedded devices and so on. There are many protocols and it is difficult to unify, so the most direct operation data is byte stream (byte []). In addition, the transmission technology was underdeveloped (300 baud rate) a long time ago, and it was limited by the storage of registers. in order to reduce the amount of data, 8 bits of 1 byte should represent 8 state types.

In the era of the Internet of things, we will face a variety of communication situations, such as: a serial channel, one-to-one, one-to-many communication; a network IP channel, one-to-one, one-to-many communication. Therefore, it is impossible to meet the requirements of versatility without a good framework support.

Some people ask how to do serial communication and network communication, it is easy for some people to answer these questions, but if the above and other problems are considered carefully, it is a complex problem, and some problems are not easy to solve.

1.2 introduction to the Framework

If a company has a large number of hardware products and different protocols, each hardware product corresponds to a set of host computer software, which needs to be maintained by special personnel. The changing needs of customers result in high maintenance costs and hinder the rapid development of the company. In addition, even if you modify the supporting software of similar hardware products, it may lead to the emergence of a new BUG.

With the needs of the development of the market and companies, it is necessary to integrate and reconstruct the software system to adapt to the changing environment and hardware, reduce manpower, operation and maintenance costs, and release labor.

Therefore, for the development to a certain stage, or a mature company must have a software framework as a support, which is from a business point of view to consider the inevitability of the development of application framework.

Technically, a framework is a reusable design of all or part of a system, usually consisting of a set of interfaces, abstract classes, and collaboration between classes. With the development of information technology, the development of software products is becoming more and more complex, and the complexity of solving problems is also increasing. The IT community is also looking for a variety of methods, including the formulation of various software development standards and specifications, the development of higher-level and more productive programming languages, the development of better compilers and runtimes and interpretive development languages that do not require compilation, the development of powerful and more universal component libraries, and the exploration of design patterns suitable for different application scenarios.

From the point of view of software engineering, we should adopt unique software architecture and design patterns at the design level to achieve our desired goals:

N try to improve the reusability of the software and avoid unnecessary repetitive coding work.

N increase the encapsulation of the assembly.

N improve the degree of modularization of the software.

N different functional modules can be seamlessly integrated.

N software has flexible expansibility.

N the expansion and development of software products are standardized.

N Software products have adaptability and portability for different application levels.

In order to achieve these requirements, at the design level, more and more software products begin to adopt the idea of application framework to design software structure. Application framework has been a widely used term, and it has become a very practical and commonly used design and development specification in software development.

We must have seen a lot of software products that call themselves "frameworks". Some people may feel disdainful that some programs with very little code even call themselves some form of application framework. In fact, the application framework is not about size, just like houses, skyscrapers and houses are houses, but they are different in size and dexterity.

In the eyes of the architect, the code needs to be designed and has a framework.

1.3 solve practical problems

In the industrial field, we often encounter the data interaction between software and hardware, and face a complex field environment:

(1) complex and diverse communication protocols. There are standard protocols, such as Modbus, etc., and there are also many protocol formats modified according to standard protocols, as well as custom protocol formats, which vary widely. For bad software architecture, struggling to deal with, adding devices or protocols to sort out the whole software, new problems or BUG often arise in the process.

(2) according to the different users' requirements for the software interface or function, the data display interface can be customized to meet the display requirements of different users.

(3) the diversity of input and output data when doing an integration project. First of all, it is necessary to integrate the equipment of other manufacturers and require data access. Secondly, there are many other manufacturers to integrate their own home equipment, involving the issue of output data, data format requirements are also very different.

(4) due to the variety of communication links, it may be necessary to support RS232/RS485/RS422, RJ45, 3G/4G and other communication modes for the same device, so for a device to correspond to multiple communication modes (serial port and network), it also causes great obstacles to our development.

(5) the compatibility between the software versions and the software and hardware is very poor, and the management is complicated.

In order to solve the above problems, a software framework is developed to support secondary development. Without changing the software framework, it can easily access the equipment, maintain the equipment, integrate the equipment, process the business data of the equipment and so on. The software framework is relatively stable and the parts that are easy to change are designed flexibly.

1.4 Application scenario

As a framework platform, it is necessary to locate its application scene after the formation of the product, have a clear understanding before designing the framework, and constantly strengthen the application goal in the design process.

In the aspect of product application, the framework platform may be deployed on PC, interact with many hardware and sensors, and store data locally.

In the aspect of project application, the framework platform may be deployed on the server side to exchange data with the client (PC, hardware, sensor, etc.) and store it in the data.

Since the framework platform can be used on both PC and server, there is also the possibility of data exchange between the framework and the framework.

Therefore, the interaction scene of the framework platform includes two aspects: first, interact with hardware products. Second, interact with software products. Basically, these two aspects are considered:

1) the framework platform is applied on PC.

Mainly used in the industrial control computer of automatic station, by means of RS485/RS232, RJ45, 4-20mA and so on.

Collect the data information of the hardware equipment. At the same time, the communication platform interacts with the software on the server side, and is responsible for uploading data and receiving control commands.

2) the framework platform is applied on the server side.

The terminal equipment is connected with the communication platform by 3G/4G, cable private network, satellite, etc., and carries on the data exchange.

The terminal equipment includes PC, mobile terminal (mobile phone), monitoring equipment and sensor, etc.

Based on the above considerations, the application scenario structure diagram of the framework platform is as follows:

1.5 Application characteristics of the framework

For the characteristics of the framework, we should have a simple and clear planning, including: functional level, performance level, application level, operational level, secondary development level and so on, which will strengthen our goals in the design and development process. These should be written not only on paper, but also in mind. When designing, SuperIO simply listed its features, although some of them were later improved, as follows:

N quickly construct the host program of communication data acquisition platform software

N quickly build device drivers, and related protocol drivers, command buffers, custom parameters and real-time data properties, etc.

N Rapid secondary development of graphic display, data output, service-driven, and mounted in the form of plug-ins.

N A device driver that supports both serial port (COM) and network (TCP Server/Tcp Client) communication mechanisms, and can be switched freely.

N built-in protocol driver, the third-party protocol can be converted into a custom protocol, the essence of the protocol is the operation of byte flow.

N built-in device command buffer, you can set the priority of the command to ensure the fast response of the command.

N redevelop OPC service, 4-20mA output, LED large screen display, short message service and so on in the way of service-driven plug-in.

N rapid development, stable operation and strong expansibility

N is suitable for industrial host computer software and collecting remote equipment data in system integration.

N support for Windows XP/7/8/8.1, Windows Server 2003 Universe 2008 and Universe 2012

1.6 frame design features

Some books talk about a lot of design features, a little confusing, do not see a sense of hierarchy, I think the most important features of this kind of framework include two points: stability, scalability, and performance.

Stability.

For a real-time data acquisition framework, the primary design feature is stability, which is the premise of all other features. There can be no phenomenon that the software can exit after an exception, the process can not exit after shutting down the software, the phenomenon of unable to respond to data, the phenomenon of unable to process data, and so on.

Based on these potential problems, we should consider: fault tolerance mechanism, module seamless docking, logging and so on.

Fault-tolerant mechanism is a mechanism that all software has, and the core idea is how to deal with abnormal state. For the general function of operation, if there is an abnormal state, we may not need too much intervention, we only need to log, and the repeatability of the abnormal state can be verified by operating the same function again. According to the log information, it can be solved pertinently. For transactional tasks, there are many options for handling the exception state. You can simply record the exception information, destroy the current resources, restart the task, directly succeed the task, and restore the node to the abnormal state. According to different scenarios, the way to choose the processing is also different. It means that if someone says something wrong, it depends on the circumstances and the people they are facing at that time. If they are good friends, it will be a thing of the past.

Module seamless docking requires us to have a good grasp of the module division and design granularity of interface, abstract class and class, which is more reflected in experience. The relationship between modules is a contract, how to implement the contract will involve the choice of many design patterns, so the degree of grasp of the design module directly affects the maturity of the software framework. Just like two people talking to each other, the way of speaking and meaning can not understand each other, so it is possible to say more than half a sentence without speculation.

Logging is a necessary feature of all software, which provides great convenience for us to troubleshoot errors. Logging has many open source projects that can be used directly, such as the commonly used Log4Net. However, when I have time to study this thing, I can also write a log library that is suitable for me.

Stability is the most direct response to software operation, is the most important consideration in all real-time framework design, and is also the most difficult to achieve.

Expansibility

Users may be more concerned about stability than designers, but users are not only satisfied with stability, but also put forward a variety of new requirements, more reflected in the function. If the scalability is not good, it will be an abyss for developers.

Therefore, scalability is one of the most prominent features of the application framework, which means that the function of the application framework has the ability to grow. The application framework without scalability has no use value and meaning, because the framework itself is to provide a unified context for specific applications to use. The expansibility of the application framework enables us to implement different functions and meet different application needs based on one platform, some of which are supported by the framework itself.

The extensibility of the framework is mainly achieved through inheritance and aggregation. Inheritance means that the derived class inherits the base class or interface, and the function is extended by reusing the functions of the base class and defining new functions; aggregation refers to calling different types to combine into a new type and extending new functions. By studying the source code of Framework framework, we can deeply feel the role of inheritance and aggregation.

If extensibility alone makes people a little hollow, then we also have to consider modularity, reusability, maintainability, and so on.

Modularity does not mean that every function is compiled into a DLL assembly. It can also be modularized within an assembly. From the framework level, the modules and layers are logically divided horizontally and vertically, in order to reduce the coupling between modules, will not affect other modules because of the change of one module, and ensure the unity of input and output between modules when dividing modules.

Reusability, also known as reusability, is one of the important indicators to measure the quality of code. Since one of the goals of framework design is to improve efficiency, reduce unnecessary repetitive work, and reduce costs. Generally speaking, framework reuse can be discrete functions, packaged class libraries, or encapsulated class libraries, so that we can use them in similar functions and businesses.

Maintainability, the ability to easily change according to business requirements, is also the foothold of scalability. Ensure that we modify the code as little as possible to complete the requirements without affecting the overall operation of the software.

Performance

Performance is an important index of software running efficiency and a test of software running limit. For example, no matter how many device drivers are mounted, the user is required to read the data of all devices once a second. If this cannot be achieved, the user says sorry, and we cannot sign the contract.

In the Internet industry, there are higher and more comprehensive requirements for performance, and there are many index parameters, such as response time, delay time, throughput, concurrency, resource utilization and so on. In the traditional industry, it is not necessary to learn from the use of advanced frameworks or third-party components, such as message queuing framework (kafka, ActiveMq, RabbitMq, ZeroMq, EQueue), responsive message framework (Akka.net), job scheduling framework (Quartz.net) and so on, which can help to improve the efficiency and performance of software and system.

Of course, for performance, software is only one aspect, more related to the network structure, server deployment and other aspects, is a comprehensive structure.

For stability, scalability and performance, it is the three aspects of a whole. I believe everyone has seen the F1 race, which requires the car not to turn over at high speed, the tire wear is very serious when driving at high speed, and it is required to facilitate tire replacement in a very short time.

1.7 plug-in application framework

Plug-in technology divides the whole application into two parts: the host program and the plug-in object in the process of software design and development. the host program can call the plug-in object, and the plug-in object can implement its own logic on the host program. the interaction between the two is based on a common communication contract. The host program can exist independently of the plug-in object, and the operation of the host program will not be affected even if there is no plug-in object. Therefore, we can add or adjust functions by adding or subtracting plug-ins or modifying plug-ins without changing the host program. Because the host program using plug-in technology has the essential characteristics of a framework, it can be regarded as a plug-in framework. Plug-in framework can effectively reduce the degree of coupling between functional objects and object management logic, and put the coupling to the optimal degree.

For most computer users and software developers, plug-in application framework is not a mystery. In fact, almost everyone has used software products with plug-in functions. These software are large and small, from simple operation such as player software to complex professional application software, have more or less used plug-in mechanism, but for end-users, because they are often satisfied with using a mature software, few people pay attention to what kind of architecture these software uses.

Visual Studio IDE, Elipse and other plug-in development tools, and implemented a very powerful plug-in mechanism, but also promote these software to become more and more powerful.

Generally speaking, the reasons why a software and a framework use plug-ins are mainly based on the following three points:

N can extend the functionality of the program without recompiling and releasing the program.

N can add new functions to the program without the need for the program source code.

N can flexibly adapt when the business logic of a program is constantly changing and new rules are added frequently.

There are generally three technologies to implement plug-in mechanisms: plug-ins based on dynamic link library DLL, plug-ins based on component object model COM, and plug-ins based on .NET reflection technology.

SuperIO is a plug-in mechanism implemented using reflection technology, which is described in detail in later chapters.

1.8 Development environment

Development language

The SuperIO framework developed with C # can also be implemented in other languages, such as JAVA.

Development tools

It was first developed using the Visual Studio 2008 tool, then upgraded to Visual Studio 2012, and SuperIO was recompiled.

Supporting framework

At first, I used the Framework 2.0 framework for development, and then upgraded to Framework 4.0. in order to be compatible with the lower version of the operating system (Windows xp sp3), the highest version of the framework can only use Framework 4.0. no higher version of the framework can run under Windows xp sp3. As shown below:

Compiling environment

Use X86 platform to compile the project, if the development plug-in also needs to be compiled with X86 platform, mainly considering the versatility of 32-bit and 64-bit operating systems. As shown below:

Development environment:

It was first developed under the Windows xp sp3 operating system and later upgraded to Windows 8max 8.1.

1.9 third-party components

Use Developer Express suite to layout the UI part of the framework, mainly used in Menu, MdiTabForm, DockPanel these three aspects.

Use PCOMM.DLL to operate the serial port channel, and do not use Microsoft's own SerialPort component, because this component is not compatible with some industrial serial cards. Please see: SerialPort operates PCI-1621D multi-serial cards with an exception of "incorrect parameters".

The OPC server uses the WtOPCSvr.dll component of the OPC Foundation, but this requires a genuine license. The OPC client uses the OPCDAAuto.dll component. You can download the SuperIO_Demo.rar case code from http://pan.baidu.com/s/1pJ7lZWf, which contains the complete OPC server and client code.

At this point, the study of "what are the knowledge points of the C# communication framework" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report