For a description of the dual-mode client of the Hslcommunication component, this description applies to all derived class clients, including Mitsubishi, Siemens, Omron, MODBUSTCP, robotics, simplifynet client, etc.

Source: Internet
Author: User

Preface

This article is mainly questions and answers, in response to the vast number of netizens frequently asked questions and summed up the problem

NuGet Address: https://www.nuget.org/packages/HslCommunication/

GitHub Address: Https://github.com/dathlin/HslCommunication If you like star or fork, you can also enjoy support.

You can download the installation in the NuGet Manager in Visual Studio, or you can enter the following instructions directly in the NuGet console to install:

Install-package hslcommunication

NuGet Installation Tutorial Http://www.cnblogs.com/dathlin/p/7705014.html

Technical Support QQ Group: 592132877 (Component version update details will be released in the group first) Component API address: http://www.cnblogs.com/dathlin/p/7703805.html

The simplest use-short connection

Before using the read-write data function, it is natural to instantiate the object, and then specify the IP address and port number, such as Siemens, do not need to specify the port can also be accessed, because the internal initialization of the default value of 102. And Omron's connection also to specify some other parameter information, all the client access class as long as the instantiation and specify the relevant parameters, you can understand the reading and writing data, the following examples:

Mitsubishi's

Melsecmcnet melsec_net = new Melsecmcnet ("192.168.0.188", 6000);//Then you can call short value = Melsec_net directly. ReadInt16 ("D1000"). Content;

Siemens '

Siemenss7net siemenstcpnet  = new Siemenss7net (siemensplcs.s1200, "192.168.0.100");//Then directly call the short value = Siemenstcpnet.readint16 ("M100"). Content;

Omron's

Omronfinsnet omronfinsnet =  new Omronfinsnet ("192.168.0.100", 6000);//Then directly call the short value = Omronfinsnet.readint16 ("D100"). Content;

Modbus TCP's

Modbustcpnet bustcpclient = new Modbustcpnet ("192.168.0.100", 502, 0x01);//Then you can call short value = Bustcpclient.readint directly 16 ("100"). Content;

Simplifynet, without specifying a token

Netsimplifyclient simplifyclient = new Netsimplifyclient ("192.168.0.100", 6000);//Then you can directly call the string read = Simplifyclient.readfromserver (1, "test")

And so on, other data access derived classes support this pattern. This is the mechanism of the short connection, the main use logic is as follows:

That is, each time a data request is reconnected to the server before the actual data request is started, and then the connection is closed. Obviously, the network connection and shutdown are consumption of resources, but do have a benefit, do not reconnect the trouble, each time is a new server request, as long as the read failed, you can think that the network has been dropped, the other has nothing to say, next look at the more complex long connection.

Efficient data interaction-long connections

In order to solve the disadvantages of the short connection mentioned above. Of course, if you do not require the frequency of access, the basic is once per second, the network is not very stable situation, or is quite suitable for short connections, if the speed of reading and writing requirements are high, the network is better, it is undoubtedly not suitable for short connections. How to use a long connection, we still give some examples

Mitsubishi's

Melsecmcnet melsec_net = new Melsecmcnet ("192.168.0.188", 6000);
Melsec_net. ConnectServer ();//Then the call will be very fast after short value = Melsec_net. ReadInt16 ("D1000"). Content;

Siemens '

Siemenss7net siemenstcpnet  = new Siemenss7net (siemensplcs.s1200, "192.168.0.100");
Siemenstcpnet.connectserver ();//Then the call will be very fast after short value = Siemenstcpnet.readint16 ("M100"). Content;

Omron's

Omronfinsnet omronfinsnet =  new Omronfinsnet ("192.168.0.100", 6000);
Omronfinsnet.connectserver ();//Then the call will be very fast after short value = Omronfinsnet.readint16 ("D100"). Content;

Modbus TCP's

Modbustcpnet bustcpclient = new Modbustcpnet ("192.168.0.100", 502, 0x01);
Bustcpclient.connectserver ();//Then the call will be very fast after short value = bustcpclient.readint16 ("100"). Content;

Simplifynet, without specifying a token

Netsimplifyclient simplifyclient = new Netsimplifyclient ("192.168.0.100", 6000);
Simplifyclient.connectserver ();//And then call it up very fast string read = Simplifyclient.readfromserver (1, "test")

And so on, if you want to know if the connection is successful, refer to the following code

Operateresult connect = client. ConnectServer (); if (connect. issuccess) {   MessageBox.Show ("Connection succeeded");} else{   MessageBox.Show ("Connection Failed");}

Then talk about the idea behind the program, more complicated than the short connection

To the caller, is actually the call of the loop can be, the normal situation and the short connection call method are consistent, the problem is in my original good data request, suddenly the network is not, and then I next read failed, at this time, do not worry, continue to loop read on can, internal logic, If a network failure occurred at the time of the last read, usually due to disconnection, the opposing party is forced to shut down. Then in the next read, will automatically first go to connect to the server, if successful, then this time the data interaction will also be successful, if the connection failed, then the next time the next read will be re-connected until the success.

delay Start Long connection

The long connection above the pattern, there is a small flaw, I must be connected to the server when switching long connections, but my software may not be read immediately, it may be a long time before starting to read data, so this component also supports the manual setting of long connections, until the first time to read the data to start the connection server, The subsequent operation is consistent with the above. The whole logic is like this.

The principle is to call a method, set to a long connection mode, waiting for the actual data interaction, only to really connect to the server to read.

Alien Mode

Since the PLC will never actively connect the ability, so the alien mode is only applicable to the Modbus client, because Modbus has a server to support active connections, specific reference

Http://www.cnblogs.com/dathlin/p/8934266.html

Description of the dual-mode client for the Hslcommunication component, which applies to all derived class clients, including Mitsubishi, Siemens, Omron, MODBUSTCP, robotics, simplifynet client, etc.

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.