private void configs() { ocr.threshold = Properties.Settings.Default.threshold; serialPort1.BaudRate = Properties.Settings.Default.BaudRate; portName = Properties.Settings.Default.PortName; matches = new regMatch[MATCHPATTERNS]; scripts = new Scripts[MATCHPATTERNS + 1]; matches[0] = new regMatch( Properties.Settings.Default.exp1, Properties.Settings.Default.accumlate1 ); scripts[0] = new Scripts(serialPort1, this, Properties.Settings.Default.script1); matches[1] = new regMatch( Properties.Settings.Default.exp2, Properties.Settings.Default.accumlate2 ); scripts[1] = new Scripts(serialPort1, this, Properties.Settings.Default.script2); matches[2] = new regMatch( Properties.Settings.Default.exp3, Properties.Settings.Default.accumlate3 ); scripts[2] = new Scripts(serialPort1, this, Properties.Settings.Default.script3); removeSpace = Properties.Settings.Default.removeSpace; scripts[3] = new Scripts(serialPort1, this, Properties.Settings.Default.script4); timer1.Interval = Properties.Settings.Default.samplePeriod; }
private void doOcr() { int pos = 0, len = 0; Invoke((MethodInvoker) delegate() { toolStripProgressBar1.ForeColor = Color.PaleGreen; toolStripProgressBar1.Step = 100; toolStripProgressBar1.PerformStep(); }); ocr.doOcr(); Invoke((MethodInvoker) delegate() { toolStripProgressBar1.Value = 0; }); OcrCore.OcrResults ocrRes = ocr.getResults(); String str1 = ocrRes.text.Replace("\n", System.Environment.NewLine); if (removeSpace) { str1 = str1.Replace(" ", String.Empty); } string str = str1;//表示用バックアップ int ii = 0; String str2 = ""; matched = null; for (int i = 0; i < matches.Length; i++) { if (matches[i].checkMatch(str1)) { pos = matches[i].pos; len = matches[i].len; } if (matches[i].result == regMatch.RESULTS.FOUND) { str2 = "Found pattern" + (i + 1).ToString(); str1 = null;//以降確実にUNMATCHにする } else if (matches[i].result == regMatch.RESULTS.MATCH) { matched = matches[i]; str2 = "Matched pattern" + (i + 1).ToString(); str1 = null;//以降確実にUNMATCHにする ii = i; } } this.Invoke((MethodInvoker) delegate() { ShowResult(str, str2, ocrRes.bmp, pos, len); }); if (matched != null) { selScript = scripts[ii]; actScript(); } else { busy = false; } }
public Form_Settings(Form_Main parent, OcrCore ocr, SerialPort port, regMatch[] match, Scripts[] scripts, Timer tmr) { InitializeComponent(); this.ocr = ocr; this.port = port; this.match = match; this.scripts = scripts; numericUpDown1.Value = ocr.threshold; String[] ports = SerialPort.GetPortNames(); comboBox1.Items.Clear(); comboBox1.Items.AddRange(ports); int li = comboBox1.FindString(port.PortName); if (li >= 0) { comboBox1.SelectedIndex = li; } comboBox2.Items.Clear(); comboBox2.Items.Add("9600"); comboBox2.Items.Add("38400"); comboBox2.Items.Add("115200"); li = comboBox2.FindString(port.BaudRate.ToString()); if (li < 0) { li = 0; } comboBox2.SelectedIndex = li; this.parent = parent; checkBox1.Checked = parent.removeSpace; matchText = new TextBox[tabControl1.TabCount]; for (int i = 0; i < tabControl1.TabCount - 1; i++) { matchText[i] = new TextBox(); } accumlate = new TextBox[tabControl1.TabCount]; for (int i = 0; i < tabControl1.TabCount - 1; i++) { accumlate[i] = new TextBox(); } script = new TextBox[tabControl1.TabCount]; for (int i = 0; i < tabControl1.TabCount; i++) { script[i] = new TextBox(); } test = new Button[tabControl1.TabCount]; for (int i = 0; i < tabControl1.TabCount; i++) { test[i] = new Button(); } for (int i = 0; i < tabControl1.TabCount - 1; i++) { tabControl1.SelectedIndex = i; Label l1 = new Label(); l1.Location = new Point(6, 16); l1.AutoSize = true; l1.Text = "Match text"; tabControl1.TabPages[i].Controls.Add(l1); Label l2 = new Label(); l2.Location = new Point(118, 72); l2.AutoSize = true; l2.Text = "Accumlate"; tabControl1.TabPages[i].Controls.Add(l2); Label l3 = new Label(); l3.Location = new Point(6, 92); l3.AutoSize = true; l3.Text = "Script"; tabControl1.TabPages[i].Controls.Add(l3); tabControl1.TabPages[i].Controls.Add(matchText[i]); matchText[i].Location = new Point(6, 34); matchText[i].Size = new Size(263, 22); tabControl1.TabPages[i].Controls.Add(matchText[i]); matchText[i].TextChanged += new EventHandler(matchText_TextChanged); accumlate[i].Location = new Point(213, 69); accumlate[i].Size = new Size(52, 22); tabControl1.TabPages[i].Controls.Add(accumlate[i]); accumlate[i].TextChanged += new EventHandler(accumlate_TextChanged); } for (int i = 0; i < tabControl1.TabCount; i++) { script[i].Location = new Point(6, 110); script[i].Size = new Size(278, 140); script[i].Multiline = true; script[i].ScrollBars = ScrollBars.Vertical; tabControl1.TabPages[i].Controls.Add(script[i]); script[i].Text = scripts[i].myScript; script[i].TextChanged += new EventHandler(script_TextChanged); test[i].Location = new Point(209, 263); test[i].Size = new Size(75, 23); test[i].Text = "Test"; tabControl1.TabPages[i].Controls.Add(test[i]); test[i].Click += new EventHandler(test_Click); } Label lb = new Label(); lb.AutoSize = true; lb.Text = "Script for [STOP] button pressed."; lb.Location = new Point(6, 90); tabControl1.TabPages[tabControl1.TabCount - 1].Controls.Add(lb); for (int i = 0; i < tabControl1.TabCount - 1; i++) { regMatch tmpMatch = match[i]; matchText[i].Text = String.Copy(tmpMatch.exps); accumlate[i].Text = tmpMatch.accumlate.ToString(); } MaximumSize = new Size(370, 585); MinimumSize = new Size(370, 585); samplePeriod = tmr; nm_SamplePeriod.Value = tmr.Interval; }