public static void SpeedUp() { if (mSpeed.Value < kSpeedCount) { mSpeed.Update(mSpeed.Value + 1); } AcceptCheckout.Start(); }
public void Start() { lock (lck) { if (State == ComRRConnectionStates.None) { try { var packet = new byte[requestLength]; packet[0] = requestHeader; var data = new byte[packet.Length - 2]; EncodeRequestInData(data); data.CopyTo(packet, 1); packet[packet.Length - 1] = (byte)((byte)data.Sum(a => a) + packet[0]); //update threshold and timeout portSettings.Threshold = responseLength; Request.PacketBytes = packet; port.Write(packet, true); State = ComRRConnectionStates.Sent; timeoutTask.Start(); } catch (Exception ex) { error(ex.ToString(), ComRRConnectionErrors.Exception); } } else { var msg = $"{nameof(State)} is {State} but required state is: {ComRRConnectionStates.None}"; error(msg, ComRRConnectionErrors.InvalidState); } } }
/// <summary> /// Останавливаем насос и частотники /// </summary> /// <param name="timeout">Задержка перед отключением насоса</param> public static void Stop(ushort timeout = 0) { SoundAlarm.Off(); if (OnStop != null) { OnStop(mState); } mTaskPumpStop.SetTimeout(timeout); mTaskPumpStop.Start(); }
/// <summary> /// Остановливаем частотники /// </summary> private static void Stop() { // выставляем скорость в 2 Гц перед тем, как полностью остановить - для преотвращения выбега mUz2.Frequency(200); mUz3.Frequency(200); mUz4.Frequency(200); mUz5.Frequency(200); // защита от выбега if (Invertors.Count(s => s.Status == EngineStatus.Failure) > 0) { mUz2.Off(true); mLastDirection = null; // выставляем неопределенное состояние, обозначающее, что у нас была остановка } else { if (Mode == EngineMode.Motion) { if (Invertors.Count(s => s.GetFrequency() <= 200) == Invertors.Count) { mUz2.Off(true); mLastDirection = null; // выставляем неопределенное состояние, обозначающее, что у нас была остановка } } /* * else if(Mode == EngineMode.Conveyor) * { * //Console.WriteLine("conveyor try stop"); * if (mConveyor.GetFrequency() <= 200) * { * mConveyor.Off(false); * //Console.WriteLine("conveyor STOP"); * // TODO: это не должно быть тут, но поставил для напоминания - не помню, как по коду сделана проверка направления вращения * mLastDirection = null; // выставляем неопределенное состояние, обозначающее, что у нас была остановка * } * } */ else { mUz2.Off(true); } } // если мы в режиме хода - то начинем процедуру сброса скорости на минимальную if (Mode != EngineMode.Motion) { return; } if (!ResetMotionSpeedToMin.IsStart) { ResetMotionSpeedToMin.Start(); } }
protected ComPort(ComPortSettings settings, Action <ComPortErrorNames, Exception> errorCallback) { try { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (settings.Validate() == false) { throw new ArgumentException(Tran.Instance.Get("InvalidSettings"), nameof(settings)); } Error = errorCallback ?? throw new ArgumentNullException(nameof(errorCallback)); port = new SerialPort { PortName = settings.PortName, BaudRate = settings.BaudRate, DataBits = settings.DataBits, Parity = settings.Parity, StopBits = settings.StopBits, Handshake = settings.Handshake, ReadBufferSize = settings.ReadBufferSize, WriteBufferSize = settings.WriteBufferSize }; } catch (Exception ex) { raiseError(ComPortErrorNames.OnConstruction, ex); } try { mainTask = new DelayedTask(main, 1); mainTask.Start(); } catch (Exception ex) { raiseError(ComPortErrorNames.OnStartingReadOperation, ex); } }
private void sendNext() { //make sure there's some command active if (!isAnyCommandActive && cmdQ.Any()) { if (cmdQ.TryDequeue(out var cmd)) { setActiveCmd(cmd); //cannot stop disallowStop(); //now that there's one active command, let it do activeCmd.ControlAsync(port, sendIsFinished); } } sendTask.Start(); }
private void main() { try { bool beOpen; lock (mustBeOpenLock) { beOpen = mustBeOpen; } if (beOpen) { if (IsOpen) { if (NewByteCallback != null) { read_NewByteCallback(); } else if (Buffer != null) { read_Buffer(); } } else { open(); } } else { close(); } } finally { mainTask.Start(); } }
public static void Stop(ushort timeout = 0) { mTaskEngineStop.SetTimeout(timeout); mTaskEngineStop.Start(); }
public static void On() { mTask.Start(); mRelay.On(); }
private void FeedbackOnChange(IReadonlySignal signal) { //Checkout(this); mTask.Start(); }
private void startSending() { sendTask = new DelayedTask(sendNext, 1000); sendTask.Start(); }
public virtual bool HandleEvent(Application.EventType aType, object aData) { var point = ScreenPosition; switch (aType) { case Application.EventType.MouseDown: { if (IsVisible && IsActive) { if (State != ButtonState.Pressed) { var mouseData = (MouseData)aData; //Console.WriteLine("{0},{1}", mouseData.X, mouseData.Y); if ((mouseData.X >= point.X && mouseData.X <= point.X + Width) && (mouseData.Y >= point.Y && mouseData.Y <= point.Y + Height)) { // меняем внутреннее состояние State = ButtonState.Pressed; mCheckHoldKey.Start(); // оповещаем всех о смене состояния if (OnPress != null) { OnPress(this); return(true); } } } } } break; case Application.EventType.MouseUp: { if (IsVisible && IsActive) { if (State == ButtonState.Pressed) { State = ButtonState.Released; mCheckHoldKey.Stop(); var isHandled = false; // оповещаем всех о смене состояния if (DateTime.Now.Subtract(mPreviousReleaseEvent).TotalMilliseconds < kDoubleClickTimeout) { if (OnDoubleClick != null) { OnDoubleClick(this); isHandled = true; } } // оповещаем всех о смене состояния if (OnRelease != null) { OnRelease(this); isHandled = true; } mPreviousReleaseEvent = DateTime.Now; return(isHandled); } } } break; case Application.EventType.KeyboardPress: { if (IsVisible && IsActive) { if (HotKeycode == ((KeyboardData)aData).Keycode) { if (State != ButtonState.Pressed) { // меняем внутреннее состояние State = ButtonState.Pressed; mCheckHoldKey.Start(); // оповещаем всех о смене состояния if (OnPress != null) { OnPress(this); return(true); } } } } } break; case Application.EventType.KeyboardRelease: { if (IsVisible && IsActive) { if (HotKeycode == ((KeyboardData)aData).Keycode) { if (State == ButtonState.Pressed) { State = ButtonState.Released; mCheckHoldKey.Stop(); var isHandled = false; // оповещаем всех о смене состояния if (DateTime.Now.Subtract(mPreviousReleaseEvent).TotalMilliseconds < kDoubleClickTimeout) { if (OnDoubleClick != null) { OnDoubleClick(this); isHandled = true; } } // оповещаем всех о смене состояния if (OnRelease != null) { OnRelease(this); isHandled = true; } mPreviousReleaseEvent = DateTime.Now; return(isHandled); } } } } break; case Application.EventType.KeyHold: { if (IsVisible && IsActive) { if (ReferenceEquals(this, aData)) { mCheckHoldKey.Stop(); // оповещаем всех о смене состояния if (OnHold != null) { OnHold(this); return(true); } return(false); } } } break; } return(false); }
private void Processing() { while (true) { try { Console.WriteLine("udp camera processing start trying at: {0}", mUrl); if (!mConnectionChecker.IsStart) { mConnectionChecker.Start(); } mListener = new UdpClient(mUrl, kListenPort); Thread.Sleep(100); mListener.Send(StopCmd, StopCmd.Length); Thread.Sleep(1000); LightCmd[31] = 0; mListener.Send(LightCmd, LightCmd.Length); Thread.Sleep(1000); mListener.Send(StartCmd, StartCmd.Length); Thread.Sleep(1000); LightCmd[31] = mDuty; mListener.Send(LightCmd, LightCmd.Length); mListener.Client.ReceiveTimeout = 3000; Thread.Sleep(100); var packetData = new byte[4500][]; var image = new byte[1600 * 1200 * 3]; var packetsInFrame = 0; var currentFrame = 0; while (mListener.Client.Connected) { if (!mConnectionChecker.IsStart) { mConnectionChecker.Start(); } { IPEndPoint remoteEp = null; var bytes = mListener.Receive(ref remoteEp); if (bytes.Length != 0) { var frame = bytes[0] << 8 | bytes[1]; if (currentFrame == 0) { currentFrame = frame; } if (currentFrame != frame) { // clear data for (var i = 0; i < ((packetsInFrame < packetData.Length) ? packetsInFrame : packetData.Length); i++) { packetData[i] = null; } packetsInFrame = 0; currentFrame = 0; //Console.WriteLine("c"); } else { var id = bytes[2] << 8 | bytes[3]; packetData[id] = bytes; packetsInFrame++; //Console.Write("{0}:{1} ", frame, id); //Console.Write("."); } } else { // собираем пакет if (packetsInFrame < packetData.Length) { //Console.Write(packetsInFrame + " "); var isvalid = true; var dstIndex = 0; for (var i = 0; i < packetsInFrame; i++) { if (packetData[i] != null) { //var id = packetData[i][2] << 8 | packetData[i][3]; //var frameid = packetData[i][0] << 8 | packetData[i][1]; //Console.Write("{0}:{1}:{2} ", frameid, id, packetData[i].Length); Array.Copy(packetData[i], 4, image, dstIndex, (packetData[i].Length - 4)); dstIndex += (packetData[i].Length - 4); } else { // error //Console.Write("b"); isvalid = false; break; } } //Console.WriteLine("s\n"); if (isvalid) { var rv = new byte[dstIndex + 1]; Array.Copy(image, rv, (dstIndex + 1)); if (OnFrame != null) { OnFrame(rv); } //File.WriteAllBytes("F:/dump/image" + currentFrame + ".jpg", rv); //Console.Write("g"); mConnectionChecker.Stop(); } } // clear data for (var i = 0; i < ((packetsInFrame < packetData.Length) ? packetsInFrame : packetData.Length); i++) { packetData[i] = null; } packetsInFrame = 0; currentFrame = 0; } } } //Console.WriteLine("ooops, disconected"); } catch (ThreadAbortException) { //Console.WriteLine("udp camera processing aborted"); return; } catch (SocketException) { //Console.WriteLine("Socket at {0}", mUrl); } catch (TimeoutException) { //Console.WriteLine("Timeout"); } catch (Exception ex) { Console.WriteLine(ex); } Thread.Sleep(1000); } }