Exemplo n.º 1
0
 public TcDaqStorage()
 {
     // Storage length = 10 minutes DAQ gathering length
     length     = (int)TcComm.ReadInt(tagDaqLength, ETcRunTime.RT1) / 2 * 5 * 60 * 10;
     values     = new float[length];
     fValueList = new List <float>(length / 2 / 30);
     dValueList = new List <double>(length / 2 / 30);
 }
Exemplo n.º 2
0
        private void DoThreadWork()
        {
            float[] tcValues    = null;
            float[] tcNewValues = null;
            int     tcLength    = TcComm.ReadInt(tagDaqLength, ETcRunTime.RT1) / 2;

            while (threadTerminated == false)
            {
                // Is a half of DAQ storage full?
                if (TcComm.ReadBool(tagDaqActive, ETcRunTime.RT1) == true)
                {
                    int tcIndex = TcComm.ReadInt(tagDaqIndex, ETcRunTime.RT1);
                    int tcStart = (tcIndex < tcLength) ? tcLength : 0;

                    // Read DAQ storage values from TwinCAT
                    tcValues = TcComm.ReadRealArray(tagDaqValues, tcLength * 2, ETcRunTime.RT1);

                    //Copy into newValues array
                    tcNewValues = new float[tcLength];
                    Array.Copy(tcValues, tcStart, tcNewValues, 0, tcLength);

                    // Reset DAQ half full flag
                    TcComm.WriteBool(tagDaqActive, false, ETcRunTime.RT1);

                    lock (dataLock)
                    {
                        Array.Copy(tcValues, tcStart, values, index, tcLength);
                        index = (index + tcLength) % length;
                    }

                    diState   = (UInt16)GetFloatValue(ETcRealTags.DI_24_None);
                    doState   = (UInt16)GetFloatValue(ETcRealTags.DO_25_None);
                    errorCode = (int)GetFloatValue(ETcRealTags.ID_27_ErrorCode);

                    try
                    {
                        OnDaqAvailable(new DaqEventArgs(tcNewValues));
                    }
                    catch (Exception ex)
                    {
                        Debug.Print(ex.ToString());
                    }
                }

                Thread.Sleep(1);
            }
        }