Beispiel #1
0
        public CCTimer(ITagOp tagOp, string tagName,
                       string outTagName, int onLast = 1000,
                       string offOutTagName          = "", int offLast = 1000)
            : base(tagName)
        {
            TagOp     = tagOp;
            OnLastMs  = onLast;
            OffLastMs = offLast;
            Func <bool?> check = () => {
                if (tagOp != null)
                {
                    return(tagOp.ReadBit(tagName));
                }
                else
                {
                    return(null);
                }
            };

            Name      = $"{tagName}-{outTagName}:{onLast}-{offOutTagName}:{offLast}";
            CheckFunc = check;
            OnLastMs  = onLast;
            OffLastMs = offLast;

            ThreadStart = new ControlledThreadStart(RunCheck);

            ThreadController = new ThreadController(ThreadStart, null, Name);

            StartThread();

            OutTag         = outTagName;
            OffOutTag      = offOutTagName;
            OutChanged    += Task_OutChanged;
            OffOutChanged += Task_OffOutChanged;
        }
Beispiel #2
0
 public static object ReadTag(this ITagOp tagOp, string tag)
 {
     if (!tagOp.CConnected)
     {
         return(null);
     }
     return(tagOp.InvokeFunc(() =>
     {
         return tagOp.ReadTagReal(tag);
     }));
 }
Beispiel #3
0
 public static void WriteTag(this ITagOp tagOp, string tag, object value)
 {
     if (!tagOp.CConnected)
     {
         return;
     }
     tagOp.InvokeAction(() =>
     {
         tagOp.WriteTagReal(tag, value);
     });
 }
Beispiel #4
0
 /// <summary>
 /// 反转位
 /// </summary>
 /// <param name="ps"></param>
 public static void InvertBit(this ITagOp tagOp, List <CCParameter> ps)
 {
     try
     {
         string tag = ps[0].DisplayValue;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
Beispiel #5
0
 /// <summary>
 /// 置位位
 /// </summary>
 /// <param name="ps"></param>
 public static void SetBit(this ITagOp tagOp, List <CCParameter> ps)
 {
     try
     {
         string tag = ps[0].DisplayValue;
         tagOp.WriteTag(tag, true);
     }
     catch (Exception ex)
     {
         Console.WriteLine("SetBit" + ex.ToString());
     }
 }
Beispiel #6
0
 public static void InvertBit(this ITagOp tagOp, string tag)
 {
     try
     {
         bool current = (bool)tagOp.ReadTag(tag);
         bool toggle  = !current;
         tagOp.WriteTag(tag, toggle);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
Beispiel #7
0
        private static object ReadTagReal(this ITagOp tagOp, string tag)
        {
            string[] tagNames = new string[1] {
                tag
            };
            ITag   itag   = tagOp.TAG;
            object result = itag.ReadTag(tagOp.RegisterCookie, tagNames);

            if (result is Array)
            {
                object[] ra = (object[])result;
                return(ra[0]);
            }
            return(result);
        }
Beispiel #8
0
 public static bool?ReadBit(this ITagOp tagOp, string tag)
 {
     try
     {
         var bit = tagOp.ReadTag(tag);
         if (bit == null)
         {
             return(null);
         }
         else
         {
             return((bool)bit);
         }
     }catch (Exception ex)
     {
     }
     return(null);
 }
Beispiel #9
0
 private static void WriteTagReal(this ITagOp tagOp, string tag, object value)
 {
     try
     {
         string[] tagNames = new string[1] {
             tag
         };
         object[] values = new object[1] {
             value
         };
         ITag itag = tagOp.TAG;
         itag.WriteTag(tagOp.RegisterCookie, tagNames, values);
     }
     catch (Exception ex)
     {
         ExceptionViewer ev = new ExceptionViewer("WriteTagReal", ex);
         ev.ShowDialog();
     }
 }