OpenLogics / MewtocolNet

⭐ A Mewtocol protocol library to interface with Panasonic PLCs over TCP/Serial written in C#
https://na.industrial.panasonic.com/
GNU General Public License v3.0
28 stars 7 forks source link

AsArray WriteAsync #14

Closed giovanni-systematik closed 1 year ago

giovanni-systematik commented 1 year ago

Hi! I have a problem with the library! After inserting a Word array with the WriteAsync function, an error occurs.

Message object reference not set to an instance of an object

Stack Trace MewtocolNet.Registers.ArrayRegister 1.<WriteAsync>d__30.MoveNext

Code

Word[] value = new Word[15];
for (; i < value .Length; i++)
{
      value[i] = new Word(8224);
}

await plc.Register.Struct<Word>("DT30390").AsArray(15).WriteAsync(value);
Sandoun commented 1 year ago

Hi, thank you for the input! It should be resolved by 19db0a9daad50eea7287bd0aa0782738264502b2

Logger.LogLevel = LogLevel.Critical;
Logger.OnNewLogMessage((t, l, m) => { Console.WriteLine(m); });

using (var plc = Mewtocol.Ethernet("192.168.115.210").Build())
{

    await plc.ConnectAsync();

    await Task.Delay(1000);

    Word[] value = new Word[15];
    for (int i = 0; i < value.Length; i++)
    {
        value[i] = new Word(8224);
    }

    await plc.Register.Struct<Word>("DT30390").AsArray(15).WriteAsync(value);
    var read = await plc.Register.Struct<Word>("DT30390").AsArray(15).ReadAsync();

    Console.WriteLine($"Read: {string.Join(", ", read.Select(x => x.ToString()))}");

}

I forgot to mark the registers that are built by the array pattern as anonymous

giovanni-systematik commented 1 year ago

Now it works correctly! Thank you!