public MainForm() { InitializeComponent(); DebugDevice = new BoardDevice(); network = new NetworkController(DebugDevice); network.Error += delegate(object s) { ConnectionNotify ErrorFunc = ConnectionError; BeginInvoke(ErrorFunc); }; network.ConnectionSuccess += delegate(object s) { ConnectionNotify SuccessFunc = ConnectionSucceeded; BeginInvoke(SuccessFunc); }; log = new LogWindow(); log.Show(); log.Hide(); PopulateCableDropdown(); }
/// <summary> /// /// </summary> /// <param name="ConnectionDelegate">连接通知委托</param> /// <param name="interval"></param> public Ras(ConnectionNotify ConnectionDelegate, double interval) { this.ConnectNotify = ConnectionDelegate; this.NotifyTimer = new Timer(interval); this.NotifyTimer.Elapsed += new ElapsedEventHandler(this.TimerEvent); this.Rasconn = new RASCONN[1]; this.Rasconn[0].dwSize = Marshal.SizeOf(this.Rasconn[0]); this.NotifyTimer.Start(); this.bConnected = false; }
public async Task Setup() { await ExecuteOnMainThread(() => _checkConnectiontimer.Stop()); IsReady = false; await Task.Delay(2000); ConnectionNotify?.Invoke(this, "Tentando se Conectar"); await Task.Delay(2000); if (_bluetoothSerial != null) { Arduino?.Dispose(); Arduino = new RemoteDevice(_bluetoothSerial); await Task.Delay(1000); await ExecuteOnMainThread(() => _bluetoothSerial.begin(57600, SerialConfig.SERIAL_8N1)); } else { Arduino?.Dispose(); Arduino = new RemoteDevice(_usbSerial); await Task.Delay(1000); await ExecuteOnMainThread(() => _usbSerial.begin(57600, SerialConfig.SERIAL_8N1)); } SerialOut = new SerialOutController(Arduino, 12, 8, 7); Arduino.DeviceConnectionLost += message => { ConnectionNotify?.Invoke(this, "Conexão Arduino Perdida: " + message); }; Arduino.DeviceConnectionFailed += async message => { ConnectionNotify?.Invoke(this, "Conexão Arduino Falhou: " + message); await Task.Delay(5000); }; Arduino.DeviceReady += async() => await ArduinoOnDeviceReady(); Servos = new Dictionary <ETinBotServo, ServoController>() { [ETinBotServo.ServoHand] = new ServoController(Arduino, 09), [ETinBotServo.ServoHeadX] = new ServoController(Arduino, 05), [ETinBotServo.ServoHeadY] = new ServoController(Arduino, 06), [ETinBotServo.ServoLeftArm] = new ServoController(Arduino, 03, true), [ETinBotServo.ServoRightArm] = new ServoController(Arduino, 11), [ETinBotServo.ServoTorso] = new ServoController(Arduino, 10) }; await ExecuteOnMainThread(() => _checkConnectiontimer.Start()); }
private async Task ArduinoOnDeviceReady() { ConnectionNotify?.Invoke(this, "Arduino Ready"); await SerialOut.Reset(false); await Task.Delay(300); await AttachServos(); Arduino.SafePinMode(_phoneChargePin, PinMode.OUTPUT); IsReady = true; }
public Body(UsbSerial usbSerial) { _usbSerial = usbSerial; _usbSerial.ConnectionEstablished += () => ConnectionNotify?.Invoke(this, "USB estabelecido"); _usbSerial.ConnectionFailed += message => { ConnectionNotify?.Invoke(this, "USB falhou: " + message); Setup(); }; _usbSerial.ConnectionLost += message => { ConnectionNotify?.Invoke(this, "USB perdido: " + message); }; _checkConnectiontimer.Interval = TimeSpan.FromSeconds(90); _checkConnectiontimer.Tick += CheckConnectiontimerOnTick; }
public Body(BluetoothSerial bluetoothSerial) { _bluetoothSerial = bluetoothSerial; _bluetoothSerial.ConnectionEstablished += () => ConnectionNotify?.Invoke(this, "Bluetooth estabelecido"); _bluetoothSerial.ConnectionFailed += async message => { ConnectionNotify?.Invoke(this, "Bluetooth falhou: " + message); await Task.Delay(5000); Setup(); }; _bluetoothSerial.ConnectionLost += message => { ConnectionNotify?.Invoke(this, "Bluetooth perdido: " + message); Setup(); }; _checkConnectiontimer.Interval = TimeSpan.FromSeconds(30); _checkConnectiontimer.Tick += CheckConnectiontimerOnTick; }