It looks like ReadUDT and WriteUDT don't work properly while ReadRaw and WriteRaw do work.
For my example I used this code:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public struct Order_Info
{
public Int32 ID;
public string Name;
public Int32 Plan_QTY;
public Int32 Time_Est;
}
private void MainForm_Load(object sender, EventArgs e)
{
var tags = ethernetIPforCLXCom1.GetTagList(); //Used to confirm that PLC is responding properly
var udtReadBytes = ethernetIPforCLXCom1.ReadRaw("Orders_Pool", 5); //Read UDT with ReadRaw method (works - this example has 100 bytes returned per UDT member)
Order_Info[] Orders = new Order_Info[5];
for (int i = 0; i < Orders.Length; i++)
{
Orders[i] = new Order_Info
{
ID = BitConverter.ToInt32(udtReadBytes, 0 + i * 100),
Name = System.Text.Encoding.Default.GetString(udtReadBytes, 8 + i * 100, BitConverter.ToInt32(udtReadBytes, 4 + i * 100)),
Plan_QTY = BitConverter.ToInt32(udtReadBytes, 92 + i * 100),
Time_Est = BitConverter.ToInt32(udtReadBytes, 96 + i * 100),
};
}
var udt1 = ethernetIPforCLXCom1.ReadUDT<Order_Info>("Orders_Pool"); //Read UDT with ReadUDT method (doesn't work properly, all values are 0 or null)
var udt2 = ethernetIPforCLXCom1.ReadUDT<Order_Info>("Orders_Pool", 5); //Read UDT with ReadUDT method (doesn't work properly, all values are 0 or null)
Byte[] udtWriteBytes = new Byte[500];
Order_Info[] Orders_Pool = new Order_Info[5];
for (int i = 0; i < Orders_Pool.Length; i++)
{
Orders_Pool[i].ID = i;
BitConverter.GetBytes(Orders_Pool[i].ID).CopyTo(udtWriteBytes, 0 + i * 100);
Orders_Pool[i].Name = "Name" + i.ToString();
BitConverter.GetBytes(Orders_Pool[i].Name.Length).CopyTo(udtWriteBytes, 4 + i * 100);
System.Text.Encoding.Default.GetBytes(Orders_Pool[i].Name).CopyTo(udtWriteBytes, 8 + i * 100);
Orders_Pool[i].Plan_QTY = i + 1;
BitConverter.GetBytes(Orders_Pool[i].Plan_QTY).CopyTo(udtWriteBytes, 92 + i * 100);
Orders_Pool[i].Time_Est = i + 2;
BitConverter.GetBytes(Orders_Pool[i].Time_Est).CopyTo(udtWriteBytes, 96 + i * 100);
}
ethernetIPforCLXCom1.WriteRaw("Orders_Pool", 5, udtWriteBytes); //Write UDT with WriteRaw method (works)
ethernetIPforCLXCom1.WriteUDT("Orders_Pool", Orders_Pool); //Write UDT with WriteUDT method (doesn't work properly - "Not Enough Data")
}
}
It is possible that I wasn't doing it right.