0

I try to read OMRON plc's DM table with a C# WPF application beacuse I have to visualize live datas from the machine.

I can read messages via UDP, but I dont know how to read the DM table from the PLC. (PLC's settings are okay, that is ready to the FINS communication)

Here is my code for reading messages via UDP:

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;

namespace OMRON_FINS
{
public partial class Form2 : Form
{

    UdpClient Client = new UdpClient(9600); // PORT number
    string data = "";


    public Form2()
    {
        InitializeComponent();


        textBox1.Text = GetLocalIPAddress();



    }

    public static string GetLocalIPAddress()
    {
        var host = Dns.GetHostEntry(Dns.GetHostName());
        foreach (var ip in host.AddressList)
        {
            if (ip.AddressFamily == AddressFamily.InterNetwork)
            {
                return ip.ToString();
            }
        }
        throw new Exception("No network adapters with an IPv4 address in the system!");
    }






    private void button1_Click(object sender, EventArgs e)
    {
        try
        {

            Client.BeginReceive(new AsyncCallback(recv), null);
            label5.Text = "Reading....";
        }
        catch (Exception ex)
        {
            richTextBox1.Text += ex.Message.ToString();
        }
    }

    public void recv(IAsyncResult res)
    {
        IPEndPoint RemoteIP = new IPEndPoint(IPAddress.Any, 60240);
        byte[] received = Client.EndReceive(res, ref RemoteIP);
        data = Encoding.UTF8.GetString(received);

        this.Invoke(new MethodInvoker(delegate
        {

            richTextBox1.Text += "\nReceived data: " + data;

        }));

        Client.BeginReceive(new AsyncCallback(recv), null);

    }


}

}

Is there any example or guide to read the DM table? Thanks!

H.Daniel
  • 1
  • 2
  • Take a look at my project https://github.com/mcNets/mcOmron, it's an old project and it uses TCP but I let it ready for UDP too. – McNets Jun 10 '22 at 12:53
  • Thank you for the quick response! Should I just modify this parameter from TCP to UDP: "this._socket = new Socket(_endPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);" Or there is anything I have to modify? – H.Daniel Jun 13 '22 at 05:56
  • Give it a try . – McNets Jun 13 '22 at 16:19

0 Answers0