Пример #1
0
        /// <summary>
        /// ReadFunction for configlist
        /// </summary>
        /// <returns></returns>
        public static List <ConfigurationVO> ReadconfigCsvfile()
        {
            List <ConfigurationVO> Configlist = new List <ConfigurationVO>();

            try
            {
                string filePath = Assembly.GetExecutingAssembly().Location;
                int    position = filePath.LastIndexOf('\\');
                filePath  = filePath.Remove(position);
                filePath += EnumAndConstants.CONFIGURATION_FILE;

                StreamReader reader = new StreamReader(File.OpenRead(filePath));
                while (!reader.EndOfStream)
                {
                    string[] line = reader.ReadLine().Split(',');
                    if (line[0] == "")
                    {
                        continue;
                    }
                    if (line[0].Equals("T1"))
                    {
                        continue;
                    }


                    ConfigurationVO config = ConfigurationVO.GetInstance();
                    config.T1  = Convert.ToInt32(line[0]);
                    config.T2  = Convert.ToInt32(line[1]);
                    config.T3  = Convert.ToInt32(line[2]);
                    config.T4  = Convert.ToInt32(line[3]);
                    config.T5  = Convert.ToInt32(line[4]);
                    config.T6  = Convert.ToInt32(line[5]);
                    config.T7  = Convert.ToInt32(line[6]);
                    config.T8  = Convert.ToInt32(line[7]);
                    config.T9  = Convert.ToInt32(line[8]);
                    config.T10 = Convert.ToInt32(line[9]);

                    config.mode_operation = Convert.ToInt32(line[11]);
                    config.adcresolution  = Convert.ToInt32(line[12]);
                    config.sampaling_rate = Convert.ToInt32(line[13]);
                    config.ChannelValue   = Convert.ToUInt16(line[14]);
                    config.T5VDAC         = Convert.ToUInt16(line[15]);
                    config.T7VDAC         = Convert.ToUInt16(line[16]);
                    Configlist.Add(config);
                }
                reader.Close();
                return(Configlist);
            }
            catch (Exception ex)
            {
                m_logger.Error(ex);
                return(Configlist);
            }
        }
Пример #2
0
        public static void CreateCsvArrayListVersion2(ArrayList config, string csvNameWithExt, int ChannelOne, int ChannelTwo, bool CreateNew)
        {
            if (config == null || config.Count == 0)
            {
                return;
            }

            List <ConfigurationVO> configList = (List <ConfigurationVO>)config[0];
            int channel = configList[0].channel;

            string newLine   = Environment.NewLine;
            bool   isNewFile = false;

            if (savefile == false)
            {
                isNewFile = true;
                if (File.Exists(csvNameWithExt))
                {
                    File.Delete(csvNameWithExt);
                }
            }
            else
            {
                if (!Directory.Exists(Path.GetDirectoryName(csvNameWithExt)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(csvNameWithExt));
                }
                if (!File.Exists(csvNameWithExt) && CreateNew == true)
                {
                    isNewFile = true;
                }

                if (File.Exists(csvNameWithExt) && CreateNew == false)
                {
                    isNewFile = false;
                }
                if (File.Exists(csvNameWithExt) && CreateNew == true)
                {
                    isNewFile = true;
                }
            }

            using (StreamWriter sw = new StreamWriter(csvNameWithExt, true))
            {
                StringBuilder sb = null;

                sb = new StringBuilder();
                if (isNewFile)
                {
                    for (int j = 1; j <= 10; j++)
                    {
                        sb.Append("T" + j);
                        sb.Append(",");
                    }
                    sb.Append("CHANNEL_VALUE");
                    sb.Append(",");
                    sb.Append("MODE_OPERATION");
                    sb.Append(",");
                    sb.Append("ADCRESOLUTION");
                    sb.Append(",");
                    sb.Append("SAMPALING_RATE");
                    sb.Append(",");
                    sb.Append("T5_VDAC_VALUE");
                    sb.Append(",");
                    sb.Append("T7_VDAC_VALUE");
                    sb.Append(",");
                    sb.Append("\n");

                    ConfigurationVO ConfigVO = configList[0];
                    if (ConfigVO == null)
                    {
                        return;
                    }
                    sb.Append(ConfigVO.T1);
                    sb.Append(",");
                    sb.Append(ConfigVO.T2);
                    sb.Append(",");
                    sb.Append(ConfigVO.T3);
                    sb.Append(",");
                    sb.Append(ConfigVO.T4);
                    sb.Append(",");
                    sb.Append(ConfigVO.T5);
                    sb.Append(",");
                    sb.Append(ConfigVO.T6);
                    sb.Append(",");
                    sb.Append(ConfigVO.T7);
                    sb.Append(",");
                    sb.Append(ConfigVO.T8);
                    sb.Append(",");
                    sb.Append(ConfigVO.T9);
                    sb.Append(",");
                    sb.Append(ConfigVO.T10);
                    sb.Append(",");

                    sb.Append(ConfigVO.ChannelValue);
                    sb.Append(",");
                    sb.Append(ConfigVO.mode_operation);
                    sb.Append(",");
                    sb.Append(ConfigVO.adcresolution);
                    sb.Append(",");
                    sb.Append(ConfigVO.sampaling_rate);
                    sb.Append(",");
                    sb.Append(ConfigVO.T5VDAC);
                    sb.Append(",");
                    sb.Append(ConfigVO.T7VDAC);

                    sb.Append("\n");
                    sw.WriteLine(sb.ToString());
                }
                //Add Adcvalues
                sb = sb.Remove(0, sb.Length);
                sb.Append("Channel ");
                sb.Append(",");
                sb.Append(ChannelOne);
                sb.Append("\n");
                sb.Append("ADC Value");
                sb.Append(",");
                sb.Append("Date");
                sb.Append("\n");
                List <ADCVO> AdcCollection = null;
                AdcCollection = (List <ADCVO>)config[1];
                if (AdcCollection == null || AdcCollection.Count == 0)
                {
                    return;
                }

                for (int iterator = 0; iterator < AdcCollection.Count; iterator++)
                {
                    ADCVO AdcVo = AdcCollection.ElementAt(iterator);
                    if (AdcVo == null)
                    {
                        continue;
                    }
                    sb.Append(AdcVo.AdcValue);
                    sb.Append(",");
                    sb.Append(AdcVo.AdcDate.Ticks);
                    sb.Append("\n");
                }
                sw.WriteLine(sb.ToString());
                sb = sb.Remove(0, sb.Length);
                // both channels
                if (config.Count > 2)
                {
                    AdcCollection = (List <ADCVO>)config[2];
                    sb.Append("Channel ");
                    sb.Append(",");
                    sb.Append(ChannelTwo);
                    sb.Append("\n");
                    sb.Append("ADC Value");
                    sb.Append(",");
                    sb.Append("Date");
                    sb.Append("\n");
                    for (int iterator = 0; iterator < AdcCollection.Count; iterator++)
                    {
                        ADCVO AdcVo = AdcCollection.ElementAt(iterator);
                        if (AdcVo == null)
                        {
                            continue;
                        }
                        sb.Append(AdcVo.AdcValue);
                        sb.Append(",");
                        sb.Append(AdcVo.AdcDate.Ticks);
                        sb.Append("\n");
                    }
                    sw.WriteLine(sb.ToString());
                }
            }
        }
Пример #3
0
        private void Commitbutton_Click(object sender, EventArgs e)
        {
            if (!(this.checkBox1.Checked || this.Channl2chkbox.Checked))
            {
                MessageBox.Show("Select the channel to be used");
                return;
            }
            if (!(this.Triggerdmoderadiobutton.Checked || this.Continousmoderadiobutton.Checked))
            {
                MessageBox.Show("Select the mode of operation ");
                return;
            }


            if (String.IsNullOrEmpty(txtT1.Text) || String.IsNullOrEmpty(textT3.Text) || String.IsNullOrEmpty(textT4.Text) || String.IsNullOrEmpty(textT5.Text) || String.IsNullOrEmpty(textT9.Text) || String.IsNullOrEmpty(textT2.Text) || String.IsNullOrEmpty(textT6.Text) || String.IsNullOrEmpty(textT7.Text) || String.IsNullOrEmpty(textT8.Text) || String.IsNullOrEmpty(textT10.Text))
            {
                MessageBox.Show("Please fill all the configuration paramters");
            }
            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("Please select ADC resolution");
            }
            else
            {
                List <ConfigurationVO> configList = new List <ConfigurationVO>();
                ConfigurationVO        configVo   = new ConfigurationVO();
                if (Continousmoderadiobutton.Checked)
                {
                    configVo.mode_operation = 1;
                }
                else
                {
                    configVo.mode_operation = 2;
                }
                if (checkBox1.Checked)
                {
                    configVo.channel = 1;
                }
                else
                {
                    configVo.channel = 2;
                }

                configVo.T1            = txtT1.Text;
                configVo.T2            = textT3.Text;
                configVo.T3            = textT4.Text;
                configVo.T4            = textT5.Text;
                configVo.T5            = textT9.Text;
                configVo.T6            = textT2.Text;
                configVo.T7            = textT6.Text;
                configVo.T8            = textT7.Text;
                configVo.T9            = textT8.Text;
                configVo.T10           = textT10.Text;
                configVo.adcresolution = comboBox1.SelectedItem.ToString();
                configList.Add(configVo);
                string path = Assembly.GetExecutingAssembly().Location;
                int    edit = path.LastIndexOf("\\");
                path  = path.Remove(edit);
                path += EnumAndConstant.Configuration_File;
                ApplicationUtil.ApplicationUtil.CreateCSVFromGenericList(configList, path);
                labelpathdispl.Text = path;



                MessageBox.Show("Configurations saved Succesfully");
            }
        }
Пример #4
0
        /// <summary>
        /// Read ConfigList and ADCList
        /// </summary>
        /// <returns></returns>

        public static ArrayList ReadconfigadcCsvfile(string filePath)
        {
            ArrayList list = new ArrayList();
            List <ConfigurationVO> Configcollection      = new List <ConfigurationVO>();
            List <ADCVO>           adccollection         = new List <ADCVO>();
            List <ADCVO>           adccollectionchannel2 = new List <ADCVO>();

            try
            {
                StreamReader reader      = new StreamReader(File.OpenRead(filePath));
                int          Case_Number = 0;
                int          channel_Ref = 0;
                int          channelA    = 0;
                int          channelB    = 0;

                while (!reader.EndOfStream)
                {
                    string[] line = reader.ReadLine().Split(',');
                    if (line[0] == "")
                    {
                        continue;
                    }
                    if (line[0].Equals("T1"))
                    {
                        Case_Number = 1;
                        continue;
                    }
                    else if (line[0].Equals("Channel"))
                    {
                        //if (line[0].Equals("Channel 1"))
                        if (channelA == 0)
                        {
                            channelA = int.Parse(line[1]);
                        }
                        else
                        {
                            channelB = int.Parse(line[1]);
                        }
                        //else if (line[0].Equals("Channel 2"))
                        // channel = 2;
                        Case_Number = 2;
                        continue;
                    }

                    switch (Case_Number)
                    {
                    case 1:
                        ConfigurationVO config = ConfigurationVO.GetInstance();
                        config.T1  = Convert.ToInt32(line[0]) / EnumAndConstants.COMMON_FACTOR;
                        config.T2  = Convert.ToInt32(line[1]) / EnumAndConstants.COMMON_FACTOR;
                        config.T3  = Convert.ToInt32(line[2]) / EnumAndConstants.COMMON_FACTOR;
                        config.T4  = Convert.ToInt32(line[3]) / EnumAndConstants.COMMON_FACTOR;
                        config.T5  = Convert.ToInt32(line[4]) / EnumAndConstants.COMMON_FACTOR;
                        config.T6  = Convert.ToInt32(line[5]) / EnumAndConstants.COMMON_FACTOR;
                        config.T7  = Convert.ToInt32(line[6]) / EnumAndConstants.COMMON_FACTOR;
                        config.T8  = Convert.ToInt32(line[7]) / EnumAndConstants.COMMON_FACTOR;
                        config.T9  = Convert.ToInt32(line[8]) / EnumAndConstants.COMMON_FACTOR;
                        config.T10 = Convert.ToInt32(line[9]) / EnumAndConstants.COMMON_FACTOR;

                        //channel_Ref = config.channel;
                        config.ChannelValue   = Convert.ToUInt16(line[10]);
                        config.mode_operation = Convert.ToInt32(line[11]);
                        config.adcresolution  = Convert.ToInt32(line[12]);
                        config.sampaling_rate = Convert.ToInt32(line[13]);

                        config.T5VDAC = Convert.ToUInt16(line[14]);
                        config.T7VDAC = Convert.ToUInt16(line[15]);
                        Configcollection.Add(config);
                        break;

                    case 2:
                        if (line[0].Equals("ADC Value") || line[0].Equals("Channel 2"))
                        {
                            continue;
                        }

                        ADCVO adcvo = new ADCVO();
                        adcvo.AdcValue = int.Parse(line[0]);
                        adcvo.AdcDate  = new DateTime(Convert.ToInt64(line[1]));
                        if (channelA != 0 && channelB == 0)
                        {
                            adcvo.Channel = channelA;
                            adccollection.Add(adcvo);
                        }
                        else if (channelB != 0)
                        {
                            adcvo.Channel = channelB;
                            adccollectionchannel2.Add(adcvo);
                        }
                        else
                        {
                            adccollection.Add(adcvo);
                        }
                        break;
                    }
                }
                list.Add(Configcollection);
                list.Add(adccollection);
                if (channelB != 0)
                {
                    list.Add(adccollectionchannel2);
                }
                reader.Close();
                return(list);
            }
            catch (Exception ex)
            {
                m_logger.Error(ex);
                return(list);
            }
        }
Пример #5
0
        /// <summary>
        /// function for request setConfiguration
        /// </summary>
        /// <returns></returns>
        public ResponseCode setConfigurationRequest(ConfigurationVO configVo)
        {
            try
            {
                stateVar = new ReadState();
                stateVar.packetState = PacketState.START_OF_PACKET;
                stateVar.currentPos = 0;

                Packet.Packet packet = new Packet.Packet(1048);
                packet.Append(EnumAndConstants.START_FRAME);//SOF
                packet.Append((byte)EnumAndConstants.PROTOCOL_VER); //Version : 1
                DSN = new Random().Next();//Random number
                packet.Append((byte)DSN);
                packet.Append((byte)RequestId.SET_CONFIGIRATION); //Request : 2
                packet.Append((byte)28); // Length : 0
                packet.Append((byte)configVo.mode_operation);
                packet.Append((byte)configVo.NumberOfSelectedChannels);
                packet.Append((UInt16)configVo.ChannelValue);

                adc_resolution = configVo.adcresolution;
                //packet.Append((byte)configVo.adcresolution);

                sampling_rate = configVo.sampaling_rate;
                packet.Append((byte)configVo.sampaling_rate);
                packet.Append((byte)configVo.T5VDAC);
                packet.Append((byte)configVo.T7VDAC);
                packet.Append((UInt16)configVo.T1);
                packet.Append((UInt16)configVo.T2);
                packet.Append((UInt16)configVo.T3);
                packet.Append((UInt16)configVo.T4);
                packet.Append((UInt16)configVo.T5);
                packet.Append((UInt16)configVo.T6);
                packet.Append((UInt16)configVo.T7);
                packet.Append((UInt16)configVo.T8);
                packet.Append((UInt16)configVo.T9);
                packet.Append((UInt16)configVo.T10);
                packet.Append((byte)calculateCheckSum(packet, false));
                GraphFileCollectionSingleton.getInstance().channelFileMap = new Dictionary<ushort, List<string>>();
                //Append packetfields
                return sendRequest(serialPort, ref packet);
            }
            catch (Exception ex)
            {
                m_logger.Error(ex);
                return ResponseCode.FAILURE;
            }
        }