public RoboUSBLinkApp() { MainThreadQueue = new Queue<RoboUSBLinkComm.VoidFunc>(); AsyncResults = new List<IAsyncResult>(); Application.EnableVisualStyles(); Application.Idle += new EventHandler(this.InvokeApplicationThreadItems); Comm = new RoboUSBLinkComm("/dev/ttyACM0", this.MarshalToMainThread); MainForm = new RoboUSBLinkForm(Comm); MainForm.FormClosing += HandleMainFormFormClosing; MainForm.Load += (sender, e) => Comm.Start(); MainForm.Show(null); }
public RoboUSBLinkForm(RoboUSBLinkComm comm) { Comm = comm; this.Size = new Size(800, 600); //this.DoubleBuffered = true; this.Text = "Robot Status"; InitFonts(); InitControls(); Data = new RoboDataModel(comm); Data.BoardData += HandleDataBoardData; Data.BoardOffline += HandleDataBoardOffline; Data.CommOffline += HandleCommOffline; Data.CommOnline += HandleCommOnline; Data.RangeChanged += HandleRangeChanged; Data.VoltageChanged += HandleVoltageChanged; Data.DebugMessage += HandleDebugMessage; }
private void MarshalToMainThread(RoboUSBLinkComm.VoidFunc func) { lock(MainThreadQueue) { MainThreadQueue.Enqueue(func); if (!isMarshaling) { isMarshaling = true; // if this generates too much garbage collection pressure, fix it then IAsyncResult ar = MainForm.BeginInvoke(new RoboUSBLinkComm.VoidFunc(this.InvokeOnMainThread)); AsyncResults.Add(ar); } } for (int i = 0; i < AsyncResults.Count; ++i) { IAsyncResult ar = AsyncResults[i]; if (ar.IsCompleted) { MainForm.EndInvoke(ar); AsyncResults.RemoveAt(i); --i; } } }
private void AttachToComm(RoboUSBLinkComm comm) { }