private void SaveButton_Click(object sender, EventArgs e) { ///////////////////// // SAVE FILE ///////////////////// Byte DeviceID; String DeviceSerialNumber; // Get Serial Number and ID int RetVal = GBMSAPI_NET_DeviceSettingRoutines.GBMSAPI_NET_GetCurrentDevice( out DeviceID, out DeviceSerialNumber); if (RetVal != GBMSAPI_NET_ErrorCodes.GBMSAPI_NET_ERROR_CODE_NO_ERROR) { GBMSAPI_Example_Util.GBMSAPI_Example_ManageErrors( RetVal, "SaveButton_Click,GBMSAPI_GetImageSize"); return; } // build file name // ver 2.10.0.0: scan area instead of flat/not flat //String FName = GBMSAPI_Example_Util.GBMSAPI_Example_GetDevNameFromDevID(DeviceID) + "_" + // (DeviceSerialNumber) + "_" + // ((this.FlatScanArea == true) ? ("FLAT") : ("ROLL")) + ".raw"; String FName = GBMSAPI_Example_Util.GBMSAPI_Example_GetDevNameFromDevID(DeviceID) + "_" + (DeviceSerialNumber) + "_" + this.GetAreaNameFromCheckedRadioButton() + ".raw"; // end ver 2.10.0.0: scan area instead of flat/not flat // build image array for saving Byte [] CalImageArray = new Byte[this.CalibrationImageSX * this.CalibrationImageSY]; if (CalImageArray == null) { MessageBox.Show("MEMORY ALLOCATION ERROR in SaveButton_Click(): close application", "HEAVY ERROR"); return; } Marshal.Copy(this.CalibrationImage, CalImageArray, 0, CalImageArray.Length); // save image on file System.IO.FileStream FS = System.IO.File.Create(FName); if (FS != null) { FS.Write(CalImageArray, 0, CalImageArray.Length); FS.Close(); MessageBox.Show("Image saved in " + FName, "Calibration results"); } else { MessageBox.Show("Cannot save file " + FName, "WARNING"); } }
private void UpdateListButton_Click(object sender, EventArgs e) { this.Enabled = true; Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); try { this.DeviceTypeComboBox.Items.Clear(); //////////////////////////////// ///// 获取设备列表存到数组中,最多存储127个设备。GBMSAPI_NET_MAX_PLUGGED_DEVICE_NUM=127常量 //////////////////////////////// GBMSAPI_NET_DeviceInfoStruct[] AttachedDeviceList = new GBMSAPI_NET_DeviceInfoStruct[ GBMSAPI_NET_DeviceInfoConstants.GBMSAPI_NET_MAX_PLUGGED_DEVICE_NUM]; Console.WriteLine(GBMSAPI_NET_DeviceInfoConstants.GBMSAPI_NET_MAX_PLUGGED_DEVICE_NUM); for (int i = 0; i < GBMSAPI_NET_DeviceInfoConstants.GBMSAPI_NET_MAX_PLUGGED_DEVICE_NUM; i++) { AttachedDeviceList[i] = new GBMSAPI_NET_DeviceInfoStruct(); } int AttachedDeviceNumber; uint USBErrorCode; int RetVal = GBMSAPI_NET_DeviceSettingRoutines.GBMSAPI_NET_GetAttachedDeviceList( AttachedDeviceList, out AttachedDeviceNumber, out USBErrorCode); Console.WriteLine(AttachedDeviceNumber); if (RetVal != GBMSAPI_NET_ErrorCodes.GBMSAPI_NET_ERROR_CODE_NO_ERROR || AttachedDeviceNumber <= 0) { if (RetVal != GBMSAPI_NET_ErrorCodes.GBMSAPI_NET_ERROR_CODE_NO_ERROR) { GBMSAPI_Example_Util.GBMSAPI_Example_ManageErrors(RetVal, USBErrorCode, "UpdateListButton_Click"); MessageBox.Show("Error in GBMSAPI_NET_GetAttachedDeviceList function: " + RetVal); } return; } // Console.WriteLine(RetVal); //////////////////////////////// //// Store device list 存储设备列表 //////////////////////////////// for (int i = 0; i < AttachedDeviceNumber; i++) { String StrToAdd = GBMSAPI_Example_Util.GBMSAPI_Example_GetDevNameFromDevID( AttachedDeviceList[i].DeviceID); StrToAdd += " " + (AttachedDeviceList[i].DeviceSerialNumber);//获取设备型号 this.DeviceTypeComboBox.Items.Add(StrToAdd); } if (AttachedDeviceNumber > 0) { this.DeviceTypeComboBox.SelectedIndex = 0;//指定索引号为0 } } catch (Exception ex) { MessageBox.Show("Error in UpdateListButton_Click function: " + ex.Message); this.Close(); } finally { Cursor.Current = Cursors.Default; this.Enabled = true; } }