Author Topic: AdvancedHMI C# BeginWriteRaw and WriteRaw Error Help  (Read 1046 times)

FlockaFlame

  • Newbie
  • *
  • Posts: 4
    • View Profile
AdvancedHMI C# BeginWriteRaw and WriteRaw Error Help
« on: November 10, 2022, 04:11:59 PM »
I am currently running 2 parallel tasks every 1 second or 3 seconds.
One to read/write heartbeat comms to say we're connected (writes to a DINT which is 4 bytes) and another one that does calculations and writes a UDT to PLC (916 bytes worth of UDT info).

In the startup of my program, it's likely to get the following error:
"System.NullReferenceException: Object reference not set to an instance of an object"
    at MfgControl.AdvancedHMI.Drivers.CIP.CIPforCLX.a(CLXAddress A_0, Int64 A_1, Int32 A_2)
    at MfgControl.AdvancedHMI.Drivers.CIP.CIPforCLX.a(CLXAddress A_0, UInt16 A_1, Byte[] A_2, Int32 A_3, Int64 A_4)
    at MfgControl.AdvancedHMI.Drivers.EthernetIPforCLX.BeginWriteRaw(String startAddress, Int32 numberOfElements, Byte[] dataToWrite)
This only occurs when trying to BeginWriteRaw() or WriteRaw() to PLC (never a problem with connecting to PLC).
If I try/catch this in an infinite loop, it will eventually not error out and write every time, but after a while, it will miss a write here and there and be good for a while again.

Anyone know the possible cause for this or any ideas?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: AdvancedHMI C# BeginWriteRaw and WriteRaw Error Help
« Reply #1 on: November 10, 2022, 04:26:10 PM »
Are you using version 3.99y Beta?

FlockaFlame

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: AdvancedHMI C# BeginWriteRaw and WriteRaw Error Help
« Reply #2 on: November 10, 2022, 04:42:32 PM »
I am using "AdvancedHMIv399xR1"

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: AdvancedHMI C# BeginWriteRaw and WriteRaw Error Help
« Reply #3 on: November 10, 2022, 05:27:48 PM »
Try it with 3.99y Beta which can be downloaded from this forum

FlockaFlame

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: AdvancedHMI C# BeginWriteRaw and WriteRaw Error Help
« Reply #4 on: November 11, 2022, 12:10:02 PM »
I found a solution, but not figured what the problem was. The version was not of the matter. For some reason, there isn't enough time given to "write" to the PLC. If I add a Thread.Sleep(>200) after using BeginWriteRaw(...), the write will always be successful.

If no Thread.Sleep(...) is used, the BeginWriteRaw will very likely make an exception/error of
"System.NullReferenceException: Object reference not set to an instance of an object."