void Camera_OnNewFrame() { if (_isClosing) { return; } try { Bitmap image = _cameraControl.Camera.GetCurrentBitmap; var found = GetDetectedImage(image); if (found == UCProgramItem.ProgramItemEnum.NA) { } else if (_lastDetectedItem != found && found == UCProgramItem.ProgramItemEnum.Start) { say("Running your program"); _currentRunningIndex = 0; flowLayoutPanel1.Invoke(new Action(() => { var item = (UCProgramItem)flowLayoutPanel1.Controls[_currentRunningIndex]; item.BackColor = Color.Green; _executor.StartScriptASync(item.GetCode()); })); } else if (_lastDetectedItem != found) { flowLayoutPanel1.Invoke(new Action(() => Invokers.AddControl(flowLayoutPanel1, new UCProgramItem(found)))); say(string.Format("Added {0} command", found)); } _lastDetectedItem = found; // Rather than creating a new bitmap for the picturebox, we simply overwrite the bitmap data with the bmTmp data // This way, when the bmpTmp is destroyed from the using, the picturebox has the brand new image data pictureBox1.Invoke(new Action(() => EZ_B.Camera.CopyBitmapMemory(image, (Bitmap)pictureBox1.Image))); Invokers.SetRefresh(pictureBox1); } catch (Exception ex) { Invokers.SetAppendText(tbLog, true, ex.ToString()); Invokers.SetEnabled(btnAttachCamera, true); } }
private void _lidarService_OnStart() { if (IsClosing) { return; } Invokers.SetText(btnConnect, "Stop"); Invokers.SetBackColor(btnConnect, Color.Red); Invokers.SetForeColor(btnConnect, Color.White); Invokers.SetEnabled(groupBox3, false); ARC.Scripting.VariableManager.SetVariable(_cf.STORAGE[ConfigTitles.IS_LIDAR_RUNNING_VARIABLE].ToString(), true); _stopWatch.Restart(); }
void detach() { if (_cameraControl != null) { if (!_isClosing) { EZ_Builder.EZBManager.Log("Detaching from {0}", _cameraControl.Text); } _cameraControl.Camera.OnNewFrame -= Camera_OnNewFrame; _cameraControl = null; } if (!_isClosing) { Invokers.SetEnabled(btnAttachCamera, true); Invokers.SetText(btnAttachCamera, "Attach Camera"); } }