Пример #1
1
        public void StartReading()
        {
            //We always want to read SCAN_RATE samples per channel
            int scanRate = _daqs.Length * SCAN_RATE;
            int iteration = 0;
            while (_continueReading)
            {
                int memHandle = MccDaq.MccService.WinBufAlloc(scanRate);
                MccDaq.MccBoard theBoard = new MccDaq.MccBoard(0);
                ushort[] buffer = new ushort[scanRate];
                float[] outVal = new float[(int)scanRate];
                MccDaq.ErrorInfo stat = new MccDaq.ErrorInfo();
                int scannedRate = 1000;
                stat = theBoard.AInScan(0, _daqs.Length - 1, scanRate, ref scannedRate, MccDaq.Range.Bip5Volts, memHandle, MccDaq.ScanOptions.Default);
                stat = MccDaq.MccService.WinBufToArray(memHandle, out buffer[0], 0, scanRate);
                for (int i = 0; i < buffer.Length; i++)
                {
                    theBoard.ToEngUnits(MccDaq.Range.Bip5Volts, buffer[i], out outVal[i]);
                }
                MccDaq.MccService.WinBufFree(memHandle);

                Dictionary<IDAQ, IDAQPoint[]> readingDictionary = new Dictionary<IDAQ, IDAQPoint[]>();
                foreach (IDAQ daq in _daqs)
                {
                    readingDictionary.Add(daq, new IDAQPoint[SCAN_RATE]);
                }

                for (int i = 0; i < scanRate;)
                {
                    foreach (IDAQ daq in _daqs)
                    {
                        DAQChannel chDaq = (DAQChannel)daq;
                        ReadingDetail rd = new ReadingDetail();
                        int currentIndex = i / _daqs.Length;
                        rd.ParentChannel = chDaq;
                        rd.Time = currentIndex + (iteration * SCAN_RATE);
                        rd.Reading = outVal[i];
                        readingDictionary[daq][currentIndex] = rd;
                        chDaq.ReadingDetails.Add(rd);
                        i++;
                    }
                }
                iteration++;
                _dataRetrieved(readingDictionary);
            }
            lock (this)
            {
                _stopFinishedCallback();
            }
        }
Пример #2
0
        public float boardDataV()
        {
            float tempData;
            MccDaq.VInOptions options = MccDaq.VInOptions.Default;

            errorLog = board.VIn(chan, range, out tempData, options);
            if (errorLog.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                throw new ArgumentException("Error: " + errorLog.Value.ToString());
            }
            return tempData;
        }
Пример #3
0
        public float boardData()
        {
            ushort tempData;
            float convertedData;

            errorLog  = board.AIn(chan, range, out tempData);
            if (errorLog.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                throw new ArgumentException("Error: " + errorLog.Value.ToString());
            }

            convertedData = convertToVolts(tempData);
            return convertedData;
        }
Пример #4
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //  Initiate error handling
            //   activating error handling will trap errors like
            //   bad channel numbers and non-configured conditions.
            //   Parameters:
            //     MccDaq.ErrorReporting.PrintAll :all warnings and errors encountered will be printed
            //     MccDaq.ErrorHandling.StopAll   :if an error is encountered, the program will stop
            m_ErrorInfo = MccDaq.MccService.ErrHandling(MccDaq.ErrorReporting.PrintAll, MccDaq.ErrorHandling.StopAll);

            rbComma.Checked = true;
        }
        public int ReadGreenSensorValue()
        {
            rgbvalue = 0;
            MccDaq.ErrorInfo ULStat;
            int   channel = 1;
            Int16 datavalue;
            float engunits;

            MccDaq.Range range;

            range = MccDaq.Range.Bip10Volts;

            ULStat = DaqBoard.AIn(channel, range, out datavalue);
            if (ULStat.Value.Equals(MccDaq.ErrorInfo.ErrorCode.NoErrors))
            {
                DaqBoard.ToEngUnits(range, datavalue, out engunits);
                if (datavalue > 11059)
                {
                    rgbvalue = 9999;
                }
                else
                {
                    rgbvalue = (datavalue - 8192);// * RedSensorGain * RedTemperatureGain
                }
            }
            else if (ULStat.Value.Equals(MccDaq.ErrorInfo.ErrorCode.BadRange))
            {
                MessageBox.Show("Change the Range argument to one supported by this board.", ULStat.Message.ToString());
            }
            else
            {
                MessageBox.Show("Some Problem has occured with the board", ULStat.Message.ToString());
            }

            return(rgbvalue);
        }
        public string PressStartButonOnFixture()
        {
            MccDaq.ErrorInfo ULStat;
            string           return_value = MccDaq.ErrorInfo.ErrorCode.NoErrors.ToString();
            short            DataValue;

            ULStat = DaqBoard.DIn(MccDaq.DigitalPortType.FirstPortA, out DataValue);
            if (ULStat.Value.Equals(MccDaq.ErrorInfo.ErrorCode.NoErrors))
            {
                if (((DataValue & (1 << 0)) == 0))
                {
                    return_value = "Start";
                }
                else
                {
                    return_value = "Not Started";
                }
            }
            else
            {
                return_value = ULStat.Value.ToString();
            }
            return(return_value);
        }
Пример #7
0
        private void cmdEnableEvent_Click(object sender, System.EventArgs e)
        {
            /// Enable and connect one or more event types to a single user callback
            /// function using MccDaq.MccBoard.EnableEvent().
            ///
            /// If we want to attach a single callback function to more than one event
            /// type, we can do it in a single call to MccDaq.MccBoard.EnableEvent, or we can do this in
            /// separate calls for each event type. The main disadvantage of doing this in a
            /// single call is that if the call generates an error, we will not know which
            /// event type caused the error. In addition, the same error condition could
            /// generate multiple error messages.
            ///
            /// Parameters:
            ///   eventType   :the condition that will cause an event to fire
            ///   eventSize   :only used for MccDaq.EventType.OnDataAvailable to determine how
            ///               many samples to collect before firing an event
            ///   _ptrMyCallback : a pointer to the user function or event handler
            ///                     to call when above event type occurs. Note that the handler
            ///						can be a delegate or a static member function. Here, we use
            ///						a pointer to a static member function.
            ///
            ///   _ptrUserData  : a pointer to a value type that will be used within the event
            ///					   handler. Since our handler is a static member function which
            ///					   does NOT include a reference to this class instance, we're
            ///					   sending the pointer to a struct that holds a reference to the class.

            MccDaq.EventType eventType = MccDaq.EventType.OnDataAvailable;
            eventType |= MccDaq.EventType.OnEndOfAiScan;

            uint eventSize = (uint)this.EventSize.Value;

            MccDaq.ErrorInfo ULStat = DaqBoard.EnableEvent(eventType, eventSize, _ptrMyCallback, _ptrUserData);

            eventType = MccDaq.EventType.OnScanError;
            ULStat    = DaqBoard.EnableEvent(eventType, 0, _ptrOnScanError, _ptrUserData);
        }
Пример #8
0
        private void frmLoggerData_Load(object sender, EventArgs e)
        {
            //  Initiate error handling
            //   activating error handling will trap errors like
            //   bad channel numbers and non-configured conditions.
            //   Parameters:
            //     MccDaq.ErrorReporting.DontPrint :all warnings and errors encountered will be handled locally
            //     MccDaq.ErrorHandling.DontStop   :if an error is encountered, the program will not stop,
            //      errors will be handled locally.

            MccDaq.ErrorInfo ULStat = MccDaq.MccService.ErrHandling
                                          (MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.DontStop);

            //  Get the first file in the directory
            //   Parameters:
            //     MccDaq.GetFileOptions.GetFirst :first file
            //     m_Path						  :path to search
            //	   filename						  :receives name of file
            string filename = new string(' ', MAX_PATH);

            ULStat = MccDaq.DataLogger.GetFileName
                         ((int)MccDaq.GetFileOptions.GetFirst, ref m_Path, ref filename);
            filename = filename.Trim();
            filename = filename.Trim('\0');

            // create an instance of the data logger
            logger = new MccDaq.DataLogger(filename);


            //  Set the preferences
            //    Parameters
            //      timeFormat					  :specifies times are 12 or 24 hour format
            //      timeZone					  :specifies local time of GMT
            //      units						  :specifies Fahrenheit, Celsius, or Kelvin
            MccDaq.TimeFormat timeFormat = MccDaq.TimeFormat.TwelveHour;
            MccDaq.TimeZone   timeZone   = MccDaq.TimeZone.Local;
            MccDaq.TempScale  units      = MccDaq.TempScale.Fahrenheit;
            logger.SetPreferences(timeFormat, timeZone, units);


            //  Get the sample info for the first file in the directory
            //   Parameters:
            //     sampleInterval					 :receives the sample interval (time between samples)
            //     sampleCount						 :receives the sample count
            //	   startDate						 :receives the start date
            //	   startTime						 :receives the start time
            int sampleInterval = 0;
            int startDate      = 0;
            int startTime      = 0;

            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                ULStat = logger.GetSampleInfo(ref sampleInterval, ref SampleCount, ref startDate, ref startTime);
            }

            //  Get the ANALOG channel count for the first file in the directory
            //   Parameters:
            //	   aiChannelCount					:receives the number of AI chennels logged
            int aiChannelCount = 0;

            if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                ULStat = logger.GetAIChannelCount(ref aiChannelCount);
            }
        }
Пример #9
0
        private void cmdCJCData_Click(object sender, EventArgs e)
        {
            int    Hour, Minute, Second;
            int    Month, Day, Year;
            int    Postfix;
            string PostfixStr, StartDateStr, DataListStr;
            string StartTimeStr, lbDataStr;
            int    StartSample, i, j;

            int[] DateTags;
            int[] TimeTags;
            int   Index;

            float[] CJCChannelData;
            int     CJCChannelCount = 0;
            string  UnitList, ChanList;
            int     ListSize;

            // Get the Digital channel count
            //   Parameters:
            //	   CJCChannelCount		:receives the number of DIO chennels logged

            ULStat      = logger.GetCJCInfo(ref CJCChannelCount);
            ChanList    = "";
            UnitList    = "";
            StartSample = 0;
            if (ULStat.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                txtData.Text = ULStat.Message;
            }
            else
            {
                CJCChannelData = new float[SampleCount * CJCChannelCount];
                if ((CJCChannelCount > 0) & (SampleCount > 0))
                {
                    DataListStr = "Time" + "\t" + "\t" + ChanList + "\r\n" +
                                  "\t" + "\t" + UnitList + "\r\n" + "\r\n";

                    DateTags = new int[SampleCount];
                    TimeTags = new int[SampleCount];
                    ULStat   = logger.ReadTimeTags(StartSample, SampleCount, ref DateTags, ref TimeTags);

                    CJCChannelData = new float[SampleCount * CJCChannelCount];
                    ULStat         = logger.ReadCJCChannels(StartSample, SampleCount, ref CJCChannelData);

                    ListSize = SampleCount;
                    if (ListSize > 50)
                    {
                        ListSize = 50;
                    }
                    PostfixStr = "";
                    for (i = 0; i < ListSize; i++)
                    {
                        //Parse the date from the StartDate parameter
                        Month        = (DateTags[i] >> 8) & 0xff;
                        Day          = DateTags[i] & 0xff;
                        Year         = (DateTags[i] >> 16) & 0xff;
                        StartDateStr = Month.ToString("00") + "/" +
                                       Day.ToString("00") + "/" + Year.ToString("0000");

                        //Parse the time from the StartTime parameter
                        Hour    = (TimeTags[i] >> 16) & 0xff;
                        Minute  = (TimeTags[i] >> 8) & 0xff;
                        Second  = TimeTags[i] & 0xff;
                        Postfix = (TimeTags[i] >> 24) & 0xff;
                        if (Postfix == 0)
                        {
                            PostfixStr = " AM";
                        }
                        if (Postfix == 1)
                        {
                            PostfixStr = " PM";
                        }
                        StartTimeStr = Hour.ToString("00") + ":" +
                                       Minute.ToString("00") + ":" + Second.ToString("00")
                                       + PostfixStr + "\t";
                        Index     = i * CJCChannelCount;
                        lbDataStr = "";
                        for (j = 0; j < CJCChannelCount; j++)
                        {
                            lbDataStr = lbDataStr + CJCChannelData[Index + j].ToString("0.00") + "\t";
                        }

                        DataListStr = DataListStr + StartDateStr + "  " + StartTimeStr + lbDataStr + "\r\n";
                    }
                    txtData.Text = "CJC data from " + logger.FileName + "\r\n" + "\r\n" + DataListStr;
                }
                else
                {
                    txtData.Text = "There is no CJC data in " + logger.FileName + ".";
                }
            }
        }
Пример #10
0
        private void cmdAnalogData_Click(object sender, EventArgs e)
        {
            int aiChannelCount = 0;

            float[] aiChannelData;
            int[]   ChannelNumbers;
            int[]   Units;
            int     i, j, ListSize, Index;
            string  DataListStr, StartTimeStr, lbDataStr;
            string  ChansStr, UnitsStr, ChanList, UnitList;
            string  PostfixStr, StartDateStr;

            int[] DateTags;
            int[] TimeTags;
            int   StartSample = 0;
            int   Hour, Minute, Second, Postfix;
            int   Month, Day, Year;

            //  Get the ANALOG info for the first file in the directory
            //   Parameters:
            //     channelMask		:receives the channel mask to specify which channels were logged
            //     unitMask			:receives the unit mask to specify temp or raw data

            ULStat = logger.GetAIChannelCount(ref aiChannelCount);
            if (ULStat.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                txtData.Text = ULStat.Message;
            }
            else
            {
                // Get the Analog information
                //  Parameters:
                //    Filename                :name of file to get information from
                //    ChannelNumbers          :array containing channel numbers that were logged
                //    Units                   :array containing the units for each channel that was logged
                //    AIChannelCount          :number of analog channels logged

                if ((aiChannelCount > 0) && (SampleCount > 0))
                {
                    ChannelNumbers = new int[aiChannelCount];
                    Units          = new int[aiChannelCount];
                    ULStat         = logger.GetAIInfo(ref ChannelNumbers, ref Units);
                    ChanList       = "";
                    UnitList       = "";
                    if (ULStat.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
                    {
                        txtData.Text = ULStat.Message;
                    }
                    else
                    {
                        for (i = 0; i < aiChannelCount; i++)
                        {
                            ChansStr = ChannelNumbers[i].ToString();
                            UnitsStr = "Temp";
                            if (Units[i] == (int)MccDaq.LoggerUnits.Raw)
                            {
                                UnitsStr = "Raw";
                            }
                            ChanList = ChanList + "Chan" + ChansStr + "\t";
                            UnitList = UnitList + UnitsStr + "\t";
                        }
                    }
                    DataListStr = "Time" + "\t" + "\t" + ChanList + "\r\n" +
                                  "\t" + "\t" + UnitList + "\r\n" + "\r\n";
                    DateTags = new int[SampleCount];
                    TimeTags = new int[SampleCount];
                    ULStat   = logger.ReadTimeTags(StartSample, SampleCount, ref DateTags, ref TimeTags);
                    if (ULStat.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
                    {
                        txtData.Text = ULStat.Message;
                    }

                    aiChannelData = new float[SampleCount * aiChannelCount];
                    ULStat        = logger.ReadAIChannels(StartSample, SampleCount, ref aiChannelData);
                    ListSize      = SampleCount;
                    if (ListSize > 50)
                    {
                        ListSize = 50;
                    }
                    PostfixStr = "";
                    for (i = 0; i <= ListSize; i++)
                    {
                        //Parse the date from the StartDate parameter
                        Month        = (DateTags[i] >> 8) & 0xff;
                        Day          = DateTags[i] & 0xff;
                        Year         = (DateTags[i] >> 16) & 0xff;
                        StartDateStr = Month.ToString("00") + "/" +
                                       Day.ToString("00") + "/" + Year.ToString("0000");

                        //Parse the time from the StartTime parameter
                        Hour    = (TimeTags[i] >> 16) & 0xff;
                        Minute  = (TimeTags[i] >> 8) & 0xff;
                        Second  = TimeTags[i] & 0xff;
                        Postfix = (TimeTags[i] >> 24) & 0xff;
                        if (Postfix == 0)
                        {
                            PostfixStr = " AM";
                        }
                        if (Postfix == 1)
                        {
                            PostfixStr = " PM";
                        }
                        StartTimeStr = Hour.ToString("00") + ":" +
                                       Minute.ToString("00") + ":" + Second.ToString("00")
                                       + PostfixStr;
                        Index     = i * aiChannelCount;
                        lbDataStr = "";
                        for (j = 0; j < aiChannelCount; j++)
                        {
                            lbDataStr = lbDataStr + "\t" + aiChannelData[Index + j].ToString("0.00");
                        }

                        DataListStr = DataListStr + StartDateStr + "  " + StartTimeStr + lbDataStr + "\r\n";
                    }
                    txtData.Text = "Analog data from " + logger.FileName + "\r\n" + "\r\n" + DataListStr;
                }
                else
                {
                    txtData.Text = "There is no analog data in " + logger.FileName + ".";
                }
            }
        }
Пример #11
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //  Initiate error handling
            //   activating error handling will trap errors like
            //   bad channel numbers and non-configured conditions.
            //   Parameters:
            //     MccDaq.ErrorReporting.PrintAll :all warnings and errors encountered will be printed
            //     MccDaq.ErrorHandling.StopAll   :if an error is encountered, the program will stop
            MccDaq.ErrorInfo errorInfo = MccDaq.MccService.ErrHandling(MccDaq.ErrorReporting.PrintAll, MccDaq.ErrorHandling.StopAll);


            //  Get the first file in the directory
            //   Parameters:
            //     MccDaq.GetFileOptions.GetFirst :first file
            //     m_Path						  :path to search
            //	   filename						  :receives name of file
            string filename = new string('\0', MAX_PATH);

            errorInfo = MccDaq.DataLogger.GetFileName((int)MccDaq.GetFileOptions.GetFirst, ref m_Path, ref filename);


            // create an instance of the data logger
            MccDaq.DataLogger logger = new MccDaq.DataLogger(filename);


            //  Set the preferences
            //    Parameters
            //      timeFormat					  :specifies times are 12 or 24 hour format
            //      timeZone					  :specifies local time of GMT
            //      units						  :specifies Fahrenheit, Celsius, or Kelvin
            MccDaq.TimeFormat timeFormat = MccDaq.TimeFormat.TwelveHour;
            MccDaq.TimeZone   timeZone   = MccDaq.TimeZone.Local;
            MccDaq.TempScale  units      = MccDaq.TempScale.Fahrenheit;
            logger.SetPreferences(timeFormat, timeZone, units);


            //  Get the sample info for the first file in the directory
            //   Parameters:
            //     sampleInterval					 :receives the sample interval (time between samples)
            //     sampleCount						 :receives the sample count
            //	   startDate						 :receives the start date
            //	   startTime						 :receives the start time
            int sampleInterval = 0;
            int sampleCount    = 0;
            int startDate      = 0;
            int startTime      = 0;

            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.GetSampleInfo(ref sampleInterval, ref sampleCount, ref startDate, ref startTime);
            }


            //  Get the ANALOG channel count for the first file in the directory
            //   Parameters:
            //	   aiChannelCount					:receives the number of AI chennels logged
            int aiChannelCount = 0;

            float [] aiChannelData = null;
            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.GetAIChannelCount(ref aiChannelCount);
                if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    aiChannelData = new float [sampleCount * aiChannelCount];
                }
            }


            //  Get the CJC info for the first file in the directory
            //   Parameters:
            //	   cjcChannelCount					:receives the number of CJC chennels logged
            int cjcChannelCount = 0;

            float [] cjcChannelData = null;
            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.GetCJCInfo(ref cjcChannelCount);
                if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    cjcChannelData = new float [sampleCount * cjcChannelCount];
                }
            }


            //  Get the DIO info for the first file in the directory
            //   Parameters:
            //	   dioChannelCount					:receives the number of DIO chennels logged
            int dioChannelCount = 0;

            int [] dioChannelData = null;
            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.GetDIOInfo(ref dioChannelCount);
                if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    dioChannelData = new int [sampleCount * dioChannelCount];
                }
            }


            //  Read the time tag information
            //   Parameters:
            //	   startSample						:first sample to read
            //	   sampleCount						:number of samples to read
            //     dateTags							:receives the date tag information
            //     timeTags							:receives the time tag information
            int startSample = 0;

            int [] dateTags = new int [sampleCount];
            int [] timeTags = new int [sampleCount];
            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.ReadTimeTags(startSample, sampleCount, ref dateTags, ref timeTags);
            }


            //  Read the Analog data
            //   Parameters:
            //	   startSample						:first sample to read
            //	   sampleCount						:number of samples to read
            //     aiChannelData					:receives the analog data
            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.ReadAIChannels(startSample, sampleCount, ref aiChannelData);
            }


            //  Read the CJC data
            //   Parameters:
            //	   startSample						:first sample to read
            //	   sampleCount						:number of samples to read
            //     cjcChannelData					:receives the cjc data
            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.ReadCJCChannels(startSample, sampleCount, ref cjcChannelData);
            }


            //  Read the DIO data
            //   Parameters:
            //	   startSample						:first sample to read
            //	   sampleCount						:number of samples to read
            //     dioChannelData					:receives the dio data
            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.ReadDIOChannels(startSample, sampleCount, ref dioChannelData);
            }


            // display the data in teh list box
            string displayStr;
            string dateStr;
            string timeStr;
            string postfix;
            int    index;

            for (int i = 0; i < sampleCount; i++)
            {
                int date = dateTags[i];
                int time = timeTags[i];

                int day   = date & 0xff;
                int month = (date >> 8) & 0xff;
                int year  = (date >> 16) & 0xffff;
                dateStr = month.ToString() + "/" + day.ToString() + "/" + year.ToString();

                switch ((time >> 24) & 0xff)
                {
                case 0:
                    postfix = " AM";
                    break;

                case 1:
                    postfix = " PM";
                    break;

                case -1:
                    postfix = "";
                    break;

                default:
                    postfix = "";
                    break;
                }
                int hours   = (time >> 16) & 0xff;
                int minutes = (time >> 8) & 0xff;
                int seconds = (time) & 0xff;
                timeStr = hours.ToString() + ":" + minutes.ToString() + ":" + seconds.ToString() + ":" + postfix;

                displayStr = dateStr + "  " + timeStr;

                if (aiChannelCount > 0)
                {
                    index = i * aiChannelCount;
                    for (int j = 0; j < aiChannelCount; j++)
                    {
                        displayStr += "\t\t" + aiChannelData[index++].ToString();
                    }
                }

                if (cjcChannelCount > 0)
                {
                    index = i * cjcChannelCount;
                    for (int j = 0; j < cjcChannelCount; j++)
                    {
                        displayStr += "\t\t" + cjcChannelData[index++].ToString();
                    }
                }

                if (dioChannelCount > 0)
                {
                    index = i * dioChannelCount;
                    for (int j = 0; j < dioChannelCount; j++)
                    {
                        displayStr += "\t" + dioChannelData[index++].ToString();
                    }
                }

                lbData.Items.Add(displayStr);
            }


            if (errorInfo.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                MessageBox.Show(errorInfo.Message);
                return;
            }
        }
Пример #12
0
 private void btnFlash_Click(object sender, System.EventArgs e)
 {
     //Flash the LED
     MccDaq.ErrorInfo ULStat = DaqBoard.FlashLED();
 }
        public float ReadOutVoltage()
        {
            MccDaq.ErrorInfo ULStat;
            MccDaq.Range     range;
            ushort           datavalue  = 0;
            ushort           datavalue1 = 0;
            ushort           datavalue2 = 0;
            ushort           datavalue3 = 0;
            ushort           datavalue4 = 0;
            int   chanel    = 2;
            float engunits  = 0;
            bool  saveState = false;

            saveState = ViewModel.TestFixtureViewModel.isStartPressed;

            //Suspend the button read in the "ListenToStartEvent" thread unconditionally to keep start thread alive
            ViewModel.TestFixtureViewModel.isStartPressed = true;

            ULStat = DaqBoard.DBitOut(MccDaq.DigitalPortType.FirstPortA, 8, MccDaq.DigitalLogicState.Low); // select load sense resistor
            ULStat = DaqBoard.DConfigPort(MccDaq.DigitalPortType.FirstPortA, MccDaq.DigitalPortDirection.DigitalOut);
            ULStat = DaqBoard.DBitOut(MccDaq.DigitalPortType.FirstPortA, 6, MccDaq.DigitalLogicState.Low); // set sense resistor voltage to 0

            System.Threading.Thread.Sleep(2000);

            ULStat = DaqBoard.DBitOut(MccDaq.DigitalPortType.FirstPortA, 6, MccDaq.DigitalLogicState.High); // set sense resistor voltage to 5V
            //System.Threading.Thread.Sleep(10);// wait for capacitors to charge a little

            range  = MccDaq.Range.Bip10Volts;
            ULStat = DaqBoard.AInputMode(MccDaq.AInputMode.Differential);

            ULStat = DaqBoard.AIn(chanel, range, out datavalue1);
            System.Threading.Thread.Sleep(5);

            ULStat = DaqBoard.AIn(chanel, range, out datavalue2);
            System.Threading.Thread.Sleep(5);

            ULStat = DaqBoard.AIn(chanel, range, out datavalue3);
            System.Threading.Thread.Sleep(5);

            ULStat = DaqBoard.AIn(chanel, range, out datavalue4);
            System.Threading.Thread.Sleep(5);

            datavalue += datavalue1;
            datavalue += datavalue2;
            datavalue += datavalue3;
            datavalue += datavalue4;
            datavalue /= 4;

            if (ULStat.Value.Equals(MccDaq.ErrorInfo.ErrorCode.NoErrors))
            {
                DaqBoard.ToEngUnits(range, datavalue, out engunits);
            }
            else if (ULStat.Value.Equals(MccDaq.ErrorInfo.ErrorCode.BadRange))
            {
                //MessageBox.Show("Change the Range argument to one supported by this board.", ULStat.Message.ToString());
                frmTestFixture.Instance.WriteToLog("Change the Range argument to one supported by this board." + Environment.NewLine + ULStat.Message.ToString(), ApplicationConstants.TraceLogType.Error);
            }
            else
            {
                //MessageBox.Show("Some Problem has occured with the board", ULStat.Message.ToString());
                frmTestFixture.Instance.WriteToLog("Some Problem has occured with the board." + Environment.NewLine + ULStat.Message.ToString(), ApplicationConstants.TraceLogType.Error);
            }
            ULStat = DaqBoard.DConfigPort(MccDaq.DigitalPortType.FirstPortA, MccDaq.DigitalPortDirection.DigitalIn);
            ULStat = DaqBoard.AInputMode(MccDaq.AInputMode.SingleEnded);

            ViewModel.TestFixtureViewModel.isStartPressed = saveState;

            return(engunits);
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Tmr_Torniquete2_Tick(object sender, EventArgs e)
        {
            try
            {
                Tmr_Torniquete2.Stop();
                short DataValue = 0;
                Acceso_Museo.App_Code.Negocio.Cls_Ope_Accesos_Negocio Acceso_Negocio = new App_Code.Negocio.Cls_Ope_Accesos_Negocio();

                MccDaq.ErrorInfo ULStat = DaqBoard.DIn(PortNum, out DataValue);

                int resul = DataValue & (1 << 1);


                if (resul != 0)
                {
                    if (First_T2)
                    {
                        First_T2 = false;
                    }
                    else
                    {
                        short            DataValue2 = 0;
                        MccDaq.ErrorInfo ULStat2    = DaqBoard.DIn(PortNum, out DataValue2);

                        int resul2 = DataValue2 & (1 << 3);

                        if (resul2 != 0)
                        {
                            Acceso_Negocio.P_No_Acceso         = Codigo_Lector2;
                            Acceso_Negocio.P_Terminal_ID       = "00001";
                            Acceso_Negocio.P_Estatus           = "UTILIZADO";
                            Acceso_Negocio.P_Fecha_Hora_Acceso = DateTime.Now;
                            Acceso_Negocio.Actualizar_Estatus_Acceso();
                        }
                    }
                }
                else
                {
                    if (!First_T2)
                    {
                        if (!Serial1.IsOpen)
                        {
                            Serial1.Open();
                        }

                        Codigo_Lector2          = string.Empty;
                        Codigo_Lector3          = string.Empty;
                        First_T2                = true;
                        Tmr_Torniquete2.Enabled = false;
                        Lector2 = true;

                        Serial1.DiscardInBuffer();
                        Serial1.DiscardOutBuffer();
                    }
                }

                Tmr_Torniquete2.Start();
            }
            catch (Exception ex)
            {
                var d = ex.Message;
            }
        }
Пример #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Tmr_Torniquete3_Tick(object sender, EventArgs e)
        {
            TimeSpan Tiempo_Transcurrido = new TimeSpan();

            try
            {
                Tmr_Torniquete3.Stop();


                short DataValue = 0;
                Acceso_Museo.App_Code.Negocio.Cls_Ope_Accesos_Negocio Acceso_Negocio = new App_Code.Negocio.Cls_Ope_Accesos_Negocio();

                MccDaq.ErrorInfo ULStat = DaqBoard.DIn(PortNum, out DataValue);

                int resul = DataValue & (1 << 0);


                if (resul == 1)
                {
                    Lector3 = false;


                    if (First_T1)
                    {
                        First_T1 = false;
                    }
                    else
                    {
                        short            DataValue2 = 0;
                        MccDaq.ErrorInfo ULStat2    = DaqBoard.DIn(PortNum, out DataValue2);


                        int resul2 = DataValue2 & (1 << 2);

                        if (!System.IO.Directory.Exists("reportes"))
                        {
                            System.IO.Directory.CreateDirectory("reportes");
                        }

                        System.IO.File.WriteAllText("reportes/ex-" + DateTime.Now.ToString("dd-MM-yyyy_HH_mm_ss") + ".txt", " " + resul2.ToString() + "\n");

                        if (resul2 != 0)
                        {
                            if (!System.IO.Directory.Exists("reportes"))
                            {
                                System.IO.Directory.CreateDirectory("reportes");
                            }

                            System.IO.File.WriteAllText("reportes/ex-" + DateTime.Now.ToString("dd-MM-yyyy_HH_mm_ss") + ".txt", resul2.ToString() + "\n");

                            Acceso_Negocio.P_No_Acceso         = Codigo_Lector3;
                            Acceso_Negocio.P_Terminal_ID       = "00001";
                            Acceso_Negocio.P_Estatus           = "UTILIZADO";
                            Acceso_Negocio.P_Fecha_Hora_Acceso = DateTime.Now;
                            Acceso_Negocio.Actualizar_Estatus_Acceso();

                            First_T1                = true;
                            Codigo_Lector3          = string.Empty;
                            Tmr_Torniquete3.Enabled = false;
                        }
                    }
                }
                else
                {
                    Lector3 = true;

                    if (!First_T1)
                    {
                        First_T1                = true;
                        Codigo_Lector3          = string.Empty;
                        Tmr_Torniquete3.Enabled = false;
                    }
                }

                Tmr_Torniquete3.Start();
            }
            catch (Exception ex)
            {
                First_T1                = true;
                Codigo_Lector3          = string.Empty;
                Tmr_Torniquete3.Enabled = false;
                Lector3 = true;

                MessageBox.Show("Error: " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Пример #16
0
 private float convertToVolts(ushort datos)
 {
     float temp;
     errorLog = board.ToEngUnits(range, datos, out temp);
     if (errorLog.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
     {
         throw new ArgumentException("Error: " + errorLog.Value.ToString());
     }
     return temp;
 }
Пример #17
0
        private void OnButtonClick_OK(object sender, System.EventArgs e)
        {
            // create an instance of the data logger
            MccDaq.DataLogger logger = new MccDaq.DataLogger(m_SrcFilename);

            //  Get the sample info for the first file in the directory
            //   Parameters:
            //     sampleInterval					 :receives the sample interval (time between samples)
            //     sampleCount						 :receives the sample count
            //	   startDate						 :receives the start date
            //	   startTime						 :receives the start time
            int	sampleInterval = 0;
            int	sampleCount = 0;
            int	startDate = 0;
            int startTime = 0;
            m_ErrorInfo = logger.GetSampleInfo(ref sampleInterval, ref sampleCount, ref startDate, ref startTime);

            // get the destination path from the source file name
            int index = m_SrcFilename.LastIndexOf(".");
            string m_DestFilename = m_SrcFilename.Substring(0, index+1) + "csv";

            //  convert the file
            //   Parameters:
            //     m_DestFilename					 :destination file
            //     startSample						 :first sample to convert
            //     sampleCount						 :number of samples to convert
            //	   m_Delimiter						 :field seperator
            int startSample = 0;
            if (m_ErrorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                m_ErrorInfo = logger.ConvertFile(m_DestFilename, startSample, sampleCount, m_Delimiter);
            }

            if (m_ErrorInfo.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                MessageBox.Show(m_ErrorInfo.Message);
                return;
            }
        }
Пример #18
0
        private void cmdSampInfo_Click(object sender, EventArgs e)
        {
            int    Hour, Minute, Second;
            int    Month, Day, Year;
            int    SampleInterval, SampleCount;
            int    StartDate, StartTime;
            int    Postfix;
            string PostfixStr, StartDateStr;
            string StartTimeStr;

            PostfixStr     = "";
            SampleInterval = 0;
            SampleCount    = 0;
            StartDate      = 0;
            StartTime      = 0;

            // Get the sample information
            //  Parameters:
            //    Filename            :name of file to get information from
            //    SampleInterval      :time between samples
            //    SampleCount         :number of samples in the file
            //    StartDate           :date of first sample
            //    StartTime           :time of first sample

            ULStat = logger.GetSampleInfo(ref SampleInterval, ref SampleCount, ref StartDate, ref StartTime);
            if (ULStat.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                lblComment.Text = ULStat.Message + ".";
            }
            else
            {
                //Parse the date from the StartDate parameter
                Month        = (StartDate >> 8) & 0xff;
                Day          = StartDate & 0xff;
                Year         = (StartDate >> 16) & 0xffff;
                StartDateStr = Month.ToString("00") + "/" +
                               Day.ToString("00") + "/" + Year.ToString("0000");

                //Parse the time from the StartTime parameter
                Hour    = (StartTime >> 16) & 0xffff;
                Minute  = (StartTime >> 8) & 0xff;
                Second  = StartTime & 0xff;
                Postfix = (StartTime >> 24) & 0xff;
                if (Postfix == 0)
                {
                    PostfixStr = " AM";
                }
                if (Postfix == 1)
                {
                    PostfixStr = " PM";
                }
                StartTimeStr = Hour.ToString("00") + ":" +
                               Minute.ToString("00") + ":" + Second.ToString("00")
                               + PostfixStr;

                txtResults.Text =
                    "The sample properties of '" + logger.FileName + "' are:" +
                    "\r\n" + "\r\n" + "\t" + "SampleInterval: " + "\t" +
                    SampleInterval.ToString("0") + "\r\n" + "\t" + "SampleCount: " +
                    "\t" + SampleCount.ToString("0") + "\r\n" + "\t" +
                    "Start Date: " + "\t" + StartDateStr + "\r\n" + "\t" +
                    "Start Time: " + "\t" + StartTimeStr;
            }
        }
Пример #19
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //  Initiate error handling
            //   activating error handling will trap errors like
            //   bad channel numbers and non-configured conditions.
            //   Parameters:
            //     MccDaq.ErrorReporting.PrintAll :all warnings and errors encountered will be printed
            //     MccDaq.ErrorHandling.StopAll   :if an error is encountered, the program will stop
            MccDaq.ErrorInfo errorInfo = MccDaq.MccService.ErrHandling(MccDaq.ErrorReporting.PrintAll, MccDaq.ErrorHandling.StopAll);


            //  Get the first file in the directory
            //   Parameters:
            //     MccDaq.GetFileOptions.GetFirst :first file
            //     m_Path						  :path to search
            //	   filename						  :receives name of file
            string filename = new string('\0', MAX_PATH);

            errorInfo = MccDaq.DataLogger.GetFileName((int)MccDaq.GetFileOptions.GetFirst, ref m_Path, ref filename);
            string newpath      = filename.TrimEnd('\0');
            string absolutePath = Path.GetFullPath(newpath);

            // create an instance of the data logger
            MccDaq.DataLogger logger = new MccDaq.DataLogger(filename);


            //  Get the file info for the first file in the directory
            //   Parameters:
            //     filename						  :file to retrieve information from
            //     version						  :receives the version of the file
            //	   size							  :receives the size of file
            int version = 0;
            int size    = 0;

            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.GetFileInfo(ref version, ref size);
                if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    lblFilename.Text    = absolutePath;
                    lblFileVersion.Text = version.ToString();
                    lblFileSize.Text    = size.ToString();
                }
            }

            //  Get the sample info for the first file in the directory
            //   Parameters:
            //     sampleInterval					 :receives the sample interval (time between samples)
            //     sampleCount						 :receives the sample count
            //	   startDate						 :receives the start date
            //	   startTime						 :receives the start time
            int sampleInterval = 0;
            int sampleCount    = 0;
            int startDate      = 0;
            int startTime      = 0;

            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.GetSampleInfo(ref sampleInterval, ref sampleCount, ref startDate, ref startTime);
                if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    lblSampleInterval.Text = sampleInterval.ToString();
                    lblSampleCount.Text    = sampleCount.ToString();

                    int    day     = startDate & 0xff;
                    int    month   = (startDate >> 8) & 0xff;
                    int    year    = (startDate >> 16) & 0xffff;
                    string dateStr = month.ToString() + "/" + day.ToString() + "/" + year.ToString();
                    lblStartDate.Text = dateStr;

                    string postfix;
                    switch ((startTime >> 24) & 0xff)
                    {
                    case 0:
                        postfix = " AM";
                        break;

                    case 1:
                        postfix = " PM";
                        break;

                    case -1:
                        postfix = "";
                        break;

                    default:
                        postfix = "";
                        break;
                    }
                    int    hours   = (startTime >> 16) & 0xff;
                    int    minutes = (startTime >> 8) & 0xff;
                    int    seconds = (startTime) & 0xff;
                    string timeStr = hours.ToString() + ":" + minutes.ToString() + ":" + seconds.ToString() + ":" + postfix;
                    lblStartTime.Text = timeStr;
                }
            }


            //  Get the ANALOG channel count for the first file in the directory
            //   Parameters:
            //     channelMask						:receives the channel mask to specify which channels were logged
            //     unitMask							:receives the unit mask to specify temp or raw data
            //	   aiChannelCount					:receives the number of AI chennels logged
            int aiChannelCount = 0;

            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.GetAIChannelCount(ref aiChannelCount);
                if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    lblAIChannelCount.Text = aiChannelCount.ToString();
                }
            }


            //  Get the ANALOG info for the first file in the directory
            //   Parameters:
            //     channelMask						:receives the channel mask to specify which channels were logged
            //     unitMask							:receives the unit mask to specify temp or raw data
            int [] channelNumbers;
            int [] units;

            channelNumbers = new int[aiChannelCount];
            units          = new int[aiChannelCount];
            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.GetAIInfo(ref channelNumbers, ref units);
                if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    lblChannelMask.Text = "";
                    lblUnitMask.Text    = "";
                    for (int i = 0; i < aiChannelCount; i++)
                    {
                        lblChannelMask.Text += channelNumbers[i].ToString();

                        if (units[i] == Convert.ToInt32(MccDaq.LoggerUnits.Raw))
                        {
                            lblUnitMask.Text += "Raw";
                        }
                        else
                        {
                            lblUnitMask.Text += "Temperature";
                        }

                        if (i < aiChannelCount - 1)
                        {
                            lblChannelMask.Text = lblChannelMask.Text + ", ";
                            lblUnitMask.Text    = lblUnitMask.Text + ", ";
                        }
                    }
                }
            }


            //  Get the CJC info for the first file in the directory
            //   Parameters:
            //	   cjcChannelCount					:receives the number of CJC chennels logged
            int cjcChannelCount = 0;

            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.GetCJCInfo(ref cjcChannelCount);
                if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    lblCJCChannelCount.Text = cjcChannelCount.ToString();
                }
            }


            //  Get the DIO info for the first file in the directory
            //   Parameters:
            //	   dioChannelCount					:receives the number of DIO chennels logged
            int dioChannelCount = 0;

            if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                errorInfo = logger.GetDIOInfo(ref dioChannelCount);
                if (errorInfo.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)
                {
                    lblDIOChannelCount.Text = dioChannelCount.ToString();
                }
            }

            if (errorInfo.Value != MccDaq.ErrorInfo.ErrorCode.NoErrors)
            {
                MessageBox.Show(errorInfo.Message);
                return;
            }
        }