コード例 #1
0
 public ScanShipBarCodeForm()
 {
     InitializeComponent();
     // 初始化扫描设备
     scanManager = ScanFactory.CreateScan();
     scanManager.Init();
     scanManager.AttachScanNotify(ScanNotifyHandler);
 }
コード例 #2
0
        /// <summary>
        /// Checks the status of the ongoing scan.
        /// </summary>
        private void PollScanProgress()
        {
            IntPtr    json       = HBFunctions.hb_get_state_json(this.hbHandle);
            string    statusJson = Marshal.PtrToStringAnsi(json);
            JsonState state      = JsonConvert.DeserializeObject <JsonState>(statusJson);

            if (state.State == NativeConstants.HB_STATE_SCANNING)
            {
                if (this.ScanProgress != null)
                {
                    this.ScanProgress(this, new ScanProgressEventArgs
                    {
                        Progress       = state.Scanning.Progress,
                        CurrentPreview = state.Scanning.Preview,
                        Previews       = state.Scanning.PreviewCount,
                        CurrentTitle   = state.Scanning.Title,
                        Titles         = state.Scanning.TitleCount
                    });
                }
            }
            else if (state.State == NativeConstants.HB_STATE_SCANDONE)
            {
                this.titles = new List <Title>();

                var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle);

                string scanJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);

                JsonScanObject scanObject = JsonConvert.DeserializeObject <JsonScanObject>(scanJson);

                foreach (Title title in ScanFactory.CreateTitleSet(scanObject))
                {
                    // Set the Main Title.
                    this.featureTitle = title.IsMainFeature ? title.TitleNumber : 0;

                    this.titles.Add(title);
                }

                this.scanPollTimer.Stop();

                if (this.ScanCompleted != null)
                {
                    this.ScanCompleted(this, new System.EventArgs());
                }
            }
        }
コード例 #3
0
ファイル: SplitFiles.cs プロジェクト: eg467/DocumentScanner
 public SplitFilesControl(DocumentMetadata docData, ScanFactory scanFactory) : this()
 {
     _docData     = docData;
     _scanFactory = scanFactory;
 }
コード例 #4
0
        public void ReadSpectrum(XmlReader reader, TRun run)
        {
            TScan scan = ScanFactory.CreateScan();

            //The cycle number is within a kvp string in the following format: "sample=1 period=1 cycle=1 experiment=1"
            //
            //This is a bit code-soup but I didn't want to spend more than one line on it and it should be robust enough not just to select on index
            //
            //This has only been tested on Sciex converted data
            //
            //Paul Brack 2019/04/03

            bool CycleInfoInID = false;

            if (run.SourceFileTypes[0].EndsWith("wiff", StringComparison.InvariantCultureIgnoreCase) || run.SourceFileTypes[0].ToUpper().EndsWith("scan", StringComparison.InvariantCultureIgnoreCase))
            {
                if (!string.IsNullOrEmpty(reader.GetAttribute("id")) && !string.IsNullOrEmpty(reader.GetAttribute("id").Split(' ').DefaultIfEmpty("0").Single(x => x.Contains("cycle"))))
                {
                    scan.Cycle = int.Parse(reader.GetAttribute("id").Split(' ').DefaultIfEmpty("0").Single(x => x.Contains("cycle")).Split('=').Last());
                    if (scan.Cycle != 0)//Some wiffs don't have that info so let's check
                    {
                        CycleInfoInID = true;
                    }
                }
            }

            bool   cvParamsRead     = false;
            double previousTargetMz = 0;
            int    currentCycle     = 0;
            bool   hasAtLeastOneMS1 = false;
            ScanAndTempProperties <TScan, TRun> scanAndTempProperties = new ScanAndTempProperties <TScan, TRun>(scan, run);

            while (reader.Read() && !cvParamsRead)
            {
                if (reader.IsStartElement())
                {
                    if (reader.LocalName == "cvParam")
                    {
                        switch (reader.GetAttribute("accession"))
                        {
                        case "MS:1000511":
                            scan.MsLevel = int.Parse(reader.GetAttribute("value"));
                            break;

                        case "MS:1000285":
                            scan.TotalIonCurrent = double.Parse(reader.GetAttribute("value"), CultureInfo.InvariantCulture);
                            break;

                        case "MS:1000016":
                            scan.ScanStartTime = double.Parse(reader.GetAttribute("value"), CultureInfo.InvariantCulture);
                            run.StartTime      = Math.Min(run.StartTime, scan.ScanStartTime);
                            run.LastScanTime   = Math.Max(run.LastScanTime, scan.ScanStartTime);  //technically this is the starttime of the last scan not the completion time
                            break;

                        case "MS:1000829":
                            scan.IsolationWindowUpperOffset = double.Parse(reader.GetAttribute("value"), CultureInfo.InvariantCulture);
                            break;

                        case "MS:1000828":
                            scan.IsolationWindowLowerOffset = double.Parse(reader.GetAttribute("value"), CultureInfo.InvariantCulture);
                            break;

                        case "MS:1000827":
                            scan.IsolationWindowTargetMz = double.Parse(reader.GetAttribute("value"), CultureInfo.InvariantCulture);
                            break;
                        }
                    }
                    else if (reader.LocalName == "binaryDataArray")
                    {
                        GetBinaryData(reader, scanAndTempProperties);
                    }
                    if (scan.MsLevel == null && reader.LocalName == "referenceableParamGroupRef")
                    {
                        scan.MsLevel = reader.GetAttribute("ref") == SurveyScanReferenceableParamGroupId ? 1 : 2;
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "spectrum")
                {
                    if (!CycleInfoInID)
                    {
                        if (scan.MsLevel == 1)
                        {
                            currentCycle++;
                            scan.Cycle       = currentCycle;
                            hasAtLeastOneMS1 = true;
                        }
                        //if there is ScanAndTempProperties ms1:
                        else if (hasAtLeastOneMS1)
                        {
                            scan.Cycle = currentCycle;
                        }
                        //if there is no ms1:
                        else
                        {
                            if (previousTargetMz >= scan.IsolationWindowTargetMz)
                            {
                                currentCycle++;
                            }
                            scan.Cycle = currentCycle;
                        }
                    }

                    previousTargetMz = scan.IsolationWindowTargetMz;

                    ProcessScanThreadedOrNot(scanAndTempProperties);
                    cvParamsRead = true;
                }
            }
        }