I am trying to get the value of TAG, but i have a problem when I read the Boolean type...
Can you tell me how to read boolean values?
try
{
// creates a tag to read B3:0, 1 item, from SLC ip address 192.168.0.100
var tag = new Tag("192.168.1.101", "1:0", CpuType.LGX, "OTRO", DataType.Int16, 1);
using (var client = new Libplctag())
{
// add the tag
client.AddTag(tag);
// check that the tag has been added, if it returns pending we have to retry
while (client.GetStatus(tag) == Libplctag.PLCTAG_STATUS_PENDING)
{
Thread.Sleep(100);
}
// if the status is not ok, we have to handle the error
if (client.GetStatus(tag) != Libplctag.PLCTAG_STATUS_OK)
{
Console.WriteLine($"Error setting up tag internal state. Error{ client.DecodeError(client.GetStatus(tag))}\n");
Thread.Sleep(5000);
return;
}
// Execute the read
var result = client.ReadTag(tag, DataTimeout);
// Check the read operation result
if (result != Libplctag.PLCTAG_STATUS_OK)
{
Console.WriteLine($"ERROR: Unable to read the data! Got error code {result}: {client.DecodeError(result)}\n");
return;
}
// Convert the data
var TestDintArray0 = client.GetInt16Value(tag, 1* tag.ElementSize); // multiply with tag.ElementSize to keep indexes consistant with the indexes on the plc
// print to console
Console.WriteLine("VALUE_TAG: " + TestDintArray0);
}
}
finally
{
Console.ReadKey();
}