private void _arduinoRW_ArduinoReadUID(string message) { Action action = () => { if (!TempMessageArduino.Equals(message)) { TempMessageArduino = message; TempUID = message.ToUpper().Trim(new Char[] { ' ', '\n', '\r' }).Substring(1); TempUID = TempUID.Replace(" ", ""); TempReader = Convert.ToInt32(message.Substring(0, 1)); CheckUser(); } }; try { if (InvokeRequired) { Invoke(action); } else { action(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } arduinoRW.ReadUID(); }
private void FormSecurity_Load(object sender, EventArgs e) { this.roomsTableAdapter.FillByName(this.accessControlSystemDataSet.Rooms, ConfigurationManager.AppSettings["Room"].ToString()); Clear_the_Form(); toolStripStatusLabelDate.Text = DateTime.Now.ToLongDateString(); toolStripStatusLabelTime.Text = DateTime.Now.ToShortTimeString(); this.labelObject.Text += ConfigurationManager.AppSettings["Room"].ToString(); this.roomsBindingSource.MoveFirst(); this.id_room = Convert.ToInt32(((DataRowView)this.roomsBindingSource.Current).Row["ID_room"].ToString()); arduinoRW = new ArduinoRW(); arduinoRW.ArduinoPortClose += _arduinoRW_ArduinoPortClose; arduinoRW.ArduinoReadUID += _arduinoRW_ArduinoReadUID; arduinoThread = new Thread(arduinoRW.Start); arduinoThread.IsBackground = true; arduinoThread.Start(); Thread.Sleep(100); arduinoRW.ReadUID(); System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer() { Interval = 1000 }; timer.Tick += new EventHandler(timer_Tick); timer.Start(); }
private void buttonReadKey_Click(object sender, EventArgs e) { arduinoRW.ReadUID(); }