/*setup timers, connections and variables*/ public UI_NetStatusPanel() { string errmsg = ""; InitializeComponent(); //Setup scalers and controls that must be scaled UIsetup(); _cmdUpdate = Update_CommandUI; _iofeedback = Update_IO_Displays; // Setup the API to use local USB devices if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { set_display1("error: " + errmsg); Logging.Add("Cant initiaet Yocto API, do you have another instance running?"); } else { Logging.Add("Yapi Initiated"); } //Set Sensors 1 and 2 sensor1 = YLightSensor.FindLightSensor("L1" + ".lightSensor"); if (sensor1 == null) { set_display1("no L1 sensor"); } else { set_display1("L1 Ok"); } sensor2 = YLightSensor.FindLightSensor("L2" + ".lightSensor"); if (sensor2 == null) { set_display2("no L2 sensor"); Logging.Add("L1 not connected"); } else { set_display2("L2 Ok"); } /*delegates for ui updates*/ _updatedisplay1 = (set_display1); _updatedisplay2 = (set_display2); _updatefeedback = (Update_feedback); _ipConfig = Update_IP_Config; Logic.Initialise_Cameras(); Servlet.Userinterface = this; ///assigning treference to ui for the servlets to conduct updates. This needs to be changed! Logic.Start(); //start a timer _UsbLightReading = new System.Threading.Timer(Lsensor_Tick, null, 0, 1000); //start a timer _NetworkTimer = new System.Threading.Timer(Nmanager.Tick, null, 0, 1000); }
/*Is called when a frame is recieved from network. Updates accoring to received settings*/ public void Update_Command(Command recieved) { Logging.Add(recieved.LogChanges); if (Logic.Status.Active == false && recieved.Active == true) //triggers if currently cameras are not active, and they are commanded to turn on { //if user provided no if (recieved.Foldername.Length == 0) { DateTime folderstamp = DateTime.Now; Logic.CurrentPath = Logic.StaticPath + folderstamp.Hour.ToString() + "." + folderstamp.Minute.ToString() + " on " + folderstamp.Day.ToString() + "." + folderstamp.Month.ToString(); } else { Logic.CurrentPath = Logic.StaticPath + recieved.Foldername; } if (System.IO.Directory.Exists(Logic.CurrentPath)) { //if folder exists do nothign } else { System.IO.Directory.CreateDirectory(Logic.CurrentPath); } Logging.Add("Starting imaging, saving to " + Logic.CurrentPath); Logic.Status.Active = recieved.Active; Logic.Start(); } else if (Logic.Status.Active == false && recieved.Active == false) { } else if (Logic.Status.Active == true && recieved.Active == false) { Logic.Status.Active = recieved.Active; Logging.Add("Stopping Imaging"); } else if (Logic.Status.Active == true && recieved.Active == true) { } else { Logging.Add("Status.Imaging or cmd.Imaging is undefined! This is imposible! "); throw new Exception("Status.Imaging or cmd.Imaging is undefined! This is imposible! "); } if (Logic.Status.Gain != recieved.Gain) { Logging.Add("Gain changed to " + recieved.Gain.ToString()); Logic.Status.Gain = recieved.Gain; } else { } //Set exposure, but only if sersor drive exposure is disabled Logic.Status.SensorDrivenExposure = recieved.SensorDrivenExposure; Logic.Status.SensorResponce = recieved.SensorResponce; if (Logic.Status.SensorDrivenExposure) { //do nothing, exposure will be set by sensors } else { if (Logic.Status.Exposureμs != recieved.Exposureμs) { Logging.Add("Exposure changed to " + recieved.Exposureμs.ToString()); Logic.Status.Exposureμs = recieved.Exposureμs; } } if (Logic.Status.FPS != recieved.FPS) { Logging.Add("FPS changed to " + recieved.FPS.ToString()); Logic.Status.FPS = recieved.FPS; } else { } if (Logic.Status.curBitDepth != recieved.curBitDepth) { Logging.Add("curBitDepth changed to " + recieved.curBitDepth.ToString()); Logic.Status.curBitDepth = recieved.curBitDepth; } else { } if (Logic.Status.CurImageImageFormat != recieved.CurImageImageFormat) { Logging.Add("CurImageImageFormat changed to " + recieved.CurImageImageFormat.ToString()); Logic.Status.CurImageImageFormat = recieved.CurImageImageFormat; } bool shiftChanged = false; bool correctionUpdated = false; for (int i = 0; i < recieved.Xshift.Length; i++) { if (recieved.Xshift[i] != Logic.Status.Xshift[i] || recieved.Yshift[i] != Logic.Status.Yshift[i]) { shiftChanged = true; } if (recieved.ExpCorrection[i] != Logic.Status.ExpCorrection[i] || recieved.DigitCorrection[i] != Logic.Status.DigitCorrection[i]) { correctionUpdated = true; } } if (shiftChanged) { Array.Copy(recieved.Xshift, Logic.Status.Xshift, Logic.Status.Xshift.Length); Array.Copy(recieved.Yshift, Logic.Status.Yshift, Logic.Status.Yshift.Length); Logging.Add("image Shift changed"); Logic.ChangeShift(); } if (correctionUpdated) { Array.Copy(recieved.ExpCorrection, Logic.Status.ExpCorrection, Logic.Status.ExpCorrection.Length); Array.Copy(recieved.DigitCorrection, Logic.Status.DigitCorrection, Logic.Status.DigitCorrection.Length); Logging.Add("Exposure correction changed"); Logic.ChangeExpCorr(); } if (recieved.Reinitialise) { Logic.Reinitialise(); } if (recieved.Shutdown) { Shutdown2(); } UI_DisplayImagging.Invoke(_cmdUpdate, recieved); Logic.QueUpdate(); //tells it to update settings before continuing taking imgaes. /*if imaging is true, sets time, if imaging is false then sets timeout to infinite, disabling it */ }