Example #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);
            }
        }
Example #2
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);
            }
        }
Example #3
0
        /// <summary>
        /// Get trigger mode values
        /// </summary>
        /// <param name="receivedPacket"></param>
        /// <param name="responceId"></param>
        private void GetTriggerModeRequest(Packet.Packet receivedPacket, int responceId)
        {
            if (responceId == (int)ADCStatus.START_ADC)
            {
                //TODO : Make 2 bytes
                ChannelValue = receivedPacket.RemoveUInt16();//CHANNEL ID
                //if (ApplicationUtil.ApplicationUtil.FirstRecievedChannelValue == 0)
                //{
                //    ApplicationUtil.ApplicationUtil.FirstRecievedChannelValue = ChannelValue;
                //}
                //else
                //{
                //    if (ChannelValue == ApplicationUtil.ApplicationUtil.FirstRecievedChannelValue)
                //    {
                //        CreateNewFile = true;

                //    }
                //}

                List <int> channels = new List <int>();
                ApplicationUtil.ApplicationUtil.GetValueFromNumber(ChannelValue, out channels);
                if (channels.Count == 1 && channels.Count != 0)
                {
                    //adc_resolution = 1;
                    ChannelA      = channels[0];
                    ChannelB      = -1;
                    isBothClicked = false;
                }
                else if (channels.Count > 1 && channels.Count != 0)
                {
                    //adc_resolution = 0;
                    ChannelA      = channels[0];
                    ChannelB      = channels[1];
                    isBothClicked = true;
                }
                //As per new Doc
                //adc_resolution = receivedPacket.RemoveByte();//adc resolution
                //TODO : 2 byte
                sampling_rate = receivedPacket.RemoveByte();       //sampling rate
                receivedPacket.UseLittleEndian = true;
                NUMBER_OF_RECORDS = receivedPacket.RemoveUInt16(); //Number of records
                //if (adc_resolution != EnumAndConstants.BIT_CHECKER)
                //{
                //    NUMBER_OF_RECORDS /= 2;
                //}
                receivedPacket.UseLittleEndian = false;

                stateVar             = new ReadState();
                stateVar.currentPos  = 0;
                stateVar.packetState = PacketState.ADC_COUNT;
                //if (adc_resolution == EnumAndConstants.BIT_CHECKER)
                //{
                stateVar.ReadBuffer = new byte[NUMBER_OF_RECORDS * EnumAndConstants.CONSTANT_VALUE];
                //}
                //else
                //{
                //    stateVar.ReadBuffer = new byte[NUMBER_OF_RECORDS * EnumAndConstants.CONSTANT_VALUE];
                //}
            }
            receivedPacket.RemoveByte(); //CRC
            waitHandle.Set();
        }
Example #4
0
        /// <summary>
        /// function for start continous request
        /// </summary>
        /// <returns></returns>
        public ResponseCode startContinousRequest()
        {
            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.START_CONTINOUS);//Request : 3
                packet.Append((byte)EnumAndConstants.PROTOCOL_LENGTH);//Length : 0
                packet.Append((byte)calculateCheckSum(packet, false));//CRC

                ResponseCode resp = sendRequest(serialPort, ref packet);
                if (resp == ResponseCode.SUCCESS)
                {
                    stateVar = new ReadState();
                    stateVar.packetState = PacketState.CONTINUOUS_ADC_COUNT;
                    stateVar.currentPos = 0;
                    fileName = ApplicationUtil.ApplicationUtil.GetFileNameWithDateTime(EnumAndConstants.CSV_FORMAT);//get name of file
                    directory = System.Configuration.ConfigurationManager.AppSettings["DirectoryPath"];
                    directory = Path.Combine(directory, fileName);
                }
                return resp;
            }
            catch (Exception ex)
            {
                m_logger.Error(ex);
                return ResponseCode.FAILURE;
            }
        }
Example #5
0
 /// <summary>
 /// stop continous request
 /// </summary>
 /// <returns></returns>
 public ResponseCode stopContinousRequest()
 {
     try
     {
         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.STOP_CONTINOUS); //Request : 4
         packet.Append((byte)EnumAndConstants.PROTOCOL_LENGTH);//Length : 0
         packet.Append((byte)calculateCheckSum(packet, false));//CRC
         stateVar = new ReadState();
         stateVar.packetState = PacketState.START_OF_PACKET;
         ResponseCode resp = sendRequest(serialPort, ref packet);
         //if (resp == ResponseCode.SUCCESS)
         {
             stateVar = new ReadState();
             stateVar.packetState = PacketState.START_OF_PACKET;
             stateVar.currentPos = 0;
         }
         return resp;
     }
     catch (Exception ex)
     {
         m_logger.Error(ex);
         return ResponseCode.FAILURE;
     }
 }
Example #6
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;
            }
        }
Example #7
0
        /// <summary>
        /// initialise the port
        /// </summary>
        /// <param name="comportvo"></param>
        /// <returns></returns>
        public bool Init(ComPortVO comportvo)
        {
            try
            {
                CloseSerialPort();
                serialPort = new SerialPort(comportvo.portName, comportvo.baudRate, comportvo.parity, comportvo.dataBits, comportvo.stopBits);
                serialPort.DtrEnable = true;
                serialPort.RtsEnable = true;
                serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);

                stateVar = new ReadState();
                stateVar.packetState = PacketState.START_OF_PACKET;
                stateVar.currentPos = 0;
                serialPort.WriteTimeout = 2000;
                ForceSetBaudRate(comportvo.portName, comportvo.baudRate);
                serialPort.Open();
                return true;
            }
            catch (Exception ex)
            {
                m_logger.Error(comportvo.portName, ex);
                return false;
            }
        }
Example #8
0
        /// <summary>
        /// function for handshaking with wireless device
        /// </summary>
        /// <returns></returns>
        public ResponseCode handshakeWirelessDevice()
        {
            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);//DOF
                packet.Append((byte)EnumAndConstants.PROTOCOL_VER); //Version : 1
                DSN = new Random().Next(); //Random number
                packet.Append((byte)DSN);
                packet.Append((byte)RequestId.HANDSHAKE_WIRELESS_DEVICE); // Request : 0x01
                packet.Append((byte)EnumAndConstants.PROTOCOL_LENGTH); //Length : 0x00
                packet.Append((byte)calculateCheckSum(packet, false));

                return sendRequest(serialPort, ref packet);
            }
            catch (Exception ex)
            {
                m_logger.Error(ex);
                return ResponseCode.FAILURE;

            }
        }
Example #9
0
        /// <summary>
        /// stop continous request
        /// </summary>
        /// <returns></returns>
        public ResponseCode getConfigurationDetails()
        {
            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.GET_CONFIGURATION); //Request : 5
                packet.Append((byte)EnumAndConstants.PROTOCOL_LENGTH);//Length : 0
                packet.Append((byte)calculateCheckSum(packet, false));//CRC

                return sendRequest(serialPort, ref packet);
            }
            catch (Exception ex)
            {
                m_logger.Error(ex);
                return ResponseCode.FAILURE;
            }
        }
Example #10
0
        /// <summary>
        /// Get trigger mode values
        /// </summary>
        /// <param name="receivedPacket"></param>
        /// <param name="responceId"></param>
        private void GetTriggerModeRequest(Packet.Packet receivedPacket, int responceId)
        {
            if (responceId == (int)ADCStatus.START_ADC)
            {
                //TODO : Make 2 bytes
                ChannelValue = receivedPacket.RemoveUInt16();//CHANNEL ID
                //if (ApplicationUtil.ApplicationUtil.FirstRecievedChannelValue == 0)
                //{
                //    ApplicationUtil.ApplicationUtil.FirstRecievedChannelValue = ChannelValue;
                //}
                //else
                //{
                //    if (ChannelValue == ApplicationUtil.ApplicationUtil.FirstRecievedChannelValue)
                //    {
                //        CreateNewFile = true;

                //    }
                //}

                List<int> channels = new List<int>();
                ApplicationUtil.ApplicationUtil.GetValueFromNumber(ChannelValue, out channels);
                if (channels.Count == 1 && channels.Count!=0)
                {
                    //adc_resolution = 1;
                    ChannelA = channels[0];
                    ChannelB = -1;
                    isBothClicked = false;
                }
                else if (channels.Count > 1 && channels.Count != 0)
                {
                    //adc_resolution = 0;
                    ChannelA = channels[0];
                    ChannelB = channels[1];
                    isBothClicked = true;

                }
                //As per new Doc
                //adc_resolution = receivedPacket.RemoveByte();//adc resolution
                //TODO : 2 byte
                sampling_rate = receivedPacket.RemoveByte();//sampling rate
                receivedPacket.UseLittleEndian = true;
                NUMBER_OF_RECORDS = receivedPacket.RemoveUInt16();//Number of records
                //if (adc_resolution != EnumAndConstants.BIT_CHECKER)
                //{
                //    NUMBER_OF_RECORDS /= 2;
                //}
                receivedPacket.UseLittleEndian = false;

                stateVar = new ReadState();
                stateVar.currentPos = 0;
                stateVar.packetState = PacketState.ADC_COUNT;
                //if (adc_resolution == EnumAndConstants.BIT_CHECKER)
                //{
                stateVar.ReadBuffer = new byte[NUMBER_OF_RECORDS * EnumAndConstants.CONSTANT_VALUE];
                //}
                //else
                //{
                //    stateVar.ReadBuffer = new byte[NUMBER_OF_RECORDS * EnumAndConstants.CONSTANT_VALUE];
                //}
            }
            receivedPacket.RemoveByte(); //CRC
            waitHandle.Set();
        }