public MainForm() { //setup window InitializeComponent(); depthIndicator = new DepthIndicator() { Location = new Point(0, 100) }; attitudeIndicator = new AttitudeIndicator() { Location = new Point(100, 100) }; headingIndicator = new HeadingIndicator() { Location = new Point(600, 100) }; Controls.Add(depthIndicator); Controls.Add(attitudeIndicator); Controls.Add(headingIndicator); //setup devices BetterSerialPort port = new BetterSerialPort("COM5", 500000); port.Open(); portLabel.Text = string.Format("{0}@{1}baud", port.PortName, port.BaudRate); comms = new SerialCommunication(port); comms.Stopped += comms_Stopped; comms.Started += comms_Started; //comms.Connect(); depthSensor = new DepthSensor(); orientationSensor = new OrientationSensor(); statusSensor = new StatusSensor(); propulsionSensor = new PropulsionSensor(); versionSensor = new VersionSensor(); statusActuator = new StatusActuator(); propulsionActuator = new PropulsionActuator(); toolsActuator = new ToolsActuator(); //update displays when sensors polled orientationSensor.Updated += OrientationSensor_Updated; depthSensor.Updated += DepthSensor_Updated; //get ROV firmware version info comms.Queue.Enqueue(versionSensor); //go Fullscreen //GoFullscreen(); //do this in the designer }
//public event EventHandler TenElapsed, HundredElapsed, ThousandElapsed; public SerialCommunication(BetterSerialPort port) : base() { //Communications Process this.port = port; //connection between UI and background threads is a queue of Devices that need updating devices = new ConcurrentQueue <GenericAbstractDevice>(); //background loop runs on this thread thread = new Thread(new ThreadStart(BackgroundLoop)); thread.SetApartmentState(ApartmentState.STA); //for UI compatibility thread.IsBackground = true; //get going thread.Start(); //port.Open(); //error when port opened in constructor }
public MainForm() { //controller pilot = X.Gamepad_1; pilot.Enable = true; pilot.Update(); //must call update right after setting enable to true in order for it to connect //setup window KeyPreview = true; InitializeComponent(); armButton.Enabled = false; resetButton.Enabled = false; //setup devices string portName = "COM6"; try { portName = BetterSerialPort.GetPortNames()[0]; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "No Serial ports available"); } BetterSerialPort port = new BetterSerialPort(portName, 4800); portLabel.Text = string.Format("{0}@{1}baud", port.PortName, port.BaudRate); comms = new SerialCommunication(port); comms.Stopped += comms_Stopped; comms.Started += comms_Started; comms.CommunicationException += Comms_CommunicationException; //comms.Connect();*/ rov = new ROV(comms); //update displays when sensors polled rov.OrientationSensor.Updated += OrientationSensor_Updated; rov.DepthSensor.Updated += DepthSensor_Updated; // enumerate video devices videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); for (int i = 0; i < videoDevices.Count; i++) { if (videoDevices[i].Name.Equals("OEM Device")) { videoSource = new VideoCaptureDevice(videoDevices[i].MonikerString); videoSource.CrossbarVideoInput = videoSource.AvailableCrossbarVideoInputs[1]; videoSource.VideoResolution = videoSource.VideoCapabilities[1]; } } // set NewFrame event handler try { videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame); } catch (NullReferenceException potato) { //fill in later, catch made temporarily to ignore NullReferenceException } picture.SizeMode = PictureBoxSizeMode.StretchImage; }