Beispiel #1
0
        /// <summary>
        /// Handles closing this object and sub-objects that support being closed.
        /// </summary>
        /// <returns>Returns true if close was successful.</returns>
        public bool Close()
        {
            bool closeSuccess = true;

            RootNode = null;

            if (SaveFile.Close())
            {
                SaveFile = null;
            }
            else
            {
                closeSuccess = false;
            }

            if (StaticData.Close())
            {
                StaticData = null;
            }
            else
            {
                closeSuccess = false;
            }

            return(closeSuccess);
        }
Beispiel #2
0
    /// <summary>
    /// Creates a new save file and refreshes the scene UI
    /// </summary>
    /// <param name="name">name of the save file to create</param>
    public void Create(string name)
    {
        SaveFile sdb = new SaveFile(name);

        sdb.Close();
        RefreshSaveFileList();
    }
Beispiel #3
0
        public void Save()
        {
            var saveFile = new SaveFile(_filename);

            SavePlayer(saveFile);
            SaveInventory(saveFile);
            SavePersistenceComponents(saveFile);

            saveFile.Close();
        }
Beispiel #4
0
        public void Load()
        {
            var saveFile = new SaveFile(_filename);

            LoadPlayer(saveFile);
            LoadInventory(saveFile);
            LoadPersistenceComponents(saveFile);

            saveFile.Close();
        }
    [TearDown] public void Dispose()
    {
        //deletes the testing save files
        if (saveFile.IsOpen())
        {
            saveFile.Close();
        }
        SaveFile.DeleteSaveFile("testing", saveFile.GetPath());
        //clear the console
        /*/*/
        var assembly = Assembly.GetAssembly(typeof(UnityEditor.ActiveEditorTracker));
        var type     = assembly.GetType("UnityEditor.LogEntries");
        var method   = type.GetMethod("Clear");

        method.Invoke(new object(), null);
        //*/
    }
        private void cmdStartTest_Click(object sender, EventArgs e)
        {
            System.DateTime CurveTime;
            float           wfmPerSec = 0;

            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            string       temp;
            bool         saveToDisk = cbxSaveToDisk.Checked;
            StreamWriter SaveFile   = 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)
            {
                // Check that the save directory is valid
                if (!System.IO.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;
                }

                if (saveToDisk)
                {
                    // 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}.csv",
                                                    txtSaveDirectory.Text,
                                                    CurveTime.Year,
                                                    CurveTime.Month,
                                                    CurveTime.Day,
                                                    CurveTime.Hour,
                                                    CurveTime.Minute,
                                                    CurveTime.Second,
                                                    CurveTime.Millisecond);
                    SaveFile = new StreamWriter(FileName, false, Encoding.ASCII, BUFFER_SIZE * 10);
                }

                // 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 to .csv file
                    foreach (byte DataPoint in DataBuffer)
                    {
                        yvalue = ((Convert.ToSingle((sbyte)DataPoint) - yoff) * ymult) + yzero;
                        if (saveToDisk)
                        {
                            SaveFile.WriteLine(xvalue.ToString() + "," + yvalue.ToString());
                        }
                        // Note: Converting to .CSV is very time consuming operation.
                        // Save in a binary format to maximize speed.  Highly recommended for waveforms >= 1 Million points.
                        xvalue += xinc;
                    }
                }

                if (saveToDisk)
                {
                    SaveFile.Close();
                }

                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;
        }
Beispiel #7
0
 /// <summary>
 /// Closes the currently opened save file
 /// </summary>
 public void Close()
 {
     rightBlockImage.SetActive(true);
     leftBlockImage.SetActive(false);
     saveFile.Close();
 }
Beispiel #8
0
 [TearDown] public void Dispose()
 {
     //deletes the testing save files
     saveFile.Close();
     SaveFile.DeleteSaveFile("testing", saveFile.GetPath());
 }
Beispiel #9
0
        public bool Process()
        {
            BoardSize = DefaultBoardSize;
            ReadFile lInput = new ReadFile();

            if (string.IsNullOrEmpty(InputFileName))
            {
                lInput.OpenConsole();
            }
            else
            {
                lInput.OpenFile(InputFileName);
            }

            if (lInput.IsError())
            {
                return(SetErrorMessage(lInput));
            }

            SGFTokens lTokens = SGFScanner.Tokenize(lInput);

            if (lTokens.IsError())
            {
                return(SetErrorMessage(lTokens));
            }

            if (RemoveWhiteSpace)
            {
                lTokens.RemoveAllWhiteSpace();
            }

            lTokens.ProcessProperties(ProcessProperty);

            if (Pretty)
            {
                lTokens.Pretty();
            }

            SaveFile lOutput = new SaveFile();

            try
            {
                if (string.IsNullOrEmpty(OutputFileName))
                {
                    lOutput.Create();
                }
                else
                {
                    lOutput.Create(OutputFileName);
                }

                if (lOutput.IsOk())
                {
                    lTokens.ToFile(lOutput);
                }

                if (lOutput.IsError())
                {
                    return(SetErrorMessage(lOutput));
                }
            }
            finally
            {
                lOutput.Close();
            }
            return(true);
        }