コード例 #1
0
        /// <summary>
        /// Get ADC Details from response packet
        /// </summary>
        /// <param name="receivedPacket"></param>
        private void GetADCDetails(Packet.Packet receivedPacket)
        {
            try
            {
                adclist = new ArrayList();
                receivedPacket.CurrentPos = 0;

                List <ConfigurationVO> configlist    = ApplicationUtil.ApplicationUtil.ReadconfigCsvfile();
                List <ADCVO>           firstChannel  = new List <ADCVO>();
                List <ADCVO>           secondChannel = new List <ADCVO>();
                List <ADCVO>           singleChannel = new List <ADCVO>();
                receivedPacket.UseLittleEndian = true;
                //
                if ((adc_resolution == 2) || (adc_resolution == 3) && isContineousStartClick)
                {
                    if (neglectValue)
                    {
                        Array.Resize(ref receivedPacket.DataArray, receivedPacket.DataArray.Length + 1);
                        Array.Copy(receivedPacket.DataArray, 0, receivedPacket.DataArray, 1, receivedPacket.DataArray.Length - 1);
                        receivedPacket.CurrentPos = 0;
                        receivedPacket.Append(lastRemoveByte);
                        if (IsEvenValue(receivedPacket.DataArray.Length))
                        {
                            m_logger.Debug("E");
                            NUMBER_OF_RECORDS += 1;
                        }
                        neglectValue = false;
                    }

                    if (!IsEvenValue(receivedPacket.DataArray.Length))
                    {
                        m_logger.Debug("O");
                        neglectValue = true;
                        receivedPacket.CurrentPos = receivedPacket.DataArray.Length - 1;
                        lastRemoveByte            = receivedPacket.RemoveByte();
                    }
                    receivedPacket.UseLittleEndian = false;
                    receivedPacket.CurrentPos      = 0;
                    m_logger.Debug("N : " + NUMBER_OF_RECORDS + " L : " + responsePacket.DataArray.Length);
                }

                for (int i = 0; i < NUMBER_OF_RECORDS; i++)
                {
                    if (receivedPacket.CurrentPos + 2 < receivedPacket.DataLength)
                    {
                        ADCVO adc = new ADCVO();
                        //receivedPacket.UseLittleEndian = true;
                        //if (adc_resolution == EnumAndConstants.BIT_CHECKER)
                        receivedPacket.UseLittleEndian = false;
                        adc.AdcValue = receivedPacket.RemoveInt16();
                        //else if (adc_resolution == 2)
                        //{
                        //    adc.AdcValue = receivedPacket.RemoveUInt16();
                        //    adc.AdcValue &= 0x3ff;
                        //}
                        //else if (adc_resolution == 3)
                        //{
                        //    adc.AdcValue = (receivedPacket.RemoveUInt16() & 0xfff);
                        //    adc.AdcValue &= 0xfff;
                        //}
                        //receivedPacket.UseLittleEndian = false;
                        //m_logger.Debug("AV : " + adc.AdcValue);
                        if (sampling_rate == 0)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 100;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(1000000);
                        }
                        if (sampling_rate == EnumAndConstants.BIT_CHECKER)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.5;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(5000);
                        }
                        else if (sampling_rate == 2)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.3333;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(3333);
                        }
                        else if (sampling_rate == 3)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.2500;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(2500);
                        }
                        else if (sampling_rate == 4)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.2000;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(2000);
                        }
                        else if (sampling_rate == 5)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.1666;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(1666);
                        }
                        else if (sampling_rate == 6)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.1000;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(1000);
                        }
                        else if (sampling_rate == 7)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.0833;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(833);
                        }
                        else if (sampling_rate == 8)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.0666;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(666);
                        }
                        adc.AdcDate = AdcCurrentDate;
                        if (i == 0 && adc.AdcValue == 0)
                        {
                            continue;
                        }

                        if (isBothClicked)
                        {
                            if (IsEvenValue(i))
                            {
                                adc.Channel = ChannelA;
                                firstChannel.Add(adc);
                                m_logger.Debug(ChannelA, adc.AdcDate, adc.AdcValue);
                            }
                            else
                            {
                                adc.Channel = ChannelB;
                                secondChannel.Add(adc);
                                m_logger.Debug(ChannelB, adc.AdcDate, adc.AdcValue);
                            }
                        }
                        else
                        {
                            adc.Channel = ChannelA;
                            singleChannel.Add(adc);
                            m_logger.Debug(ChannelA, adc.AdcDate, adc.AdcValue);
                        }
                    }
                }

                // m_logger.Debug("AdcCurrentDate : " + AdcCurrentDate.Ticks);
                if (singleChannel.Count == 0)
                {
                    adclist.Add(firstChannel);
                    adclist.Add(secondChannel);
                    //m_logger.Debug(ChannelA, firstChannel,secondChannel);
                }
                else
                {
                    adclist.Add(singleChannel);
                }
                if (isContineousStartClick)
                {
                    ApplicationUtil.ApplicationUtil.adcValueList = singleChannel;
                }
                else
                {
                    ApplicationUtil.ApplicationUtil.adcValueList = null;
                }

                if (stateVar.packetState != PacketState.CONTINUOUS_ADC_COUNT)
                {
                    stateVar             = new ReadState();
                    stateVar.packetState = PacketState.START_OF_PACKET;
                    stateVar.currentPos  = 0;
                }

                int operationMode = configlist[0].mode_operation;



                //if (Channel > 2)
                //  Channel = 1;

                ArrayList comblist       = new ArrayList();
                ArrayList comblist_Other = new ArrayList();

                comblist.Add(configlist);
                comblist.Add(adclist);//create arraylist containing configlist and adclist

                if (adclist == null || adclist.Count == 0)
                {
                    return;
                }
                fileName = ApplicationUtil.ApplicationUtil.GetFileNameWithDateTime(EnumAndConstants.CSV_FORMAT);//get name of file
                if (ApplicationUtil.ApplicationUtil.CurrentFolderPath == "" || ApplicationUtil.ApplicationUtil.CurrentFolderPath == null)
                {
                    ApplicationUtil.ApplicationUtil.CurrentFolderPath = Path.Combine(ApplicationUtil.ApplicationUtil.GetApplicationPath(), ApplicationUtil.ApplicationUtil.GetFileNameWithDateTime(""));
                }
                directory = Path.Combine(ApplicationUtil.ApplicationUtil.CurrentFolderPath, fileName);
                if (stateVar.packetState != PacketState.CONTINUOUS_ADC_COUNT)
                {
                    //directory = System.Configuration.ConfigurationManager.AppSettings["DirectoryPath"];
                    try
                    {
                        if (!Directory.Exists(ApplicationUtil.ApplicationUtil.CurrentFolderPath) && ApplicationUtil.ApplicationUtil.IsDirectoryCreateAllowed == true)
                        {
                            if (!Directory.Exists(ApplicationUtil.ApplicationUtil.CurrentFolderPath))
                            {
                                Directory.CreateDirectory(ApplicationUtil.ApplicationUtil.CurrentFolderPath + "1");
                                Directory.Delete(ApplicationUtil.ApplicationUtil.CurrentFolderPath + "1");
                            }
                        }
                        // throw new IOException();
                    }
                    catch (IOException e)
                    {
                        ApplicationUtil.ApplicationUtil.IsDirectoryCreateAllowed = false;
                        if (DirectoryCreationErrorEvent != null)
                        {
                            DirectoryCreationErrorEvent(ApplicationUtil.ApplicationUtil.CurrentFolderPath);
                        }
                    }
                }
                if (operationMode == 1)
                {
                    confirmation = true;
                }
                FileObjectVO file = new FileObjectVO();
                //CacheStore.getInstance().comblist = null;
                //CacheStore.getInstance().ChannelA = ChannelA;
                //CacheStore.getInstance().ChannelB = ChannelB;
                //CacheStore.getInstance().directory = directory;
                //CacheStore.getInstance().comblist = comblist;
                file.Data     = comblist;
                file.channel1 = ChannelA;
                file.channel2 = ChannelB;
                file.filePath = directory;
                FileLoggingQueue.EnqueObject(file);

                isDataReceived = true;
                //ApplicationUtil.ApplicationUtil.addFileNameToList(configlist[0].ChannelValue, fileName);
                //ApplicationUtil.ApplicationUtil.CreateCsvArrayList(comblist, directory, ChannelA, ChannelB);//create arraylist containing configlist adclist and directories
                //if (CreateNewFile == true)
                //{

                // ApplicationUtil.ApplicationUtil.CreateCsvArrayListVersion2(comblist,directory, ChannelA, ChannelB, true);
                //}
                //else
                //{
                //    //ApplicationUtil.ApplicationUtil.CreateCsvArrayList(comblist, directory, ChannelA, ChannelB);//create arraylist containing configlist adclist and directories
                //    ApplicationUtil.ApplicationUtil.CreateCsvArrayListVersion2(comblist, directory, ChannelA, ChannelB, false);

                //}

                // read the csv for both channels selected mode
                //if (filecreateEvent != null)
                //  filecreateEvent(directory);
            }
            catch (Exception ex)
            {
                m_logger.Error(ex);
            }
        }
コード例 #2
0
ファイル: DASCommunicator.cs プロジェクト: jramshur/SRD_GUI
        /// <summary>
        /// Get ADC Details from response packet
        /// </summary>
        /// <param name="receivedPacket"></param>
        private void GetADCDetails(Packet.Packet receivedPacket)
        {
            try
            {
                adclist = new ArrayList();
                receivedPacket.CurrentPos = 0;

                List<ConfigurationVO> configlist = ApplicationUtil.ApplicationUtil.ReadconfigCsvfile();
                List<ADCVO> firstChannel = new List<ADCVO>();
                List<ADCVO> secondChannel = new List<ADCVO>();
                List<ADCVO> singleChannel = new List<ADCVO>();
                receivedPacket.UseLittleEndian = true;
                //
                if ( (adc_resolution == 2) || (adc_resolution == 3) && isContineousStartClick)
                {
                    if (neglectValue)
                    {
                        Array.Resize(ref receivedPacket.DataArray, receivedPacket.DataArray.Length + 1);
                        Array.Copy(receivedPacket.DataArray, 0, receivedPacket.DataArray, 1, receivedPacket.DataArray.Length - 1);
                        receivedPacket.CurrentPos = 0;
                        receivedPacket.Append(lastRemoveByte);
                        if (IsEvenValue(receivedPacket.DataArray.Length))
                        {
                            m_logger.Debug("E");
                            NUMBER_OF_RECORDS += 1;
                        }
                        neglectValue = false;
                    }

                    if (!IsEvenValue(receivedPacket.DataArray.Length))
                    {
                        m_logger.Debug("O");
                        neglectValue = true;
                        receivedPacket.CurrentPos = receivedPacket.DataArray.Length - 1;
                        lastRemoveByte = receivedPacket.RemoveByte();
                    }
                    receivedPacket.UseLittleEndian = false;
                    receivedPacket.CurrentPos = 0;
                    m_logger.Debug("N : " + NUMBER_OF_RECORDS + " L : " + responsePacket.DataArray.Length);
                }

                for (int i = 0; i < NUMBER_OF_RECORDS; i++)
                {
                    if (receivedPacket.CurrentPos + 2 < receivedPacket.DataLength)
                    {
                        ADCVO adc = new ADCVO();
                        //receivedPacket.UseLittleEndian = true;
                        //if (adc_resolution == EnumAndConstants.BIT_CHECKER)
                        receivedPacket.UseLittleEndian = false;
                        adc.AdcValue = receivedPacket.RemoveInt16();
                        //else if (adc_resolution == 2)
                        //{
                        //    adc.AdcValue = receivedPacket.RemoveUInt16();
                        //    adc.AdcValue &= 0x3ff;
                        //}
                        //else if (adc_resolution == 3)
                        //{
                        //    adc.AdcValue = (receivedPacket.RemoveUInt16() & 0xfff);
                        //    adc.AdcValue &= 0xfff;
                        //}
                        //receivedPacket.UseLittleEndian = false;
                        //m_logger.Debug("AV : " + adc.AdcValue);
                        if (sampling_rate == 0)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 100;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(1000000);
                        }
                        if (sampling_rate == EnumAndConstants.BIT_CHECKER)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.5;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(5000);
                        }
                        else if (sampling_rate == 2)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.3333;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(3333);
                        }
                        else if (sampling_rate == 3)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.2500;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(2500);
                        }
                        else if (sampling_rate == 4)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.2000;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(2000);
                        }
                        else if (sampling_rate == 5)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.1666;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(1666);
                        }
                        else if (sampling_rate == 6)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.1000;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(1000);
                        }
                        else if (sampling_rate == 7)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.0833;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(833);
                        }
                        else if (sampling_rate == 8)
                        {
                            ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.0666;
                            AdcCurrentDate = AdcCurrentDate.AddTicks(666);
                        }
                        adc.AdcDate = AdcCurrentDate;
                        if (i == 0 && adc.AdcValue == 0)
                            continue;

                        if (isBothClicked)
                        {
                            if (IsEvenValue(i))
                            {
                                adc.Channel = ChannelA;
                                firstChannel.Add(adc);
                                m_logger.Debug(ChannelA, adc.AdcDate, adc.AdcValue);
                            }
                            else
                            {
                                adc.Channel = ChannelB;
                                secondChannel.Add(adc);
                                m_logger.Debug(ChannelB, adc.AdcDate, adc.AdcValue);
                            }
                        }
                        else
                        {
                            adc.Channel = ChannelA;
                            singleChannel.Add(adc);
                            m_logger.Debug(ChannelA, adc.AdcDate, adc.AdcValue);
                        }
                    }
                }

                // m_logger.Debug("AdcCurrentDate : " + AdcCurrentDate.Ticks);
                if (singleChannel.Count == 0)
                {

                    adclist.Add(firstChannel);
                    adclist.Add(secondChannel);
                    //m_logger.Debug(ChannelA, firstChannel,secondChannel);
                }
                else
                {
                    adclist.Add(singleChannel);
                }
                if (isContineousStartClick)
                {
                    ApplicationUtil.ApplicationUtil.adcValueList = singleChannel;
                }
                else
                {
                    ApplicationUtil.ApplicationUtil.adcValueList = null;
                }

                if (stateVar.packetState != PacketState.CONTINUOUS_ADC_COUNT)
                {
                    stateVar = new ReadState();
                    stateVar.packetState = PacketState.START_OF_PACKET;
                    stateVar.currentPos = 0;
                }

                int operationMode = configlist[0].mode_operation;

                //if (Channel > 2)
                  //  Channel = 1;

                ArrayList comblist = new ArrayList();
                ArrayList comblist_Other = new ArrayList();

                comblist.Add(configlist);
                comblist.Add(adclist);//create arraylist containing configlist and adclist

                if (adclist == null || adclist.Count == 0)
                    return;
                fileName = ApplicationUtil.ApplicationUtil.GetFileNameWithDateTime(EnumAndConstants.CSV_FORMAT);//get name of file
                if (ApplicationUtil.ApplicationUtil.CurrentFolderPath == "" || ApplicationUtil.ApplicationUtil.CurrentFolderPath == null)
                {
                    ApplicationUtil.ApplicationUtil.CurrentFolderPath = Path.Combine(ApplicationUtil.ApplicationUtil.GetApplicationPath(), ApplicationUtil.ApplicationUtil.GetFileNameWithDateTime(""));
                }
                directory = Path.Combine(ApplicationUtil.ApplicationUtil.CurrentFolderPath, fileName);
                if (stateVar.packetState != PacketState.CONTINUOUS_ADC_COUNT)
                {
                    //directory = System.Configuration.ConfigurationManager.AppSettings["DirectoryPath"];
                    try
                    {
                        if (!Directory.Exists(ApplicationUtil.ApplicationUtil.CurrentFolderPath) && ApplicationUtil.ApplicationUtil.IsDirectoryCreateAllowed == true)
                        {

                            if (!Directory.Exists(ApplicationUtil.ApplicationUtil.CurrentFolderPath))
                            {
                                Directory.CreateDirectory(ApplicationUtil.ApplicationUtil.CurrentFolderPath+"1");
                                Directory.Delete(ApplicationUtil.ApplicationUtil.CurrentFolderPath+"1");
                            }
                        }
                        // throw new IOException();
                    }
                    catch (IOException e)
                    {
                        ApplicationUtil.ApplicationUtil.IsDirectoryCreateAllowed = false;
                        if (DirectoryCreationErrorEvent != null)
                            DirectoryCreationErrorEvent(ApplicationUtil.ApplicationUtil.CurrentFolderPath);
                    }
                }
                if (operationMode == 1)
                    confirmation = true;
                FileObjectVO file = new FileObjectVO();
                //CacheStore.getInstance().comblist = null;
                //CacheStore.getInstance().ChannelA = ChannelA;
                //CacheStore.getInstance().ChannelB = ChannelB;
                //CacheStore.getInstance().directory = directory;
                //CacheStore.getInstance().comblist = comblist;
                file.Data = comblist;
                file.channel1 = ChannelA;
                file.channel2 = ChannelB;
                file.filePath = directory;
                FileLoggingQueue.EnqueObject(file);

                isDataReceived = true;
                //ApplicationUtil.ApplicationUtil.addFileNameToList(configlist[0].ChannelValue, fileName);
                //ApplicationUtil.ApplicationUtil.CreateCsvArrayList(comblist, directory, ChannelA, ChannelB);//create arraylist containing configlist adclist and directories
                //if (CreateNewFile == true)
                //{

                   // ApplicationUtil.ApplicationUtil.CreateCsvArrayListVersion2(comblist,directory, ChannelA, ChannelB, true);
                //}
                //else
                //{
                //    //ApplicationUtil.ApplicationUtil.CreateCsvArrayList(comblist, directory, ChannelA, ChannelB);//create arraylist containing configlist adclist and directories
                //    ApplicationUtil.ApplicationUtil.CreateCsvArrayListVersion2(comblist, directory, ChannelA, ChannelB, false);

                //}

                // read the csv for both channels selected mode
                //if (filecreateEvent != null)
                //  filecreateEvent(directory);
            }
            catch (Exception ex)
            {
                m_logger.Error(ex);
            }
        }
コード例 #3
-3
ファイル: FrmMain.cs プロジェクト: jramshur/SRD_GUI
        private void button5_Click_1(object sender, EventArgs e)
        {
            List<ConfigurationVO> configlist = ApplicationUtil.ApplicationUtil.ReadconfigCsvfile();
            List<ADCVO> adcList = new List<ADCVO>();
            DateTime date = DateTime.Now;
            for (int i = 0; i < 10; i++)
            {
                ADCVO adc = new ADCVO();
                adc.AdcValue = i;
                date = date.AddMilliseconds(10);
                adc.AdcDate = date;

                adcList.Add(adc);
            }
            ArrayList comblist = new ArrayList();
            comblist.Add(configlist);
            comblist.Add(adcList);
            ApplicationUtil.ApplicationUtil.CreateCsvArrayList(comblist, @"D:\RamshurRatApp\Application\RamshurRatApp\bin\x86\Debug\try.csv", 1,0);
        }