HslCommunication

repository·master·Indexed 24 days ago

https://github.com/dathlin/hslcommunication

An industrial IoT communication library providing connectivity for protocols including Mitsubishi, Siemens, OMRON, and Modbus. It supports C#, Java, and Python across multiple platforms, enabling the development of MES, monitoring, and data acquisition systems. Key features include PLC communication, NetSimplify for cross-language communication, and industrial utilities such as log functions and Fourier transforms.

Tokens
1.3K
Snippets
3
Records
8
Agent score
35%

What's inside HslCommunication

  1. Overview of HslCommunication capabilities

    master

    HslCommunication is an industrial IoT communication architecture implementation designed for industrial software development. It provides cross-program, cross-language, and cross-platform communication capabilities.

    Key Features:

    • PLC Communications: Support for Mitsubishi, Siemens, OMRON, and Modbus.
    • Multi-language Support: Implementations available for .NET (C#), Java, and Python.
    • Industrial Utilities: Includes log functions, flow number generation, mail sending, and Fourier transform functions.
    • System Integration: Enables real-time data acquisition for C/S, B/S, and hybrid (Desktop/Browser/Android) systems, facilitating the development of MES, monitoring, and automated scheduling software.
  2. Implement cross-language communication with NetSimplify

    master

    The library supports a NetSimplify pattern for cross-language communication (e.g., a C# server communicating with Python, Java, or Android clients).

    1. Server Side (C#): Use NetSimplifyServer to listen for connections and handle incoming messages via the ReceiveStringEvent.
    2. Client Side: Use NetSimplifyClient in C#, Java, or Python to send requests and read responses from the server.

    Note: The server-side implementation is primarily available in the .NET version.

  3. Call HslCommunication.dll from Visual C++

    master

    To use the .NET DLL in a C++ project, you must enable CLR support and reference the DLL.

    1. In your C++ project: Properties -> Configuration Properties -> General -> CLR Support (Set to Yes).
    2. Add a reference to HslCommunication.dll(net35).
    3. Use the HslCommunication and ModBus namespaces.

    Example using ModbusTcpNet via C++/CLI:

    #include "pch.h"
    #include <iostream>
    using namespace HslCommunication;
    using namespace ModBus;
    
    int main()
    {
        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");
        }
    }
  4. Read and write PLC data using HslCommunication.dll

    master

    HslCommunication provides a simplified way to interact with various PLCs (Siemens, Mitsubishi, AB, OMRON, etc.). Instead of managing raw network protocols, you use high-level classes.

    To handle potential network failures or incorrect addresses, all read/write operations return an OperateResult<T> object. You should always check IsSuccess before accessing the Content property to avoid errors.

    Short Connection (Default): By default, the library uses a short connection that automatically shuts down the network after the operation is finished.

    Persistent Connection: For frequent communication, use SetPersistentConnection() to keep the connection open. When you are finished with the device, you must manually call ConnectClose() to release the connection.

  5. Set the authorization code in C#

    master

    HslCommunication requires an authorization code to unlock full functionality. If authorization fails, the program is limited to 8 hours of use. You should call HslCommunication.Authorization.SetAuthorizationCode exactly once at the start of your application (e.g., in the Main method).

    // Authorization example: call only once
    if(!HslCommunication.Authorization.SetAuthorizationCode( "你的激活码" ))
    {
        MessageBox.Show( "授权失败!当前程序只能使用8小时!" );
        return;
    }
  6. Reference: HslCommunication Component Versions

    master

    The project provides different versions of the library optimized for specific platforms:

    • HslCommunication.dll (.NET): Full version including both Server and Client capabilities. Suitable for Windows desktop, Web backends, and general .NET applications.
    • HslCommunication.jar (Java): A 'castrated' version of the .NET library. It removes server-side code and retains client-side functionality. Ideal for Android and J2EE clients communicating with a .NET server.
    • HslCommunication.py (Python): A 'castrated' version of the .NET library. It removes server-side code and retains client-side functionality for cross-platform Python applications.