KrPLCnet 1.1.0

dotnet add package KrPLCnet --version 1.1.0
                    
NuGet\Install-Package KrPLCnet -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KrPLCnet" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KrPLCnet" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="KrPLCnet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KrPLCnet --version 1.1.0
                    
#r "nuget: KrPLCnet, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KrPLCnet@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KrPLCnet&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=KrPLCnet&version=1.1.0
                    
Install as a Cake Tool

C# .NET 환경에서 해외 대형 PLC 제작사가 아닌 국내 제작사(LS ELECTRIC)의 통신을 지원하기 위해 제작된 NuGet 라이브러리입니다. 복잡한 헤더 생성이나 바이트 변환 과정을 맞추지 않으셔도 함수 호출만으로 데이터를 쉽고 편하게 읽고 쓸 수 있습니다.

주요 기능 지원 기종:** XGK, XGI, XGR, XGB (XBC/XEC) 통신 프로토콜:** LS FEnet 전용 프로토콜 (XGT 서버 설정) 지원 데이터 타입:** Word(short), DWord(int), Bit(bool)


사용 예제

1. 간단하게 비트/워드 읽고 쓰기 (Quick Start)

라이브러리를 참조하고 바로 사용하여 통신하는 기본적인 방법입니다.

using KrPLCnet; // 라이브러리 참조

public async Task TestPlcAsync() 
{ 
    // 1. 설정 (IP: 192.168.1.10, Port: 2004, CPU: XGK) 
    // ※ XGB 사용자는 LsCpuType.XGK(XBC) 또는 XGI(XEC)를 선택하세요. 
    using (var plc = new LsEnetClient("192.168.1.10", 2004, LsCpuType.XGK)) 
    { 
        // 2. 연결 
        await plc.ConnectAsync(); 
        Console.WriteLine("PLC 연결 성공!");

        // 3. 데이터 쓰기 (D100 번지에 1234 쓰기)
        await plc.WriteWordAsync("%DW100", 1234);

        // 4. 데이터 읽기 (D100 번지 읽기)
        short value = await plc.ReadWordAsync("%DW100");
        Console.WriteLine($"읽은 값: {value}");

        // 5. 비트 제어 (M0 비트 ON)
        await plc.WriteBitAsync("%MX0", true);

    } // using 문을 빠져나오면 자동으로 연결 해제 (Disconnect)
}


2. 확장성을 고려한 구조 (Interface 패턴)
타사 장비(미쓰비시, 지멘스 등)와 함께 통신하거나, 유지보수성을 높이기 위해 인터페이스를 활용하는 방법입니다.

2-1. 공통 PLC 인터페이스 선언 (IPlcDriver)

C#

namespace SmartFactory 
{ 
    public interface IPlcDriver 
    { 
        bool IsConnected { get; }
        Task<bool> ConnectAsync();
        void Disconnect();

        // 데이터 읽기/쓰기 정의
        Task<short> ReadWordAsync(string address);
        Task WriteWordAsync(string address, short value);
        Task<bool> ReadBitAsync(string address);
        Task WriteBitAsync(string address, bool value);
    }
}

2-2. LS 드라이버 구현 (XgtDriver)


C#

using KrPLCnet;

namespace SmartFactory 
{ 
    public class XgtDriver : IPlcDriver 
    { 
        private LsEnetClient _client; 
        private readonly string _ip; 
        private readonly int _port;
        
        public bool IsConnected => _client != null && _client.IsConnected;

        public XgtDriver(string ip, int port = 2004)
        {
            _ip = ip;
            _port = port;
            // XGK/XGI 모델 기준 생성 (환경에 맞게 수정)
            _client = new LsEnetClient(ip, port, LsCpuType.XGK);
        }

        public async Task<bool> ConnectAsync()
        {
            try
            {
                if (IsConnected) return true;
                await _client.ConnectAsync();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public void Disconnect() => _client?.Disconnect();

        public Task<short> ReadWordAsync(string address) => _client.ReadWordAsync(address);
        public Task WriteWordAsync(string address, short value) => _client.WriteWordAsync(address, value);
        
        public async Task<bool> ReadBitAsync(string address)
        {
            // 주소 편의성 제공 (예: "100" 입력 시 -> "%MX100" 자동 변환)
            string fmtAddress = address.StartsWith("%") ? address : $"%MX{address}";
            return await _client.ReadBitAsync(fmtAddress);
        }

        public Task WriteBitAsync(string address, bool value) => _client.WriteBitAsync(address, value);
    }
}


2-3. WinForms 사용 예제
C#

namespace SmartFactory 
{ 
    public partial class Form1 : Form 
    { 
        // 인터페이스로 선언 (유연성 확보) 
        private IPlcDriver _machine1;

        public Form1()
        {
            InitializeComponent();
            // LS 드라이버로 인스턴스 생성
            _machine1 = new XgtDriver("192.168.1.80", 2004);
        }

        private async void btnConnect_Click(object sender, EventArgs e)
        {
            bool success = await _machine1.ConnectAsync();
            if(success) MessageBox.Show("연결 성공!");
        }

        private async void btnRead_Click(object sender, EventArgs e)
        {
            if (!_machine1.IsConnected) return;

            // 워드 읽기
            short d100 = await _machine1.ReadWordAsync("%DW100");
            Console.WriteLine($"D100: {d100}");

            // 비트 읽기 (예외처리 로직이 포함된 ReadBitAsync 호출)
            bool m0 = await _machine1.ReadBitAsync("0"); // 내부에서 %MX0으로 변환
            Console.WriteLine($"M0: {m0}");
        }
    }
}


더 궁금하시거나 수정을 원하시는 분은 아래 메일로 연락 주시면 답변 드리겠습니다.

Email: gimduho1022@gmail.com
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 714 12/3/2025
1.0.9 675 12/3/2025
1.0.8 685 12/2/2025
1.0.7 683 12/2/2025
1.0.6 683 12/2/2025
1.0.5 498 12/1/2025
1.0.4 191 11/27/2025
1.0.3 192 11/27/2025
1.0.2 193 11/26/2025
1.0.1 193 11/26/2025
1.0.0 195 11/26/2025