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!