Omron NJ/NX Plc support

630 views
Skip to first unread message

Leandro

unread,
May 15, 2021, 10:07:20 AM5/15/21
to libp...@googlegroups.com
First of all, congratulations for the lib. It is very helpful and well done.
I'm using the C# wrapper from mesa to communicate with several AB Plc types (Micrologix 1100, SLC500, Control and CompactLogix, Micro820) and all are working very well.
But now I'm trying to communicate with Omron Nj/Nx plc and I got an error message: PLCTAG_ERR_UNSUPPORTED from tags that exist in the PLC
and PLCTAG_ERR_NOT_FOUND from the ones that are not.
I'm using configs as Micro800 protocol, with IP and no path. 
Any one have any examples or ideas that can help me with this?
I have a plc borrowed from Omron that I can put it on the web to test, approve the protocol and have an example code to other users. What do you think?

I also can create a lot of different tags and types on it.

Best Regards,

Leandro 

Leandro Coeli

unread,
May 15, 2021, 12:49:35 PM5/15/21
to libplctag
Now I could get it.
Check the results:

Results.png

The code:

using System;
using System.Collections.Generic;
using System.Threading;
using LibplctagWrapper;

namespace LgxSimple
{
    class Program
    {
        const int DataTimeout = 5000;

        static void Main(string[] args)
        {
            var client = new Libplctag();

            const string PLC_IP = "192.168.1.233";
            const string PLC_PATH = "18,192.168.1.233";
            const CpuType PLC_TYPE = CpuType.nx1p2;  // I created this CPUType nx1p2

            var tag1 = new Tag(PLC_IP, PLC_PATH, PLC_TYPE, "tag1", DataType.Int16, 1);
            var tag2 = new Tag(PLC_IP, PLC_PATH, PLC_TYPE, "tag2", DataType.Float32, 1);
            var tag3 = new Tag(PLC_IP, PLC_PATH, PLC_TYPE, "tag3", DataType.Int16, 1);
            var tag4 = new Tag(PLC_IP, PLC_PATH, PLC_TYPE, "tag4", DataType.Int16, 1);

            var tags = new List<Tag> {
                tag1,
                tag2,
                tag3
            };

            var tagsBool = new List<Tag> {
                tag4
            };

            /* create the tag(s) */
            foreach (var tag in tags)
            {
                client.AddTag(tag);
            }

            foreach (var tag in tagsBool)
            {
                client.AddTag(tag);
            }

            /* let the connect succeed we hope */
            foreach (var tag in tags)
            {
                while (client.GetStatus(tag) == Libplctag.PLCTAG_STATUS_PENDING)
                {
                    Thread.Sleep(100);
                }

                if (client.GetStatus(tag) != Libplctag.PLCTAG_STATUS_OK)
                {
                    Console.WriteLine($"Error setting up '{tag.Name}' internal state. Error {client.DecodeError(client.GetStatus(tag))}\n");
                    return;
                }
            }

            foreach (var tag in tagsBool)
            {
                while (client.GetStatus(tag) == Libplctag.PLCTAG_STATUS_PENDING)
                {
                    Thread.Sleep(100);
                }

                if (client.GetStatus(tag) != Libplctag.PLCTAG_STATUS_OK)
                {
                    Console.WriteLine($"Error setting up '{tag.Name}' internal state. Error {client.DecodeError(client.GetStatus(tag))}\n");
                    return;
                }
            }

            /* get the data */
            int rc;
            foreach (var tag in tags)
            {
                rc = client.ReadTag(tag, DataTimeout);
                if (rc != Libplctag.PLCTAG_STATUS_OK)
                {
                    Console.WriteLine($"ERROR: Unable to read the '{tag.Name}' data! Got error code {rc}: {client.DecodeError(client.GetStatus(tag))}\n");
                    return;
                }
            }


            /* print out the data */
            Console.WriteLine("\n\n{{{{{{{{{{{{{{{{{{{{{\n");

            Console.WriteLine($"initial 'tag1' = { client.GetInt16Value(tag1, 0)}\n");
            Console.WriteLine($"initial 'tag2' = { client.GetFloat32Value(tag2, 0)}\n");
            Console.WriteLine($"initial 'tag3[0]' = { client.GetInt16Value(tag3, 0)}\n");
            Console.WriteLine($"initial 'tag3[1]' = { client.GetInt16Value(tag3, 2)}\n");
            Console.WriteLine($"initial 'tag4[0]' = { client.GetBitValue(tag4, 0, DataTimeout)}\n");
            Console.WriteLine($"initial 'tag4[1]' = { client.GetBitValue(tag4, 1, DataTimeout)}\n");
            Console.WriteLine($"initial 'tag4[2]' = { client.GetBitValue(tag4, 2, DataTimeout)}\n");
            Console.WriteLine($"initial 'tag4[3]' = { client.GetBitValue(tag4, 3, DataTimeout)}\n");

            Console.WriteLine("---------------------\n");

            client.Dispose();
        }

        static void LogError(string error)
        {
            Console.WriteLine(error);
            Console.ReadKey();
        }
    }
}

Kyle

unread,
May 18, 2021, 11:54:09 AM5/18/21
to libplctag
Hi Leandro,

Thanks for the update and thanks for the patch to libplctag.NET!   And many thanks for your kind offer of access to an Omron PLC!

Best,
Kyle
Message has been deleted

Błażej Cieślikowski

unread,
Oct 28, 2021, 5:21:24 AM10/28/21
to libplctag
Hello everyone,

I try to connect to Omron PLC also but I have several problems. 
How did You choose the path as "18, IP_NUMBER". What does 18 mean? 
You wrote that You add to enum another type, what int is hidden under that CpuType? 

When I tried to use Your program mentioned before in the comments above I get the Error PLCTAG_ERR_CREATE.
Thank You for your help in advance.

Kyle

unread,
Oct 28, 2021, 9:39:32 AM10/28/21
to libplctag
Hi,

For some reason Omron PLCs need to have a path that has the IP address in it.  The "18" or "19" part indicates that what follows is an IP address and to use either port 1 (18) or port 2 (19).   Since you already connect to the IP address, I do not know why you need to send it again.  Perhaps some have multiple CPUs in one chassis?

What wrapper are you using?   What operating system?

Best,
Kyle
Reply all
Reply to author
Forward
0 new messages