Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - gti13

Pages: [1]
1
Support Questions / Re: Logix ReadUDT exception
« on: June 17, 2019, 03:05:23 PM »
Awesome! That appears to have resolved the ReadUDT issue, thank you Archie.

2
Support Questions / Re: Logix ReadUDT exception
« on: June 17, 2019, 12:53:10 PM »
I'm also experiencing this null reference exception. Upgrading to Beta 32 does not appear to have resolved the issue, at least not for my scenario.

Code: [Select]
//readData = ethernetIPforCLXCom1.ReadUDT<CompleteUDT>("TestData");
   at MfgControl.AdvancedHMI.Drivers.UDTBytesToClass.a[a]()
   at MfgControl.AdvancedHMI.Drivers.UDTBytesToClass.GetObjectFromBytes[t](Byte[] data, Int32 startIndex)
   at MfgControl.AdvancedHMI.Drivers.EthernetIPforCLX.ReadUDT[t](String startAddress, Int32 numberOfElements)
   at MfgControl.AdvancedHMI.Drivers.EthernetIPforCLX.ReadUDT[t](String startAddress)
   at MainForm.PLC_Read(String element) in C:\Project\MainForm.cs:line 363

//readData = ethernetIPforCLXCom1.ReadUDT<CompleteUDT>("TestData", 1)[0];
   at MfgControl.AdvancedHMI.Drivers.UDTBytesToClass.a[a]()
   at MfgControl.AdvancedHMI.Drivers.UDTBytesToClass.GetObjectFromBytes[t](Byte[] data, Int32 startIndex)
   at MfgControl.AdvancedHMI.Drivers.EthernetIPforCLX.ReadUDT[t](String startAddress, Int32 numberOfElements)
   at MainForm.PLC_Read(String element) in C:\Project\MainForm.cs:line 363

I have a feeling this may be caused by having a nested UDT, similar to the following:
Code: [Select]
public class CompleteUDT
{
public PartUDT PartOne;
public PartUDT PartTwo;
public PartUDT PartThree;
public CompleteUDT()
{
PartOne = new PartUDT();
PartTwo = new PartUDT();
PartThree = new PartUDT();
}       

public class PartUDT
{
public string DetailOne;
public short DetailTwo;
public float DetailThree;
public short[] DetailFour;
public float[] DetailFive;
public PartUDT()
{
DetailOne = string.Empty;
DetailTwo = 0;
DetailThree = 0f;
DetailFour = new short[64];
DetailFive = new float[64];
}
}
}

WriteUDT works fine, but ReadUDT on the root UDT returns the null reference exception.

Code: [Select]
CompleteUDT completeData = new CompleteUDT();

// Assign values
PartUDT partData = new PartUDT();
dynamic value = "0";
// Repeat following for DetailOne, DetailTwo, and DetailThree
value = "some string";
partData.DetailOne = Convert.ChangeType(value, partData.DetailOne.GetTypeCode());
// Repeat following for DetailFive (Array types)
for (int i = 0; i < partData.DetailFour.Length; i++) {
value = i;
partData.DetailFour = Convert.ChangeType(value, partData.DetailFour[i].GetTypeCode());
}
completeData.PartOne = partData;
// Repeat the block above for PartTwo and PartThree

// Write CompleteUDT to tag "TestData"
ethernetIPforCLXCom1.WriteUDT("TestData", completeData);

// Read CompleteUDT from tag "TestData"
CompleteUDT readData = new CompleteUDT();
// Cause null reference exceptions:
//readData = ethernetIPforCLXCom1.ReadUDT<CompleteUDT>("TestData");
//readData = ethernetIPforCLXCom1.ReadUDT<CompleteUDT>("TestData", 1)[0];
// Current workaround:
readData.PartOne = ethernetIPforCLXCom1.ReadUDT<CompleteUDT.PartUDT>("TestData.PartOne");
readData.PartTwo = ethernetIPforCLXCom1.ReadUDT<CompleteUDT.PartUDT>("TestData.PartTwo");
readData.PartThree = ethernetIPforCLXCom1.ReadUDT<CompleteUDT.PartUDT>("TestData.PartThree");

Pages: [1]