private void writeInt16Val(Tag tag, Libplctag client, Int16 value, bool print) { for (int i = 0; i < tag.ElementCount; i++) { client.SetInt16Value(tag, (i * tag.ElementSize), value); } if (print) { readInt16Val(tag, client); } }
private void setStringLength(Tag tag, Libplctag client, Int16 valLength) { client.SetInt16Value(tag, (0 * tag.ElementSize), valLength); }
private static bool RefreshTags(List <Tag> tags, Libplctag client) { foreach (var tag in tags) { if (tag.Name.StartsWith("F")) { /* get the data */ var rc = client.ReadTag(tag, DataTimeout); if (rc != Libplctag.PLCTAG_STATUS_OK) { LogError( $"{tag.Name} ERROR: Unable to read the data! Got error code {rc}: {client.DecodeError(rc)}"); return(false); } /* print out the data */ for (int i = 0; i < tag.ElementCount; i++) { Console.WriteLine($"{tag.Name} data[{i}]={client.GetFloat32Value(tag, (i*tag.ElementSize))}"); } /* now test a write */ for (int i = 0; i < tag.ElementCount; i++) { var val = client.GetFloat32Value(tag, (i * tag.ElementSize)); val++; if (val > 1000) { val = 0; } Console.WriteLine($"{tag.Name} Setting element {i} to {val}"); client.SetFloat32Value(tag, (i * tag.ElementSize), val); } rc = client.WriteTag(tag, DataTimeout); if (rc != Libplctag.PLCTAG_STATUS_OK) { LogError( $"{tag.Name} ERROR: Unable to read the data! Got error code {rc}: {client.DecodeError(rc)}"); return(false); } /* get the data again*/ rc = client.ReadTag(tag, DataTimeout); if (rc != Libplctag.PLCTAG_STATUS_OK) { LogError( $"{tag.Name} ERROR: Unable to read the data! Got error code {rc}: {client.DecodeError(rc)}"); return(false); } /* print out the data */ for (int i = 0; i < tag.ElementCount; i++) { Console.WriteLine($"{tag.Name} data[{i}]={client.GetFloat32Value(tag, (i*tag.ElementSize))}"); } } else { /* get the data */ var rc = client.ReadTag(tag, DataTimeout); if (rc != Libplctag.PLCTAG_STATUS_OK) { LogError( $"{tag.Name} ERROR: Unable to read the data! Got error code {rc}: {client.DecodeError(rc)}"); return(false); } /* print out the data */ for (int i = 0; i < tag.ElementCount; i++) { Console.WriteLine($"{tag.Name} data[{i}]={client.GetInt16Value(tag, (i*tag.ElementSize))}"); } if (!tag.Name.Contains("O") && !tag.Name.Contains("I")) // we can't write on I/O { /* now test a write */ for (int i = 0; i < tag.ElementCount; i++) { var val = client.GetInt16Value(tag, (i * tag.ElementSize)); val++; if (val > 1000) { val = 0; } Console.WriteLine($"{tag.Name} Setting element {i} to {val}"); client.SetInt16Value(tag, (i * tag.ElementSize), val); } rc = client.WriteTag(tag, DataTimeout); if (rc != Libplctag.PLCTAG_STATUS_OK) { LogError( $"{tag.Name} ERROR: Unable to write the data! Got error code {rc}: {client.DecodeError(rc)}"); return(false); } /* get the data again*/ rc = client.ReadTag(tag, DataTimeout); if (rc != Libplctag.PLCTAG_STATUS_OK) { LogError( $"{tag.Name} ERROR: Unable to read the data! Got error code {rc}: {client.DecodeError(rc)}"); return(false); } /* print out the data */ for (int i = 0; i < tag.ElementCount; i++) { Console.WriteLine($"{tag.Name} data[{i}]={client.GetInt16Value(tag, (i*tag.ElementSize))}"); } } } } return(true); }