Giter Club home page Giter Club logo

dathlin / hslcommunication Goto Github PK

View Code? Open in Web Editor NEW
1.5K 63.0 600.0 42.58 MB

A very popular industrial Internet of Things communication plug-in. Using this dll can be very convenient, stable, and fast to obtain data from PLC equipment of multiple brands, and also supports redis, mqtt, websocket, etc., which can let your data on the network Free transmission, reducing enterprise development costs.

Home Page: http://www.hslcommunication.cn

C# 100.00%
modbus siemens hslcommunication redis melsec panasonic omron allen-bradley

hslcommunication's Introduction

             ///\      ///\             /////////\              ///\
            //\\/      //\/           //\\\\\\\\//\            //\\/
           //\/       //\/          //\\/       \\/           //\/
          //\/       //\/           \//\                     //\/
         /////////////\/             \//////\               //\/
        //\\\\\\\\\//\/               \\\\\//\             //\/
       //\/       //\/                     \//\           //\/
      //\/       //\/           ///\      //\\/          //\/       //\
     ///\      ///\/            \/////////\\/           /////////////\/
     \\\/      \\\/              \\\\\\\\\/             \\\\\\\\\\\\\/             Present by Richard.Hu

HslCommunication

Build status NuGet Status NuGet Download Gitter NetFramework Visual Studio copyright status

HslCommunication.jar

Build status NetFramework version JDK status IDE status copyright status

HslCommunication.py

Build status NetFramework version download IDE status copyright status

CopyRight

(C) 2017 - 2023 Richard.Hu, All Rights Reserved

Authorization(授权)

具体可以参照 http://www.hsltechnology.cn/Home/Licence?area=HslCommunication

试用授权: 加入 技术支持VIP群 即可以获得激活码,支持长时间测试使用。企业用户可以联系微信:13516702732 申请试用的证书

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main( )
        {
            // 授权示例   调用一次即可  call only once
            if(!HslCommunication.Authorization.SetAuthorizationCode( "你的激活码" ))
            {
                MessageBox.Show( "授权失败!当前程序只能使用8小时!" );
                return;
            }


            Application.EnableVisualStyles( );
            Application.SetCompatibleTextRenderingDefault( false );
            Application.Run( new Form1( ) );
        }

商用授权(赠送源代码):

  1. 公对公签订合同。
  2. 公对公打款,开具增值税发票。
  3. 获取专用的软件,账户,来下载最新的源代码,激活码
  4. 企业专业培训额外付费,1000元人民币1小时,培训控件使用,控件开发。

Official Website

Webside: http://www.hslcommunication.cn/

API: http://api.hslcommunication.cn/

Gitter[talk with me]: https://gitter.im/HslCommunication/community

What is HSL

This is an industrial IoT based, computer communications architecture implementation, integrated with most of the basic functional implementation of industrial software development, such as Mitsubishi PLC Communications, Siemens PLC Communications, OMRON PLC Communications, Modbus Communications, All of these communications have been implemented in multiple languages, and of course, the feature integration of the main. NET Library is even more powerful, in addition to the implementation of cross-program, cross-language, cross-platform communication, so that you are no longer obsessed with the use of Windows or Linux system, the realization of log function, flow number generation function, mail sending function, Fourier transform function, and so on, will integrate more common features of industrial environment in the future.

In order not to let the industry 4.0 stay on the slogan, the high-rise flat up, and the cornerstone is HSL.

What can HSL do

HSL can connect the equipment of the industrial production site to the free transmission of data at the bottom, whether active or passive, whatever your acquisition system (usually the acquisition system is a Windows computer, or an embedded system, or a Linux-based box), can achieve the random transmission of data, convenient and fast to achieve a strong, real-time, high-response robust system, whether you are building a C/S system, or B/S system, or C-B-S-A (Integrated desktop client, browser, Android) hybrid system, is a fast and low-cost implementation,

As long as you have the primary data of the industrial field, that is, can build a powerful real-time monitoring function of the software, production reports and automated scheduling software, a variety of process parameters history tracking software, data based on the experience of machine learning software, as well as full-featured MES system and so on.

By the way, the traditional industrial model is the procurement of off-the-shelf industrial software, including the host computer software and MES system, while ignoring their own system. For some industry-standard functional software, such as ERP systems, financial software, these can be purchased directly, However, for the host computer and MES system, the actual needs of each enterprise are very different, it is difficult to have a common scene, and the current situation is to spend a lot of money to do small things, so here, give a future-oriented model to achieve: for the production enterprise, Based on HSL to develop enterprise-class MES system implementation, as the core Warehouse center of data, and business logic processing Center, for equipment suppliers, based on HSL to develop the host computer software system, fast and convenient distribution of data to the customer's MES system, work together.

Install From NuGet

Description: NuGet for stable version, Support Online upgrade, the use of components is best downloaded from NuGet, the project published here is likely to have not yet compiled the beta version, NuGet installation is as follows:

Install-Package HslCommunication

HslCommunication.dll Summary

When I started working on this project, I had an idea of how to easily and quickly read and write PLC data. Our code logic should be very simple, and it only takes one or two lines of code to implement this feature. Like this

// Pseudo code
PLC plc = new PLC("192.168.0.11", 6000);

short value = plc.ReadInt16("D100");

But after a long period of development and attempt, found that the return of PLC is likely to be abnormal, this anomaly may come from the network failure, may also come from you entered the wrong address, or the PLC itself is not allowed to operate, so in this project added a class Operateresult, So the final code becomes what it looks like (with Siemens PLC as an example)

SiemensS7Net siemens = new SiemensS7Net( SiemensPLCS.S1200, " 192.168.1.110" );
OperateResult<short> read = siemens.ReadInt16("M100");

if(read.IsSuccess)
{
	// you get the right value
	short value = read.Content;
}
else
{
	// failed , but you still can know the failed detail
	Consolo.WriteLine(read.Message);
}

Of course, you can also write very concise, because the judgment of success is ignored, so the following operation is risky.

SiemensS7Net siemens = new SiemensS7Net( SiemensPLCS.S1200, " 192.168.1.110" );
short value = siemens.ReadInt16("M100").Content;   // Look at this code, isn't it very succinct.

When use .Net4.5 or higher plateform. we can use like this

SiemensS7Net siemens = new SiemensS7Net( SiemensPLCS.S1200, " 192.168.1.110" );
short value = (await siemens.ReadInt16Async("M100")).Content;   // Look at this code, isn't it very succinct.

The above operation we have read the data, but is based on a short connection, when the reading of the data finished, automatically shut down the network, if you want to open a long connection, follow the following actions.

SiemensS7Net siemens = new SiemensS7Net( SiemensPLCS.S1200, " 192.168.1.110" );
siemens.SetPersistentConnection( );
OperateResult<short> read = siemens.ReadInt16("M100");

if(read.IsSuccess)
{
	// you get the right value
	short value = read.Content;
}
else
{
	// failed , but you still can know the failed detail
	Consolo.WriteLine(read.Message);
}

// when you don't want read data, you should call close method
siemens.ConnectClose( );

When use .Net4.5 or higher plateform. we can use like this

SiemensS7Net siemens = new SiemensS7Net( SiemensPLCS.S1200, " 192.168.1.110" );
siemens.SetPersistentConnection( );
OperateResult<short> read = await siemens.ReadInt16Async("M100");

if(read.IsSuccess)
{
	// you get the right value
	short value = read.Content;
}
else
{
	// failed , but you still can know the failed detail
	Consolo.WriteLine(read.Message);
}

// when you don't want read data, you should call close method
siemens.ConnectClose( );

So we can see that all the other modes of communication are similar to this, including Mitsubishi PLC, Siemens PLC,AB PLC, OMRON PLC, Keane plc, Panasonic Plc, redis Communications, EFT Robots, Kuka robots and so on, including its own support for the HSL protocol.

The goal is to reduce the cost of learning for developers, and usually you have to learn how to use several different libraries and learn the basics of PLC. Now, all you need to know is how the basic PLC address is represented, and you can read and write PLC data.

Called from Visual C++ project

cppProject -> Properties -> Configuration Properties -> General -> CLR Support

Add HslCommunication.dll(net35) reference

#include "pch.h"
#include <iostream>
using namespace HslCommunication;
using namespace ModBus;

int main()
{
    std::cout << "Hello World!\n";


	// This is the demo , called C# ModbusTcpNet
	System::String ^ipAddress = gcnew System::String("127.0.0.1");
	ModbusTcpNet ^modbus = gcnew ModbusTcpNet(ipAddress, 502, 1);

	System::String ^dataAddress = gcnew System::String("100");
	OperateResult<short> ^readValue = modbus->ReadInt16(dataAddress);
	if (readValue->IsSuccess) {
		short value = readValue->Content;
		printf("Read Value:%d \n", value);
	}
	else
	{
		printf("Read Failed");
	}
}

If you want to communication in your mobile phone application, you also can use C# code by xamarin, you can download HslAppDemo to test HslAppDemo.apk

Another feature of this project is support for cross-language communication support. You can build a C # background server that supports Windows desktop application and Web background, and Android phone-side, Python programs, Java programs to communicate. server side code:

class Program
{
    static void Main(string[] args)
    {
		NetSimplifyServer simplifyServer;
		try
		{
			simplifyServer = new NetSimplifyServer( );
			simplifyServer.ReceiveStringEvent += SimplifyServer_ReceiveStringEvent;
			simplifyServer.ServerStart( 12345 );
		}
		catch(Exception ex )
		{
			Console.WriteLine( "Create failed: " + ex.Message );
			Return;
		}

		Console.ReadLine();
	}

	private static void SimplifyServer_ReceiveStringEvent( AppSession session, NetHandle handle, string value )
	{
		if (handle == 1)
		{
			// Message to operate when a signal from the client is received 1
			simplifyServer.SendMessage( session, handle, "This is test single:" + value );
		}
		else
		{
			simplifyServer.SendMessage( session, handle, "not supported msg" );
		}
	
		// Show out, who sent it, what did it send?
		Console.WriteLine($"{session} [{handle}] {value}");
	}
}

C# Client Side (Also asp.net mvc, asp.net core mvc)

NetSimplifyClient simplifyClient = new NetSimplifyClient( "127.0.0.1", 12345 );
string value = simplifyClient.ReadFromServer( 1, "test" ).Content;

Java Client Side

NetSimplifyClient simplifyClient = new NetSimplifyClient( "127.0.0.1", 12345 );
string value = simplifyClient.ReadFromServer( 1, "test" ).Content;

Python Client Side

netSimplifyClient = NetSimplifyClient("127.0.0.1",12345)
value = netSimplifyClient.ReadFromServer(1,'123').Content

Note: In the source code, still contains a lot of Chinese annotation, in the future for a short period of time, will be used in English and Chinese double annotation, thank you for your understanding.

HslCommunicationDemo The features supported by this project can be roughly clear through the demo interface below: Picture

HslCommunication.jar Summary

This component provides the Java version, for the. NET version of the castration version, removed all the server function code, retained part of the client function code, convenient and plc, device data interaction, and C # program data interaction, this jar component is suitable for the development of Android, easy to build a. NET Server + Windows Client + asp.net client + J2EE client + Java Client + Android client. Picture

HslCommunication.py Summary

This component provides a Python version, a castration version of the. NET version, removes all server function codes, retains some of the client function code, facilitates data interaction with PLC, devices, and data interaction with C # programs for cross-platform operation Picture

Xamarin.Android Demo

Picture

Where is the Source code?

Not free open source. you can refer to webside: http://www.hslcommunication.cn/Cooperation

How to sponsor author?

PayPal

Alipay

Thank you for your understanding

hslcommunication's People

Contributors

arunpratap26 avatar dathlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hslcommunication's Issues

关于ADS读取指定长度的位,结果问题

ADS位读取
例如 M100.0 ,长度10 ,布尔类型
获取结果 [M100.0] [False,False]
报文:
[调试] 2023-01-16 22:38:15.836 Thread [003] BeckhoffAdsServer[10086] : [127.0.0.1:10766] Tcp 接收:00 00 2C 00 00 00 C0 A8 A3 08 01 01 53 03 C0 A8 A3 09 01 01 BD 80 02 00 04 00 0C 00 00 00 00 00 00 00 12 00 00 00 21 40 00 00 20 03 00 00 0A 00 00 00
[调试] 2023-01-16 22:38:15.836 Thread [003] BeckhoffAdsServer[10086] : [127.0.0.1:10766] Tcp 发送:00 00 2A 00 00 00 C0 A8 A3 09 01 01 BD 80 C0 A8 A3 00 01 01 53 03 02 00 05 00 0A 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 02 00 00 00 00 00

而且第18个字节为0,不明白为什么?

网址无法访问

官网无法访问,我们想买都找不到入口,希望在readme界面留下联系方式。

新手小白,报错System.ObjectDisposedException:“已关闭 Safe handle”

 private void opencomplc()//打开接口
        {
            try
            {
                if (ccbcom1.Text == "")
                {
                    MessageBox.Show("Select Port Settings First");
                }
                else
                {
                    FxSerial.SerialPortInni(spplc =>
                        {
                            serialPortEncoding = Encoding.GetEncoding("iso-8859-1");
                            spplc.Encoding = serialPortEncoding;
                            spplc.RtsEnable = true;
                            spplc.PortName = ccbcom1.Text;
                            spplc.BaudRate = Convert.ToInt32(cbbrate1.Text);
                            spplc.Parity = (Parity)Enum.Parse(typeof(Parity), "2");
                            //spplc.Parity = System.IO.Ports.Parity.Even;
                            spplc.DataBits = 7;
                            spplc.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "1");
                            //spplc.StopBits = System.IO.Ports.StopBits.One;
                            spplc.Handshake = (Handshake)Enum.Parse(typeof(Handshake), "None");
                            spplc.ReadTimeout = 100;
                            spplc.WriteTimeout = 200;
                        });
                    try
                    {
                        OperateResult connect = FxSerial.Open();
                        if (connect.IsSuccess)
                        {
                            // 串口打开成功
                            Console.WriteLine("Open success");
                        }
                        else
                        {
                            // 串口打开失败,输出原因,可能串口不存在,或是已经被其他程序打开了
                            Console.WriteLine("Open failed:" + connect.Message);
                        }
                        //FxSerial.Open();
                        timer.Start();
                        lbck1.Color = Color.Lime;
                        //MessageBox.Show("串口打开!");
                        if (cbAutoCon1.Checked)
                        {
                            Properties.Settings.Default.PlcPort = "0";
                            Properties.Settings.Default.Save();
                        }
                        
                    }
                    catch (Exception ex)
                    {

                        MessageBox.Show(ex.Message);
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "Message ", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
```
      ```
  private void Closecomplc()//关闭接口
        {
                try
                {
                  
                    FxSerial.Close();
                    FxSerial.Dispose();
                    timer.Stop();
                    lbck1.Color = System.Drawing.Color.Gray;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "message");
                }
            
        }
```
 ```
 /// <summary>
        /// 读取和写入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn5xy_Click(object sender, EventArgs e)
        {
            if (FxSerial.IsOpen() == true)
            {
                OperateResult<bool> R_X1 = FxSerial.ReadBool("Y002");
                if (R_X1.IsSuccess)
                {
                    // success
                    bool value = R_X1.Content;
                    if (value == false)
                    {
                        OperateResult write = FxSerial.Write("M2", true);

                        if (write.IsSuccess)
                        {
                            //MessageBox.Show(write.IsSuccess.ToString());
                            OperateResult wrie = FxSerial.Write("M2", false);
                        }
                    }
                    else
                    {
                        MessageBox.Show("未停止增压");
                    }
                }
                else
                {
                    // failed
                    MessageBox.Show("Read failed: " + R_X1.ToMessageShowString());
                }
            }
        }

```
点击打开串口再关闭,再打开串口,

读取或者写入就报错System.ObjectDisposedException:“已关闭 Safe handle”




GE SRTP仿真软件

请问对于GE SRTP协议的验证, 有什么软件可以作为参考呢,

西门子S7-300批量采集BOOL数据值解析有误

image

逐条采集代码

Console.WriteLine((await siemensTcpNet.ReadBoolAsync("I2.3")).Content);
                Console.WriteLine((await siemensTcpNet.ReadBoolAsync("I2.4")).Content);

批量采集代码

   var result = await siemensTcpNet.ReadAsync(addressArray, lenArray);
            var byteArray = result.Content;

    case "BOOL":
                    result = siemensS7Net.ByteTransform.TransBool(byteArray, startIndex);
                    break;

用两种方式采集的数据,核对发现一次性采集BOOL类型的值解析有误。

requesting to contact support

why It is asking for commercial authorization??

Connection NOK!Error Code: :10000
Description: :System authorization failed, need to use activation code authorization, thank you for your support. Active device number:2910494 If you need commercial authorization, please contact Email: [email protected]

PLC反馈信号错误:0 Actual: 00 00 00 00,怎么解决

三菱plc断电在连上,
读取 short WDTextBox2 = FxSerial.ReadInt16("D200").Content
和写入 OperateResult WD1 = FxSerial.Write("D201", 20);
报PLC反馈信号错误:0 Actual: 00 00 00 00
这是为什么出现这个问题,如果先用GX works2先监视,再到C#上位机连接就没有报错

丢包率过高

对西门子S1500系列进行读写,丢包率达到40%。

            var Connector = new SiemensS7Net(SiemensPLCS.S1500, "172.16.2.121")
            {
                ConnectTimeOut = 5000
            };
            var result1 = Connector.ConnectServer();
            var amount = 0;
            for (short i = 0; i < 10000; i++)
            {
                Connector.Write("DB1001.6", i);
                var output = Connector.ReadInt16("DB1001.6").Content;
                if (i == output)
                {
                    amount++;
                }
            }
            Logger.LogDebug($"进行输入10000次,正确{amount}");
            Connector.ConnectClose();

结果是进行输入10000次,正确6060次

布尔类型无法写入

S7-200 Smart中布尔类型地址格式是存储器[字节地址].[位地址],比如M0.0,报告如下错误。
image

java在使用AB CIP协议API批量读取的时候长度超过30会报错误“目标收到一个无效长度的信息。”

您好,我在使用AllenBradleyNet.Read方法进行AB plc测试批量读取的时候,发现读取点位数没超过30的时候能够正常读取,但是一超过30就会报“目标收到一个无效长度的信息。”这样的错误信息,请问,这是因为长度做了限制吗?如果做了限制的话,假设plc有非常多的点位又该怎么去一次性读取呢?以下是方法测试的调试过程截图:
成功的:
success
失败的:
fail

Hsl Communication调试工具或java调取接口批量读取三菱、AB等协议报远程关闭问题

当我单个读取时没有什么问题,但是实际上使用大部分的场景都是批量读取点位数据,批量读取时Hsl Communication调试工具会报“Read failed:错误代号:-1 文本描述:Socket Exception ->远程关闭了连接”,代码调用也是单个读取不报错,批量读会报远程关闭了连接这样的错误。不知道这是bug还是其他问题?或者说代码有更新?

采集AB CIP一组数据,调用API进行解析时,布尔类型数据解析异常

以下图中程序使用java程序编写,操作如下:
先在plc中准备有一组数据,地址分别有"B[0].A","B[0].B", "B[0].C","B[0].D","B[0].E", "ZZ.B",以B打头的都是布尔类型,ZZ.B是plc中的int类型数值为66,"B[0].A","B[0].B"这两个布尔量为true,其他为false;如下图编写程序批量进行读取,会发现布尔类型读到的全为true,但是感觉返回的byte数据中的数据也并没有什么问题,第二张图中我把false的布尔量点位放到了第一个位置,这里相当于调换了一下位置,发现解析出来的布尔量又全部变成了false。
L~ }$SV 9`U_2WYH }JE0Z1
点位调换顺序:
_M$ZHMHDWZEVK5(7F404SWC

modbus的crc校验检查失败

我使用modbusrtu做从站,写数据始终报“modbus的crc校验检查失败”,是什么原因啊?
使用HslCommunication测试工具也是同样的问题
1683555884551

driver deltav emerson #1

I visited your advanced scada on github and noticed your services support distributed control systems like AB, Panasonic, Siemens and etc. I’m interested to know if your product supports DeltaV Emerson too?
If not, Would it be possible to receive a couple of suggestions over e-mail about how to make this connection between your product and DeltaV Emerson!? (except OPC)

读写DB块错误

您好,我这个在读写S7-1200的时候遇到一个错误,望能解答
环境:ubuntu18.04 python3.6
代码:
siemens.WriteBool("DB300.1.1", True)
错误:
AttributeError: 'bytearray' object has no attribute 'Length'

AB Program Tags

Only showing program tags in Program:MainProgram
Can you add the ability to list tags from all programs in PLC?

FanucSeries0i: ReadProgram 無法讀取程式

11.2.2 這個版本更新之後功能後,讀取程式時會卡住,然後timeout
FanucSeries0i: 读取程序的 API 接口 ReadProgram 再接收完程序后,再接收一次 0x18 指令的报文。
使用的型號是 FanucSeries32i

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.