static void WriteOther(LogixTag tag, LogixProcessor processor) { Console.Write("Enter a value: "); string sValue = Console.ReadLine(); //Now we have to convert it to the right type... try { switch (tag.LogixType) { case LogixTypes.DInt: ((LogixDINT)tag).Value = Convert.ToInt32(sValue); break; case LogixTypes.Int: ((LogixINT)tag).Value = Convert.ToInt16(sValue); break; case LogixTypes.LInt: ((LogixLINT)tag).Value = Convert.ToInt64(sValue); break; case LogixTypes.Real: ((LogixREAL)tag).Value = Convert.ToSingle(sValue); break; case LogixTypes.SInt: ((LogixSINT)tag).Value = Convert.ToSByte(sValue); break; default: return; } //At this point the tag has not been committed to the processor. The //tag must be written, then read back for the value to change. The //easiest way to do this with a single tag is to use the processor //LogixProcessor.WriteRead() which performs the write, then the //subsequent read on the tag. processor.WriteRead(tag); } catch (Exception e) { Console.WriteLine("Could not convert " + sValue + " to the correct type for " + tag.Address); } }
static void WriteBool(LogixTag tag, LogixProcessor processor) { Console.WriteLine("Enter 1 for True, 0 for False: "); char key = Console.ReadKey().KeyChar; if (key == '1') { ((LogixBOOL)tag).Value = true; } else { ((LogixBOOL)tag).Value = false; } //At this point the tag has not been committed to the processor. The //tag must be written, then read back for the value to change. The //easiest way to do this with a single tag is to use the processor //LogixProcessor.WriteRead() which performs the write, then the //subsequent read on the tag. processor.WriteRead(tag); }
static void WriteStructure(LogixTag tag, LogixProcessor processor) { Console.Write("The tag is a structure called " + ((LogixUDT)tag).TypeName + ", please enter a member name: "); string memberName = Console.ReadLine(); //First we have to find out if the member exists, if it doesn't we can't write to it... List<string> memberNames = ((LogixUDT)tag).MemberNames; bool hasMember = false; for (int i = 0; i < memberNames.Count; i++) { if (string.Compare(memberNames[i], memberName) == 0) { hasMember = true; break; } } if (!hasMember) { Console.WriteLine("The specified member could not be found in the structure"); return; } Console.Write("Enter a value: "); string sValue = Console.ReadLine(); //Now we have to convert it to the right type... try { switch (tag.LogixType) { case LogixTypes.Bool: if (sValue == "1") ((LogixUDT)tag)[memberName] = true; else ((LogixUDT)tag)[memberName] = false; break; case LogixTypes.DInt: ((LogixUDT)tag)[memberName] = Convert.ToInt32(sValue); break; case LogixTypes.Int: ((LogixUDT)tag)[memberName] = Convert.ToInt16(sValue); break; case LogixTypes.LInt: ((LogixUDT)tag)[memberName] = Convert.ToInt64(sValue); break; case LogixTypes.Real: ((LogixUDT)tag)[memberName] = Convert.ToSingle(sValue); break; case LogixTypes.SInt: ((LogixUDT)tag)[memberName] = Convert.ToSByte(sValue); break; case LogixTypes.User_Defined: default: Console.WriteLine("This demo does not support writing to nested structure tags"); return; } //At this point the tag has not been committed to the processor. The //tag must be written, then read back for the value to change. The //easiest way to do this with a single tag is to use the processor //LogixProcessor.WriteRead() which performs the write, then the //subsequent read on the tag. processor.WriteRead(tag); } catch (Exception e) { Console.WriteLine("Could not convert " + sValue + " to the correct type for " + tag.Address); } }
static void WriteBool(LogixTag tag, LogixProcessor processor) { Console.WriteLine("Enter 1 for True, 0 for False: "); char key = Console.ReadKey().KeyChar; if (key == '1') ((LogixBOOL)tag).Value = true; else ((LogixBOOL)tag).Value = false; //At this point the tag has not been committed to the processor. The //tag must be written, then read back for the value to change. The //easiest way to do this with a single tag is to use the processor //LogixProcessor.WriteRead() which performs the write, then the //subsequent read on the tag. processor.WriteRead(tag); }
static void WriteStructure(LogixTag tag, LogixProcessor processor) { Console.Write("The tag is a structure called " + ((LogixUDT)tag).TypeName + ", please enter a member name: "); string memberName = Console.ReadLine(); //First we have to find out if the member exists, if it doesn't we can't write to it... List <string> memberNames = ((LogixUDT)tag).MemberNames; bool hasMember = false; for (int i = 0; i < memberNames.Count; i++) { if (string.Compare(memberNames[i], memberName) == 0) { hasMember = true; break; } } if (!hasMember) { Console.WriteLine("The specified member could not be found in the structure"); return; } Console.Write("Enter a value: "); string sValue = Console.ReadLine(); //Now we have to convert it to the right type... try { switch (tag.LogixType) { case LogixTypes.Bool: if (sValue == "1") { ((LogixUDT)tag)[memberName] = true; } else { ((LogixUDT)tag)[memberName] = false; } break; case LogixTypes.DInt: ((LogixUDT)tag)[memberName] = Convert.ToInt32(sValue); break; case LogixTypes.Int: ((LogixUDT)tag)[memberName] = Convert.ToInt16(sValue); break; case LogixTypes.LInt: ((LogixUDT)tag)[memberName] = Convert.ToInt64(sValue); break; case LogixTypes.Real: ((LogixUDT)tag)[memberName] = Convert.ToSingle(sValue); break; case LogixTypes.SInt: ((LogixUDT)tag)[memberName] = Convert.ToSByte(sValue); break; case LogixTypes.User_Defined: default: Console.WriteLine("This demo does not support writing to nested structure tags"); return; } //At this point the tag has not been committed to the processor. The //tag must be written, then read back for the value to change. The //easiest way to do this with a single tag is to use the processor //LogixProcessor.WriteRead() which performs the write, then the //subsequent read on the tag. processor.WriteRead(tag); } catch (Exception e) { Console.WriteLine("Could not convert " + sValue + " to the correct type for " + tag.Address); } }