Thanks to your library I'm able to learn about AB PLC tags without having the device on hand.
I'm using version 1.0.3 from nuget, I'm running the code on my machine with the ab_server simulator that I found.
Tags that I'm using:
tag1, tag2 = new Tag<DintPlcMapper, int[]>() {}
tag1.Value = new int[10] - only for reading
tag2.Value = new int[10] - only for writing
I wrote some code based on the examples. I have a simple loop to establish and maintain the connection:
if(!Connected)
{
try
{
CreateTags();
InitializeTags();
//Verify if can read/write
tag1.Read();
tag2.Write();
Connected = true;
}
catch(LibPlcTagException lptex)
{
Connected = false;
DestroyTags();
}
}
Then I read and write tags as follows:
while(Connected)
{
sr = tag1.GetStatus();
sw = tag2.GetStatus();
if( sr== Status.Ok)
{
tag1.ReadAsync();
//decide how to set outputs
}
if(sw == Status.Ok)
{
Thread.Sleep(4);
//write outputs
tag2.WriteAsync();
}
if (sr == Status.Pending || sw == Status.Pending)
{
Thread.Sleep(11);
}
Thread.Sleep(4);
}
The Sleep right before calling WriteAsync() and the one at the end I had to add because without this I'm getting ErrorUnsupported (8/-35). Attached dump from this. I guessed it needs some time between operations so I added sleep.
When testing further testing with those timeouts I noticed that the tags are getting stuck in Pending state after a while and only re-connecting fixes this issue. Added another sleep in case of Pending state, which helped a bit. This happens in Release mode outside Visual Studio, I suspect without VS overhead the performance is different. Does tag timeout not work at all in async?
One inconvenience is that the tag takes more time to establish connection than for RW operations so I have to set a high Timeout (>100ms) which doesn't makes sense to me as then for tag RW I'd expect to timeout much faster than connection takes. Can I change tag timeout after successfully connected?
I think I'm doing something wrong, as I shouldn't use these timeouts, please give me some advice.
ab_server command for my tags is:
Snippet ab_server --plc=ControlLogix --path=1,0 --tag=tag1:DINT[10] --tag=tag2:DINT[10]