/// <summary> /// Download program settings ("LJ -> PC" button pressed) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _btnDownloadProgram_Click(object sender, EventArgs e) { if (_txtProgramFilePath.Text.Length == 0) { return; } // Parameter LJV7IF_TARGET_SETTING setting = GetSelectedProgramTargetSetting(); UInt32 size = GetSelectedProgramDataSize(); // Allocate buffer byte[] receiveBuffer = new byte[size]; using (PinnedObject pin = new PinnedObject(receiveBuffer)) { // Download Rc rc = (Rc)NativeMethods.LJV7IF_GetSetting(DEVICE_ID, SettingDepth.Running, setting, pin.Pointer, size); if (!CheckReturnCode(rc)) { return; } } // Save program data using (FileStream fs = new FileStream(_txtProgramFilePath.Text, FileMode.Create)) using (BinaryWriter writer = new BinaryWriter(fs)) { writer.Write(receiveBuffer); } }
/// <summary> /// Upload program settings <![CDATA[("LJ <- PC" button pressed)]]> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _btnUploadProgram_Click(object sender, EventArgs e) { if (_txtProgramFilePath.Text.Length == 0) { return; } if (File.Exists(_txtProgramFilePath.Text) == false) { return; } // Parameter LJV7IF_TARGET_SETTING setting = GetSelectedProgramTargetSetting(); UInt32 size = GetSelectedProgramDataSize(); // Allocate buffer byte[] receiveBuffer = new byte[size]; // Load program data using (FileStream fs = new FileStream(_txtProgramFilePath.Text, FileMode.Open)) { //It is a very simple validation method. You should use a more certain method. if (fs.Length != size) { MessageBox.Show("File size is not match."); return; } using (BinaryReader reader = new BinaryReader(fs)) { reader.Read(receiveBuffer, 0, (int)size); } } using (PinnedObject pin = new PinnedObject(receiveBuffer)) { // Upload uint error = 0; Rc rc = (Rc)NativeMethods.LJV7IF_SetSetting(DEVICE_ID, SettingDepth.Running, setting, pin.Pointer, size, ref error); if (!CheckReturnCode(rc)) { return; } } }
internal static extern int LJV7IF_GetSetting(int lDeviceId, SettingDepth byDepth, LJV7IF_TARGET_SETTING TargetSetting, IntPtr pData, uint dwDataSize);