/// <summary> /// ContextMenu ItemClick event loads registers from file. /// </summary> private void regContextMenu_ItemClick_loadFromFile(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Select File"; openFileDialog.Filter = "x-IMU Binary Files (*.bin)|*.bin|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) { x_IMU_API.xIMUfile xIMUfile = new x_IMU_API.xIMUfile(openFileDialog.FileName.ToString()); xIMUfile.RegisterDataRead += new x_IMU_API.xIMUfile.onRegisterDataRead(delegate(object s, x_IMU_API.RegisterData r) { registerTreeView.ApplyRegisterData(r, false); }); xIMUfile.Read(); if (xIMUfile.ReadErrors != 0) { MessageBox.Show(xIMUfile.ReadErrors.ToString() + " read errors occurred.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } xIMUfile.Close(); } }
/// <summary> /// ContextMenu ItemClick event saves all registers to file. /// </summary> private void regContextMenu_ItemClick_saveAllToFile(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Select File"; saveFileDialog.Filter = "x-IMU Binary Files (*.bin)|*.bin|All files (*.*)|*.*"; saveFileDialog.FileName = "savedRegisters" + registerTreeNodeTextBox_deviceID.TextBox.Text + ".bin"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { x_IMU_API.xIMUfile xIMUfile = new x_IMU_API.xIMUfile(saveFileDialog.FileName.ToString(), true); foreach (TreeNode rootNode in registerTreeView.Nodes) { WriteAllChildRegisterTreeNode(xIMUfile, rootNode); } xIMUfile.Close(); } }
/// <summary> /// Button Click event disables form control and starts binary file conversion in new thread. /// </summary> private void button_convertBinaryFileConvert_Click(object sender, EventArgs e) { // Error if file not exist if (!File.Exists(textBox_convertBinaryFileFilePath.Text)) { MessageBox.Show("File does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Disable SD card form controls textBox_convertBinaryFileFilePath.Enabled = false; button_convertBinaryFileBrowse.Enabled = false; button_convertBinaryFileConvert.Enabled = false; button_convertBinaryFileConvert.Text = "Converting..."; // Create process dialog binaryFileConverterProgressDialog = new ProgressDialog(this.Handle); binaryFileConverterProgressDialog.Title = "Converting Binary File"; binaryFileConverterProgressDialog.CancelMessage = "Cancelling..."; binaryFileConverterProgressDialog.Line1 = "Converting to binary file to CSV files"; binaryFileConverterProgressDialog.Line3 = "Initialising x-IMU file reader."; binaryFileConverterProgressDialog.ShowDialog(); binaryFileConverterProgressDialog.Value = 0; // Create file converter objects binaryFileConverterCSVfileWriter = new x_IMU_API.CSVfileWriter(Path.GetDirectoryName(textBox_convertBinaryFileFilePath.Text) + "\\" + Path.GetFileNameWithoutExtension(textBox_convertBinaryFileFilePath.Text)); x_IMU_API.xIMUfile xIMUfile = new x_IMU_API.xIMUfile(textBox_convertBinaryFileFilePath.Text); xIMUfile.xIMUdataRead += new x_IMU_API.xIMUfile.onxIMUdataRead(xIMUfile_xIMUdataRead); xIMUfile.AsyncReadProgressChanged += new x_IMU_API.xIMUfile.onAsyncReadProgressChanged(xIMUfile_AsyncReadProgressChanged); xIMUfile.AsyncReadCompleted += new x_IMU_API.xIMUfile.onAsyncReadCompleted(xIMUfile_AsyncReadCompleted); xIMUfile.RunAnsycRead(); }