Skip to content

Latest commit

 

History

History
131 lines (90 loc) · 3.35 KB

README.md

File metadata and controls

131 lines (90 loc) · 3.35 KB

PLC Omron Standard

MIT NuGet

This project was created to have an easy to use, .NET Standard library to communicate with Omron PLCs. The following features are available:

  • Read from PLC memory areas
  • Write to PLC memory areas
  • Read and write with single values or arrays
  • Read and write with typed values (options are byte, bool, short, int, float, string)
  • Receive events during communications

Getting Started

These instuctions can be used to acquire and implement the library.

Installation

To use this library either clone a copy of the repository or check out the NuGet package

Usage

TCP Example

The following example provides a basic use case for TCP based communications.

using PLC_Omron_Standard;

public class MyClass() 
{
    public bool Test() 
    {
        // Create PLC connection
        var plc = new PlcOmron("192.168.1.100");

        plc.Connect();

        // Read data
        var data = plc.ReadString(123); // Assumes value is "Hello"

        // Write data
        return plc.Write(123, $"{data}, World!");
    }
}

UDP Example

The following example provides a basic use case for UDP based communications.

using PLC_Omron_Standard;

public class MyClass() 
{
    public bool Test() 
    {
        // Get node addresses
        var ip = "192.168.1.100";
        var remote = byte.Parse(ip.Split('.').Last());

        var local = byte.Parse("101"); // This can be any non-zero value, but using the final part of your local IP address is recommended
        
        // Create PLC connection
        var plc = new PlcOmron(ip, 9600, false, remote, local);

        plc.Connect();

        // Read data
        var data = plc.ReadString(123); // Assumes value is "Hello"

        // Write data
        return plc.Write(123, $"{data}, World!");
    }
}

Events Example

The following example provides a use case where events are subscribed to and handled.

using PLC_Omron_Standard;

public class MyClass() 
{
    private readonly ILogger Logger;

    public bool Test(ILogger<MyClass> logger) 
    {
        // Store logger
        Logger = logger;

        // Create PLC connection
        var plc = new PlcOmron("192.168.1.100");

        plc.NotifyCommandError += LogError;
        plc.Connect();

        // Read data
        var data = plc.ReadString(123); // Assumes value is "Hello"

        // Write data
        return plc.Write(123, $"{data}, World!");
    }

    private void LogError(string message) 
    {
        Logger.LogError("{Message}", message);
    }
}

Authors

  • NF Software Inc.

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

Parts of this library have been inspired by:

Thank you to: