private void ExposureThread() { while (true) { bool success; try { success = this.semaphore.WaitOne(); } catch { success = false; } if (!success || !this.threadRunning) { cameraState = CameraStates.cameraIdle; break; } int startX = this.startX; int startY = this.startY; int numX = this.numX; int numY = this.numY; HashSet <string> states = new HashSet <string>(); while (this.threadRunning) { ComPort.Response response = this.comPort.State(states); LogMessage("ExposureThread", response.ToString()); if (response != ComPort.Response.OK) { success = false; break; } if (!states.Contains(ComPort.Exposure)) { break; } cameraState = CameraStates.cameraExposing; Thread.Sleep(1); } if (!this.threadRunning) { this.cameraState = CameraStates.cameraIdle; break; } if (success && this.exposureStart > this.exposureAbort) { this.cameraState = CameraStates.cameraReading; this.imageReady = this.webcam.Capture(out this.imageArray, startX, startY, numX, numY); } this.cameraState = CameraStates.cameraIdle; } }
public void StartExposure(double Duration, bool Light) { this.CheckConnected("StartExposure"); if (Duration < this.exposureMin || this.exposureMax < Duration) { if (Duration != 0) { throw new InvalidValueException("StartExposure", Duration.ToString(), exposureMin.ToString(), exposureMax.ToString()); } Duration = exposureMin; } if (this.startX < 0 || this.cameraXSize <= this.startX) { throw new InvalidValueException("StartExposure", this.startX.ToString(), "0", (this.cameraXSize - 1).ToString()); } if (this.startY < 0 || this.cameraYSize <= this.startY) { throw new InvalidValueException("StartExposure", this.startY.ToString(), "0", (this.cameraYSize - 1).ToString()); } if (this.numX < 1 || this.cameraXSize - this.startX < this.numX) { throw new InvalidValueException("StartExposure", this.numX.ToString(), "1", (this.cameraXSize - this.startX).ToString()); } if (this.numY < 1 || this.cameraYSize - this.startY < this.numY) { throw new InvalidValueException("StartExposure", this.numY.ToString(), "1", (this.cameraYSize - this.startY).ToString()); } ComPort.Response response = this.comPort.Start((int)(Duration * 1000 + 0.5)); LogMessage("StartExposure", response.ToString()); if (response.Reply != "OK") { throw new InvalidOperationException("StartExposure"); } this.exposureDuration = Duration; this.exposureStart = DateTime.Now; this.imageReady = false; this.imageArray = null; this.cameraState = CameraStates.cameraWaiting; try { this.semaphore.Release(); } catch { } }
public void StopExposure() { this.CheckConnected("StopExposure"); if (this.cameraState != CameraStates.cameraIdle) { ComPort.Response response = this.comPort.Stop(); LogMessage("StopExposure", response.ToString()); if (response.Reply != "OK") { throw new InvalidOperationException("StopExposure"); } } }