示例#1
0
        private void Btn_Go(object sender, RoutedEventArgs e)
        {
            if (combo.SelectedItem == null)
            {
                return;
            }
            Globals.StopReadingHIstoryFile = true;

            //if (speed.SelectedIndex == 0) CAN_Common.HistoryReadRefreshSpeed = 0.25f;
            //else if (speed.SelectedIndex == 1) CAN_Common.HistoryReadRefreshSpeed = 0.5f;
            //else CAN_Common.HistoryReadRefreshSpeed = speed.SelectedIndex-1;
            Thread.Sleep(50);
            CAN_Common.CloseAllConnections();
            Thread.Sleep(100);
            //CAN_Common.Instance.CmdCloseConnection.Execute(null);
            // vm_sciChartOsciloscope.prepareDataReceiver();
            vm_sciChartOsciloscope.CmdClear.Execute(null);
            Thread.Sleep(100);

            string fileName = combo.SelectedItem.ToString();

            Task.Factory.StartNew(
                action: () => SaveToDisk.Restore(fileName, vm_sciChartOsciloscope));//, vm_sciChartOsciloscope));
            Close();
        }
示例#2
0
        private void Btn_OK(object sender, RoutedEventArgs e)
        {
            string nfn = newFileName.Text;

            SaveToDisk.RenameFile(nfn, originalFileName.Text);
            Close();
        }
示例#3
0
    static GameObject ReadAssetFromDiskAsObj()
    {
        var result = EditorUtility.OpenFilePanel("Load...", "", "obj");

        Debug.Log(result);
        if (!string.IsNullOrEmpty(result))
        {
            return(SaveToDisk.ReadObjFromDisk(result, ""));
        }
        return(new GameObject());
    }
示例#4
0
    static void ReadAssetFromDisk()
    {
        var result = EditorUtility.OpenFilePanel("Load...", "", "asset");

        Debug.Log(result);

        if (!string.IsNullOrEmpty(result))
        {
            SaveToDisk.ReadAssetFromDisk(result, "");
        }
    }
示例#5
0
        private void OscilloscopeChart_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!_dataContext.IsShowingHistory)
            {
                return;
            }
            var    hitTestPoint = e.GetPosition(oscilloscopeChart.GridLinesPanel as UIElement);
            var    xPosition    = xAxis.HitTest(hitTestPoint);
            double pos          = (double)xPosition.DataValue;

            SaveToDisk.RestoreDataAtPoint(pos);
        }
示例#6
0
    static void SaveAssetToDiskAsObj()
    {
        if (Selection.activeTransform != null)
        {
            Debug.Log(Selection.activeTransform.name);
            var result = EditorUtility.SaveFilePanel("Save...", "", Selection.activeTransform.name, "obj");
            Debug.Log(result);

            if (!string.IsNullOrEmpty(result))
            {
                SaveToDisk.SaveObjToDisk(Selection.activeTransform.GetComponent <MeshFilter>(), result);
            }
        }
    }
示例#7
0
        public UI_HistoryAdvanced(VM_SciChartOsciloscope sci)
        {
            vm_sciChartOsciloscope = sci;
            InitializeComponent();
            List <string> comboItems = SaveToDisk.getHistoryValues();

            foreach (var comboItem in comboItems)
            {
                combo.Items.Add(comboItem);
            }
            if (comboItems.Count != 0)
            {
                combo.SelectedItem = comboItems[0];
            }
        }
示例#8
0
        private void Btn_Delete(object sender, RoutedEventArgs e)
        {
            if (combo.SelectedIndex == -1)
            {
                return;
            }
            SaveToDisk.DeleteHistoryFile(combo.SelectedItem.ToString());
            List <string> comboItems = SaveToDisk.getHistoryValues();

            combo.Items.Clear();
            foreach (var comboItem in comboItems)
            {
                combo.Items.Add(comboItem);
            }
            if (comboItems.Count != 0)
            {
                combo.SelectedItem = comboItems[0];
            }
        }
示例#9
0
        public UI_HistoryChooser(VM_SciChartOsciloscope sci)
        {
            vm_sciChartOsciloscope = sci;
            InitializeComponent();
            List <string> comboItems = SaveToDisk.getHistoryValues();

            foreach (var comboItem in comboItems)
            {
                combo.Items.Add(comboItem);
            }
            if (comboItems.Count != 0)
            {
                if (selectedIndex != -1 && comboItems.Count > selectedIndex)
                {
                    combo.SelectedItem = comboItems[selectedIndex];
                }
                else
                {
                    combo.SelectedItem = comboItems[comboItems.Count - 1];
                }
            }
        }
示例#10
0
        private void cmdStartTest_Click(object sender, EventArgs e)
        {
            DateTime curveTime;
            float    wfmPerSec = 0;

            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            string       temp;
            SaveToDisk   saveToDisk = (SaveToDisk)cmbxSaveToDisk.SelectedIndex;
            StreamWriter textFile   = null;
            FileStream   binaryFile = null;
            BinaryWriter binWriter  = null;

            string SaveDirectory = txtSaveDirectory.Text;

            byte[] DataBuffer;
            int    AcqLength  = 0;
            int    CurveCount = 0;
            int    DataLength;
            int    BytesRemaining;

            // Curve data conversion parameters
            int   pt_off;
            float xinc;
            float xzero;
            float ymult;
            float yoff;
            float yzero;

            float xvalue;
            float yvalue;

            cmdStartTest.Enabled = false;
            lblCurveCount.Text   = CurveCount.ToString();
            lblWfmPerSec.Text    = wfmPerSec.ToString("f");
            Application.DoEvents();  // Allow the front panel to redraw

            if (saveToDisk != SaveToDisk.None)
            {
                // Check that the save directory is valid
                if (!Directory.Exists(SaveDirectory))
                {
                    MessageBox.Show("Invalid save directory.  Please enter a valid directory then try again.", "Error: Invalid Directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cmdStartTest.Enabled = true;
                    return;
                }
            }

            // Prompt the user to prep the scope
            if (MessageBox.Show("Please setup the scope then press OK to start Curve Streaming.  Once Curve Streaming has started you will not be able to control the scope until Curve Streaming is ended.",
                                "Setup Scope",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Information) == DialogResult.Cancel)
            {
                cmdStartTest.Enabled = true;
                return;
            }

            // Open a connection to the instrument
            try
            {
                //TekScope = new MessageBasedSession(txtVisaResourceName.Text.Trim());
                TekScope = GlobalResourceManager.Open(txtVisaResourceName.Text.Trim()) as IMessageBasedSession;
                TekScope.Clear();
            }
            catch (Exception ex)
            {
                // Show and error message then exit if the connection fails
                MessageBox.Show(ex.Message, "Error Opening Connection to Instrument", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TekScope             = null;
                cmdStartTest.Enabled = true;
                return;
            }

            GatherCurves       = true;
            cmdEndTest.Enabled = true;

            // Setup the waveform transfer
            TekScope.FormattedIO.WriteLine("*CLS");
            TekScope.FormattedIO.WriteLine("*CLE");
            TekScope.FormattedIO.WriteLine("DATa:SOUrce CH1");
            TekScope.FormattedIO.WriteLine("DATa:ENCdg RIBinary");
            TekScope.FormattedIO.WriteLine("DATa:STARt 0");
            TekScope.FormattedIO.WriteLine("HORizontal:ACQLENGTH?");
            temp      = TekScope.RawIO.ReadString().Trim();
            AcqLength = Int32.Parse(temp);
            TekScope.FormattedIO.WriteLine(String.Format("DATa:STOP {0}", AcqLength));
            TekScope.FormattedIO.WriteLine("WFMOutpre:ENCdg BINary");
            TekScope.FormattedIO.WriteLine("WFMOutpre:BYT_Nr 1");

            // Get the needed values from the scope to scale the data
            TekScope.FormattedIO.WriteLine("WFMOutpre:PT_Off?");
            temp   = TekScope.RawIO.ReadString().Trim();
            pt_off = Int32.Parse(temp);
            TekScope.FormattedIO.WriteLine("WFMOutpre:XINcr?");
            temp = TekScope.RawIO.ReadString().Trim();
            xinc = Single.Parse(temp);
            TekScope.FormattedIO.WriteLine("WFMOutpre:XZEro?");
            temp  = TekScope.RawIO.ReadString().Trim();
            xzero = Single.Parse(temp);
            TekScope.FormattedIO.WriteLine("WFMOutpre:YMUlt?");
            temp  = TekScope.RawIO.ReadString().Trim();
            ymult = Single.Parse(temp);
            TekScope.FormattedIO.WriteLine("WFMOutpre:YOFf?");
            temp = TekScope.RawIO.ReadString().Trim().TrimEnd('0').TrimEnd('.');
            yoff = Single.Parse(temp);
            TekScope.FormattedIO.WriteLine("WFMOutpre:YZEro?");
            temp  = TekScope.RawIO.ReadString().Trim();
            yzero = Single.Parse(temp);

            // Turn on curve streaming
            TekScope.FormattedIO.WriteLine("CURVEStream?");
            stopWatch.Reset();
            stopWatch.Start();

            // While still collecting curves.  Ends when the user clicks End Test
            while (GatherCurves)
            {
                int    NumBytesCharCount = 0;
                string BlockHeader       = "";

                TekScope.TimeoutMilliseconds = 200;

                // Loop until the block header is found
                while (BlockHeader.Length == 0)
                {
                    try
                    {
                        // Read the length of the string that contains the length of the data
                        // Note: If this times out it just means that no curve has been sent out yet so need to wait again
                        BlockHeader = TekScope.RawIO.ReadString(2);

                        if (BlockHeader == ";\n") // Then it's the terminator from the previous curve so throw it out and try again.
                        {
                            BlockHeader = "";
                        }
                    }
                    catch (IOTimeoutException)
                    {
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }

                    wfmPerSec         = (float)CurveCount / ((float)stopWatch.ElapsedMilliseconds / (float)1000);
                    lblWfmPerSec.Text = wfmPerSec.ToString("f");
                    Application.DoEvents();
                    if (!GatherCurves)
                    {
                        break;
                    }
                }
                if (!GatherCurves)
                {
                    break;
                }

                // Block header has been found.  Prepare to receive waveform data
                if (saveToDisk != SaveToDisk.None)
                {
                    // Create a file with the current date and time as the name
                    curveTime = DateTime.Now;
                    string FileName = String.Format("{0}{1}-{2:D2}-{3:D2}_{4:D2}{5:D2}{6:D2}.{7:D3}.{8}",
                                                    txtSaveDirectory.Text,
                                                    curveTime.Year,
                                                    curveTime.Month,
                                                    curveTime.Day,
                                                    curveTime.Hour,
                                                    curveTime.Minute,
                                                    curveTime.Second,
                                                    curveTime.Millisecond,
                                                    saveToDisk == SaveToDisk.Text ? "csv" : "dat");

                    if (saveToDisk == SaveToDisk.Text)
                    {
                        textFile = new StreamWriter(FileName, false, Encoding.ASCII, BUFFER_SIZE * 10);
                    }
                    else // binary
                    {
                        binaryFile = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.None, BUFFER_SIZE * 8, FileOptions.SequentialScan);
                        binWriter  = new BinaryWriter(binaryFile);
                    }
                }

                // Calculate the xvalue for the first point in the record
                xvalue = (((float)(-pt_off)) * xinc) + xzero;

                // Get the number of bytes that make up the data length string
                NumBytesCharCount = Int32.Parse(BlockHeader.TrimStart('#'), System.Globalization.NumberStyles.HexNumber);

                // Read the data length string
                temp           = TekScope.RawIO.ReadString(NumBytesCharCount);
                DataLength     = int.Parse(temp);
                BytesRemaining = DataLength;

                // Read the back the data, process it and save it to the file
                TekScope.TimeoutMilliseconds = 5000;
                while (BytesRemaining > 0)
                {
                    // Read bytes from scope
                    if (BytesRemaining >= BUFFER_SIZE)
                    {
                        //DataBuffer = TekScope.ReadByteArray(BUFFER_SIZE);
                        DataBuffer      = TekScope.RawIO.Read(BUFFER_SIZE);
                        BytesRemaining -= BUFFER_SIZE;
                    }
                    else
                    {
                        DataBuffer     = TekScope.RawIO.Read(BytesRemaining);
                        BytesRemaining = 0;
                    }

                    // Convert byte values to floating point values then write them to the file
                    foreach (byte DataPoint in DataBuffer)
                    {
                        yvalue = ((Convert.ToSingle((sbyte)DataPoint) - yoff) * ymult) + yzero;

                        switch (saveToDisk)
                        {
                        case SaveToDisk.Binary:
                            // Store the data in binary file as 32-bit floating point XY pairs
                            binWriter.Write(xvalue);
                            binWriter.Write(yvalue);
                            break;

                        case SaveToDisk.Text:
                            textFile.WriteLine(xvalue.ToString() + "," + yvalue.ToString());
                            // Note: Converting to .CSV is very time consuming operation.
                            // Saving in a binary format is much faster and highly recommended for waveforms >= 1 Million points.
                            break;
                        }
                        xvalue += xinc;
                    }
                }

                if (saveToDisk == SaveToDisk.Binary)
                {
                    binWriter.Close();
                    binWriter.Dispose();
                    binaryFile.Dispose();
                }
                else if (saveToDisk == SaveToDisk.Text)
                {
                    textFile.Close();
                    textFile.Dispose();
                }

                CurveCount++;
                wfmPerSec          = (float)CurveCount / ((float)stopWatch.ElapsedMilliseconds / (float)1000);
                lblWfmPerSec.Text  = wfmPerSec.ToString("f");
                lblCurveCount.Text = CurveCount.ToString();
                Application.DoEvents();
            }

            // Send Device Clear to stop the curve streaming
            TekScope.Clear();

            TekScope.Dispose();
            TekScope             = null;
            cmdStartTest.Enabled = true;
            cmdEndTest.Enabled   = false;
        }