Exemple #1
0
 public override void ScanRunResult()
 {
     //int i = 0;
     while (scanFlag)
     {
         this.ScanRestEvent.WaitOne();
         bool[] result = null;
         if (Key == "PCB")
         {
             result = this.ReadCoil(16, 1, "0", true);
         }
         if (RunResult != null && result != null)
         {
             IList <byte> idList = new List <byte>();
             for (byte i = 0; i < 16; i++)
             {
                 if (RunResult[i] ^ result[i])
                 {
                     idList.Add(i);
                 }
             }
             if (idList.Count > 0)
             {
                 OnChangeSampleRackStatus?.Invoke(idList.ToArray(), (byte)(result[idList[0]] ? 1 : 0));
             }
         }
         RunResult = result;
         Thread.Sleep(Constants.Timespan);//间隔时间
     }
 }
Exemple #2
0
        public void ScanRunResult()
        {
            this.CanComm.ReadRegister(OP.SampleRackCoils[0].Addr);
            var retval = this.CanComm.GetInt(OP.SampleRackCoils[0].Addr, 0x00);

            RunResult = retval < 0 ? null : this.CanComm.IntToBools(6, retval, true);
            while (scanFlag)
            {
                this.ScanRestEvent.WaitOne();
                this.CanComm.ClsRegisterMap(OP.SampleRackCoils[0].Addr);
                bool is_timeout = false;
                retval = this.CanComm.GetIntBlock(OP.SampleRackCoils[0].Addr, 1000, out is_timeout);
                bool[] result = retval < 0 ? null : this.CanComm.IntToBools(6, retval, true);
                if (result != null)
                {
                    result = result.Reverse().ToArray();
                }
                if (RunResult != null && result != null)
                {
                    IList <byte> idList = new List <byte>();
                    for (byte i = 0; i < 6; i++)
                    {
                        if (RunResult[i] ^ result[i])
                        {
                            idList.Add(i);
                        }
                    }
                    if (idList.Count > 0)
                    {
                        OnChangeSampleRackStatus?.Invoke(idList.ToArray(), (byte)(result[idList[0]] ? 1 : 0));
                    }
                }
                RunResult = result;
                Thread.Sleep(Constants.Timespan);//间隔时间
            }
        }