/// <summary> /// 刷新Panel的设置 /// 静态模式有对应的积分时间校正文件,设置Gain校正文件是否调用的函数快速返回,不然会设置错误,导致时间很长 /// 所以这里设置积分时间,再设置是否调用Gain校正文件 /// </summary> public override void RefreshPanelSettings() { try { int result; //设置探测器的工作模式;Rad模式; result = CareRayInterface.CR_set_check_mode((int)checkMode); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("Set mode error, reason: {0}\n", CareRayErrors.CrErrStrList(result)); } //1,设置Trigger同步模式 result = CareRayInterface.CR_set_sync_mode((int)TriggerSyncMode); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("Set sync mode error, reason: {0}\n " + CareRayErrors.CrErrStrList(result)); } //2,设置探测器的曝光时间,延迟时间,等待时间 result = CareRayInterface.CR_set_cycle_time(ExposureTime, DelayTime, WaitTime); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("Set cycle time error, reason: {0}\n", CareRayErrors.CrErrStrList(result)); } //3,设置输出1800I的Gain校正算法 UseCalibrationConfig(Enable1800IGainAlgorithm); } catch (System.Exception ex) { Console.WriteLine("RefreshFixedPanelSettings()...catch..." + ex.Message); } }
private bool TryLink() { Console.WriteLine("0.96 Static try link..."); int result; byte *path = (byte *)Marshal.StringToCoTaskMemAnsi(CapturePub.CareRayPath); result = CareRayInterface.CR_connect_detector(path); bool v = result == (int)KZ_ERROR_TYPE.CR_NO_ERR; if (!v) { Console.WriteLine("Connect default detector (IP:192.168.68.1) error, reason: %s\n", CareRayErrors.CrErrStrList(result)); Console.WriteLine("For dual_system, try to connect another detector (IP:192.168.68.2)...\n\n"); } else { Console.WriteLine("Connect detector successfully"); } if ((IntPtr)path != IntPtr.Zero) { Marshal.FreeCoTaskMem((IntPtr)path); } return(v); }
/// <summary> /// 是否启用Gain校正算法 /// </summary> /// <param name="gain_cal"></param> void UseCalibrationConfig(bool gain_cal) { Console.WriteLine("UseCalibrationConfig(gain_cal={0})", new object[] { gain_cal }); int result; try { userCorrection.fixedCorr = gain_cal; userCorrection.non_fixedCorr = false; userCorrection.portableCorr = false; result = CareRayInterface.CR_set_user_correction(ref userCorrection); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("CR_set_user_correction error, reason: {0}\n", CareRayErrors.CrErrStrList(result)); } else { Console.WriteLine("set gain successfully"); } } catch (System.Exception ex) { Console.WriteLine("UseCalibrationConfig()...catch error:" + ex.Message); } }
private void CaptureParameterSetting_Load(object sender, EventArgs e) { //Capture Parameter string xmlValueString; xmlValueString = CapturePub.readCaptrueValue(XmlField.KZCheckMode); if (xmlValueString == ((int)CareRayInterface.CheckMode.MODE_RAD).ToString()) { comboBoxWorkMode.SelectedIndex = 0; } else if (xmlValueString == ((int)CareRayInterface.CheckMode.MODE_FLUORO_START + 2).ToString()) { comboBoxWorkMode.SelectedIndex = 1; } else if (xmlValueString == ((int)CareRayInterface.CheckMode.MODE_FLUORO_START).ToString()) { comboBoxWorkMode.SelectedIndex = 2; } this.textBoxExposureTime.Text = CapturePub.readCaptrueValue(XmlField.CareRay_ExposureTime); this.textBoxDelayTime.Text = CapturePub.readCaptrueValue(XmlField.CareRay_ExposureDelay); this.textBoxWaitTime.Text = CapturePub.readCaptrueValue(XmlField.CareRay_ExposureWait); string config_file = CapturePub.CareRayPath + "Config.ini"; string PanelIP = CareRayInterface.ReadConfigOptionValue(config_file, "ipAddress"); this.textBoxPanelIP.Text = PanelIP; }
protected void btnOK_Click(object sender, EventArgs e) { //Capture Parameter if (comboBoxWorkMode.SelectedIndex == 0) { CapturePub.saveCaptrueValue(XmlField.KZCheckMode, ((int)CareRayInterface.CheckMode.MODE_RAD).ToString()); } else if (comboBoxWorkMode.SelectedIndex == 1) { CapturePub.saveCaptrueValue(XmlField.KZCheckMode, ((int)CareRayInterface.CheckMode.MODE_FLUORO_START + 2).ToString()); } else if (comboBoxWorkMode.SelectedIndex == 2) { CapturePub.saveCaptrueValue(XmlField.KZCheckMode, ((int)CareRayInterface.CheckMode.MODE_RAD).ToString()); } CapturePub.saveCaptrueValue(XmlField.CareRay_ExposureTime, this.textBoxExposureTime.Text); CapturePub.saveCaptrueValue(XmlField.CareRay_ExposureDelay, this.textBoxDelayTime.Text); CapturePub.saveCaptrueValue(XmlField.CareRay_ExposureWait, this.textBoxWaitTime.Text); string config_file = CapturePub.CareRayPath + "Config.ini"; CareRayInterface.SaveConfigOptionValue(config_file, "ipAddress", textBoxPanelIP.Text.Trim()); this.DialogResult = DialogResult.OK; }
public Capture1800I_096Dynamic() : base() { //是否后台监测Panel网络连接 MonitorPanelNetwork_Background = CapturePub.readCaptrueValue(XmlField.MonitorPanelNetwork_Background) == "T"; //读取Panel IP地址 string config_file = CapturePub.CareRayPath + "Config.ini"; PanelIP = CareRayInterface.ReadConfigOptionValue(config_file, "ipAddress"); LinkPanelThread = new Thread(LinkPanelThreadFun); LinkPanelThread.IsBackground = true; EventCallbak = new CareRayInterface.EventCallbackDelegate(drocEventCallback); }
public override void Cancel() { if (WorkStatus) { //强制中断采集 int result = CareRayInterface.CR_stop_acq_frame(); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("CR_stop_acq_frame error, reason: {0}\n", CareRayErrors.CrErrStrList(result)); } } WorkStatus = false; Kernel32Interface.PostMessage(this.HostHandle, WIN_MSG.WM_CAPTURE_WORKSTATUS, 0, 0); Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_SHOW_PROGRESS, -2, 0); Trigger.Stop(); }
//Show current mode information int showModeInfo() { Console.WriteLine("\nCalling CR_get_detector_info:\n"); int result = CareRayInterface.CR_get_mode_info((int)checkMode, ref modeInfo); if ((int)KZ_ERROR_TYPE.CR_NO_ERR == result) { Console.WriteLine("\t\tModeId={0}\n", modeInfo.modeId); Console.WriteLine("\t\tAcqType={0}\n", modeInfo.acqType); Console.WriteLine("\t\tImageWidth={0}, ImageHeight={0}\n", modeInfo.imageWidth, modeInfo.imageHeight); Console.WriteLine("\t\tLinesPerPixel={0}, ColsPerPixel={0}\n", modeInfo.linesPerPixel, modeInfo.colsPerPixel); Console.WriteLine("\t\tImageSize(in Byte):{0}\n", modeInfo.imageSize); Console.WriteLine("\t\tMaxFrameRate:%f\n", modeInfo.maxFrameRate); Console.WriteLine("\t\tModeDescription:{0}\n", modeInfo.modeDescription); } return(result); }
int showStatusInfo() { Console.WriteLine("\nCalling CR_get_status_info:\n"); int result = CareRayInterface.CR_get_status_info(ref statusInfo); if ((int)KZ_ERROR_TYPE.CR_NO_ERR == result) { Console.WriteLine("\t\tcheckMode: {0}\n", statusInfo.checkMode); Console.WriteLine("\t\tframeRate: {0}\n", statusInfo.frameRate); Console.WriteLine("\t\tdetectorState: {0}\n", statusInfo.detectorState); Console.WriteLine("\t\taveTemperature: {0}\n", statusInfo.temperature.aveTemperature); Console.WriteLine("\t\tmaxTemperature: {0}\n", statusInfo.temperature.maxTemperature); //overhot_flag: see enum TempStatus Console.WriteLine("\t\toverhot: {0}\n", statusInfo.temperature.overhot_flag); } return(result); }
//Show detector information int showDetectorInfo() { Console.WriteLine("\nCalling CR_get_detector_info:\n"); int result = CareRayInterface.CR_get_detector_info(ref detectorInfo); if ((int)KZ_ERROR_TYPE.CR_NO_ERR == result) { Console.WriteLine("\t\tRawImageWidth is: {0}\n", detectorInfo.rawImageWidth); Console.WriteLine("\t\tRawImageHeight is: {0}\n", detectorInfo.rawImageHeight); Console.WriteLine("\t\tMaxPixelValue is: {0}\n", detectorInfo.maxPixelValue); Console.WriteLine("\t\tBitsPerPixel is: {0}\n", detectorInfo.bitsPerPixel); Console.WriteLine("\t\tHardWareVerion is: {0}\n", detectorInfo.hardWareVersion); Console.WriteLine("\t\tSoftWareVerion is: {0}\n", detectorInfo.softWareVersion); Console.WriteLine("\t\tSerialNumber is: {0}\n", detectorInfo.serialNumber); Console.WriteLine("\t\tDetectorDescription is: {0}\n", detectorInfo.detectorDescription); } return(result); }
void buttongainCal_Click(object sender, EventArgs e) { List <ImageObject> images = new List <ImageObject>(); Thread.Sleep(10000); CareRayInterface.CalParams cal_params = new CareRayInterface.CalParams(); int result = CareRayInterface.CR_get_cal_params(ref cal_params); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("CR_get_cal_params error, reason: {0}\n", CareRayErrors.CrErrStrList(result)); return; } int ConfigNumber = cal_params.linear_dose_num * cal_params.linear_num_per_dose; if (ConfigNumber != images.Count) { MessageBox.Show("Please check images."); return; } int v = (ImgCapture as Capture1800I_096Static).performGainCalibrationInTwoSteps(images); if (v == 0) { MessageBox.Show("create gain files successfully."); } else { MessageBox.Show("Fail to create gain files."); } }
public override void CaptureImageData() { int result; #region Step(1):设置采集的帧数 //acqImageNuber = 3; #endregion//End Step(1) #region Step(2):设置工作电压 try { result = CareRayInterface.CR_set_normal_power(); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("CR_set_normal_power error, reason: {0}\n", CareRayErrors.CrErrStrList(result)); Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_CAPTURE_WORKSTATUS, 0, 0); Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_SHOW_PROGRESS, -2, 0); WorkStatus = false; return; } else { Console.WriteLine("Set panel working voltage successfully."); } } catch (System.Exception ex) { Console.WriteLine("CR_set_normal_power error, reason: {0}\n", ex.Message); Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_CAPTURE_WORKSTATUS, 0, 0); Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_SHOW_PROGRESS, -2, 0); WorkStatus = false; return; } #endregion//End Step(2) #region Step(3):刷新Panel的参数设置; Console.WriteLine("Step(3):Refresh panel settings..."); RefreshPanelSettings(); #endregion//End Step(3) #region Step(4):采集之前本底丢弃,刷新探测器的lag //CaptureDarkImage_DiscardDarkImage_BeforeCapture(); #endregion//End Step(4) #region Step(5):动态本底校正; //.... #endregion//End Step(5) #region Step(6):是否内触发采集本底 //... #endregion//End Step(6) //设置状态栏进度信息; int msgID2 = GenerateWinMessage("Preparing irradiation..."); Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_SHOW_PROGRESS, msgID2, 0); //调用函数开始采集; result = CareRayInterface.CR_start_acq_full_image(); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("Step(7):CR_start_acq_image_full error, reason: " + CareRayErrors.CrErrStrList(result)); Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_CAPTURE_WORKSTATUS, 0, 0); Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_SHOW_PROGRESS, -2, 0); WorkStatus = false; return; } else { Console.WriteLine("1800I 0.96 start acquisition successfully."); } }
void drocEventCallback(int eventID, ref CareRayInterface.EventData eventData) { Console.WriteLine("Event ID:" + eventID); switch (eventID) { case (int)CareRayInterface.event_id.EVT_DISCONNECT: case (int)CareRayInterface.event_id.EVT_DETECTOR_ERROR: { int result = CareRayInterface.CR_stop_acq_frame(); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("CR_stop_acq_frame error, reason: {0}\n", CareRayErrors.CrErrStrList(result)); } } break; case (int)CareRayInterface.event_id.EVT_IMAGE_ARRIVE: case (int)CareRayInterface.event_id.EVT_VIDEO_FRAME_INDEX_CHANGED: { //外部中断Cancel();立即退出; if (!WorkStatus) { Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_CAPTURE_WORKSTATUS, 0, 0); Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_SHOW_PROGRESS, -2, 0); WorkStatus = false; return; } //用于判断采集是否结束 acqImageNuber--; //改变采集到的帧数统计; acqBrightImageNumber++; //输出亮场帧数统计信息; Console.WriteLine("Image Number=" + acqBrightImageNumber); //Windows界面输出采集进度; int msgID = GenerateWinMessage("Capturing image number:" + acqBrightImageNumber); Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_SHOW_PROGRESS, msgID, 0); #region Step(1):TCP/IP协议网络从Panel缓冲区取出图像; DateTime tm = DateTime.Now; //log int imageSize = eventData.width * eventData.height * eventData.bits / 8; int imageRows = eventData.height; int imageColumns = eventData.width; ushort *imageData = (ushort *)eventData.data; #region 验证是否丢帧 IntPtr checkPtr = (IntPtr)imageData; int imageID = Marshal.ReadInt32(checkPtr, 0); if (imageID != ImageTrackID) { Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!lost frame ID=" + imageID); } ImageTrackID = imageID; ImageTrackID++; #endregion Console.WriteLine("Step(1):(TCP/IP)Transfer image time=" + (DateTime.Now - tm)); //log #endregion #region Step(2)封装数据到对象ImageObject tm = DateTime.Now; RefreshScale(); ImageObject imageObjectBase = new ImageObject(); ushort[,] imagedata = BufferToArray(imageData, RawFileHeadSize, imageRows, imageColumns); imageObjectBase.pixelSize = this.pixelSize; imageObjectBase.centerX = this.imageCenterX; imageObjectBase.centerY = this.imageCenterY; imageObjectBase.ImageData = imagedata; imageObjectBase.createTime = DateTime.Now; Console.WriteLine("Encapsulate image data to ImageROI time=" + (DateTime.Now - tm)); //log #endregion #region Step(3):将采集到的数据ImageROI对象压入到堆栈中供异步处理 //压入堆栈; imgList.Enqueue(imageObjectBase); //发送消息到采集界面;保存数据库; Kernel32Interface.PostMessage(HostHandle, WIN_MSG.WM_CAPTURE_DATA, (int)captureImageMode, acqBrightImageNumber); #endregion //判断采集是否结束 if (acqImageNuber == 0) { Cancel(); return; } } break; default: Console.WriteLine("Rad image transmission complete default"); break; } }
/// <summary> /// 刷新Panel连接之后固定的配置; /// 一般在Panel连接之后调用一次; /// </summary> void RefreshFixedPanelSettings() { try { //when detected the DROC disconnected with detector by calling //CR_getConnState(), only call CR_connect_detector to reconnect, and don't //call CR_reset_detector any more. int result = 0; result = CareRayInterface.CR_reset_detector(0); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("CR_reset_detector error,reason: {0}\n", CareRayErrors.CrErrStrList(result)); } //输出探测器信息; result = showDetectorInfo(); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { //showDetectorInfo()有注释 } //输出探测器状态信息; //Attention the Temperature, overhot_flag indicates the temperature //status in current detector!!!!!!! result = showStatusInfo(); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { //showStatusInfo()有注释 } //输出探测器型号; int currentDetectorType = CareRayInterface.CR_get_detector_type(); Console.WriteLine("Detector type:{0}", new object[] { ((CareRayInterface.DetectorType)currentDetectorType).ToString() }); //输出探测器的模式信息; result = showModeInfo(); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.WriteLine("Show mode info error, reason: %s\n", CareRayErrors.CrErrStrList(result)); } } catch (System.Exception ex) { Console.WriteLine("RefreshFixedPanelSettings()...catch(1)..." + ex.Message); } try { int result; //设置Gain值; fpga = new CareRayInterface.FpgaReg(); result = CareRayInterface.CR_get_fpga_reg(ref fpga); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.Write("CR_get_fpga_reg error, reason: {0}\n", CareRayErrors.CrErrStrList(result)); } int readoutCntr = fpga.readout_cntr; int gainId = (readoutCntr >> 4) & 0x00000007; Console.WriteLine("Gain Value read from FPGA =" + gainId); gainId = GainValue; Console.WriteLine("Set Gain ID =" + gainId); int readout = fpga.readout_cntr; int readoutCntrPrev = (readout & (~(7 << 4))) | (gainId << 4); fpga.readout_cntr = readoutCntrPrev; //int prmId = (int)((uint)(&fpga.readout_cntr) - (uint)(&fpga.res1)); int prmId = 160; result = CareRayInterface.CR_set_detector_iparam(prmId, readoutCntrPrev); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.Write("CR_set_detector_iparam error, reason: {0}\n", CareRayErrors.CrErrStrList(result)); } fpga = new CareRayInterface.FpgaReg(); result = CareRayInterface.CR_get_fpga_reg(ref fpga); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != result) { Console.Write("CR_get_fpga_reg error, reason: {0}\n", CareRayErrors.CrErrStrList(result)); } readoutCntr = fpga.readout_cntr; gainId = (readoutCntr >> 4) & 0x00000007; Console.WriteLine("Gain ID read 2 from FPGA=" + gainId); } catch (System.Exception ex) { Console.WriteLine("RefreshFixedPanelSettings()...catch(2)..." + ex.Message); } int res = CareRayInterface.CR_register_callback(EventCallbak); if ((int)KZ_ERROR_TYPE.CR_NO_ERR != res) { Console.Write("CR_register_callback error, reason: {0}\n", CareRayErrors.CrErrStrList(res)); } }
private void btnBuildGainSeq_Click(object sender, EventArgs e) { if (tbDoseRate_Image.Text.Trim() == "") { cls_MessageBox.Show("Please input dose rate."); return; } List <ImageObject> images = new List <ImageObject>(); foreach (int i in userControlMutiDicomImages.SelectList) { images.Add(captureImagesNow[i]); } if (images.Count <= 0) { cls_MessageBox.Show("Please select images."); return; } if (this.ImgCapture is CaptureCareRay) { //string path = new string((this.ImgCapture as CaptureCareRay).cal_params.gain_image_dir); string path = @"D:\CareRayCalImgs\C12140510-003\GainImage\"; //Console.WriteLine(path); //path = path.Replace("\\","\\\\"); Console.WriteLine(path); if (!Directory.Exists(path)) { //Console.WriteLine("delete folder"); //Directory.Delete(path, true); Console.WriteLine("create folder"); Directory.CreateDirectory(path); } for (int index = 0; index < images.Count; ++index) { this.writeImageToDisk(path + (object)(index + 1) + ".raw", images[index].ImageData); } int index1 = CareRayInterface.CR_linatech_calibration(); if (index1 != 0) { Console.WriteLine("CR_linear_calibration error, reason: " + CareRayErrors.CrErrStrList(index1)); } else { CareRayInterface.ExpProgress expProg = new CareRayInterface.ExpProgress(); do { int result = CareRayInterface.CR_query_prog_info((int)CareRayInterface.ProgType.CR_CAL_PROG, ref expProg); if (0 == result) { if (1 == expProg.calComplete) { Console.WriteLine("gain cal successfully"); break; } if (0 != expProg.errorCode) { result = expProg.errorCode; Console.WriteLine("fail to gain"); break; } } } while (true); } } return; string sortgainfolder = CapturePub.SaveDFPath;// +DateTime.Now.ToString("yyyy.MM.dd.HHmmss"); CapturePub.saveCaptrueValue(XmlField.SortGainFolder, sortgainfolder); string gainFolder = sortgainfolder + "\\gain"; if (!Directory.Exists(gainFolder)) { Directory.CreateDirectory(gainFolder); } if (!Directory.Exists(CapturePub.SaveDFPath + "\\offset")) { Directory.CreateDirectory(CapturePub.SaveDFPath + "\\offset"); } images.Sort(); List <ushort[, ]> dataList = new List <ushort[, ]>(); foreach (ImageObject obj in images) { dataList.Add(obj.ImageData); } string doserate = tbDoseRate_Image.Text.Trim(); string gainFile = "gain_" + DateTime.Now.ToString("yyyy.MM.dd.HHmmss") + "_" + doserate + "cGy(min)_" + getGainString((CapturePKI.ElectricCapacityMode)comboBoxGainMode_Image.SelectedIndex) + "_" + dataList[0].GetLength(0) + "x" + dataList[0].GetLength(1) + ".his"; string gain_fullPath = gainFolder + "\\" + gainFile; SaveasHisFile(gain_fullPath, dataList, 1000); CapturePub.saveCaptrueValue(XmlField.GainSeqFile_Image, gain_fullPath); if (ImgCapture is CapturePKI) { (ImgCapture as CapturePKI).SetLinkCorrection(); } cls_MessageBox.Show("Create gain sequence successfully!"); }