public MainPage()
        {
            this.InitializeComponent();

            if( useBluetooth )
            {
                /*
                 * I've written my bluetooth device name as a parameter to the BluetoothSerial constructor. You should change this to your previously-paired
                 * device name if using Bluetooth. You can also use the BluetoothSerial.listAvailableDevicesAsync() function to list
                 * available devices, but that is not covered in this sample.
                 */
                bluetooth = new BluetoothSerial( "RNBT-E072" );

                arduino = new RemoteDevice( bluetooth );
                bluetooth.ConnectionEstablished += OnConnectionEstablished;

                //these parameters don't matter for bluetooth
                bluetooth.begin( 0, 0 );
            }
            else
            {
                /*
                 * I've written my Arduino device VID and PID as a parameter to the BluetoothSerial constructor. You should change this to your
                 * device VID and PID if using USB. You can also use the UsbSerial.listAvailableDevicesAsync() function to list
                 * available devices, but that is not covered in this sample.
                 */
                usb = new UsbSerial( "VID_2341", "PID_0043" );   //I've written in my device D directly

                arduino = new RemoteDevice( usb );
                usb.ConnectionEstablished += OnConnectionEstablished;

                //SerialConfig.8N1 is the default config for Arduino devices over USB
                usb.begin( 115200, SerialConfig.SERIAL_8N1 );
            }
        }
Beispiel #2
0
        //protected override void OnNavigatedTo(NavigationEventArgs e) {
        //    base.OnNavigatedTo(e);

        //    FindConnection();
        //}

        private void FindConnection()
        {
            cancelTokenSource = new CancellationTokenSource();
            cancelTokenSource.Token.Register(() => OnConnectionCancelled());

            Task <DeviceInformationCollection> task = UsbSerial.listAvailableDevicesAsync().AsTask <DeviceInformationCollection>(cancelTokenSource.Token);

            if (task != null)
            {
                //store the returned DeviceInformation items when the task completes
                task.ContinueWith(listTask => {
                    //store the result and populate the device list on the UI thread

                    var result = listTask.Result;
                    if (result != null && result.Count > 0)
                    {
                        DeviceInformation device = result[0];


                        App.Connection = new UsbSerial(device);

                        MakeConnection();
                    }
                });
            }
        }
Beispiel #3
0
        private async void grid1_Loaded(object sender, RoutedEventArgs e)
        {
            var devices = await UsbSerial.listAvailableDevicesAsync();

            int idx = -1;

            for (int i = 0; i < devices.Count; i++)
            {
                if (devices[i].Name.StartsWith("Arduino"))
                {
                    idx = i;
                }
            }

            if (idx != -1)
            {
                usbSerial = new UsbSerial(devices[idx]);
                firmata   = new UwpFirmata();
                arduino   = new RemoteDevice(firmata);
                firmata.begin(usbSerial);
                //arduino.DeviceReady += OnDeviceReady;
                //usbSerial.ConnectionEstablished += OnDeviceReady;
                firmata.FirmataConnectionReady += OnDeviceReady;
                //arduino.SysexMessageReceived += DataRecieved;
                firmata.SysexMessageReceived          += Firmata_SysexMessageReceived;
                firmata.PinCapabilityResponseReceived += Firmata_PinCapabilityResponseReceived;
                firmata.DigitalPortValueUpdated       += Firmata_DigitalPortValueUpdated;
                usbSerial.begin(57600, SerialConfig.SERIAL_8N1);
            }
        }
Beispiel #4
0
 private void InitWRA()
 {
     connection = new UsbSerial("VID_2341", "PID_0043");
     arduino    = new RemoteDevice(connection);
     connection.ConnectionEstablished += Connection_ConnectionEstablished;
     connection.begin(57600, SerialConfig.SERIAL_8N1);
 }
        public async Task RenewDeviceList(string interfaceType)
        {
            connections.Clear();

            Task <DeviceInformationCollection> task = null;

            switch (interfaceType)
            {
            case "Bluetooth":
                task = BluetoothSerial.listAvailableDevicesAsync().AsTask <DeviceInformationCollection>();
                break;

            case "USB":
                task = UsbSerial.listAvailableDevicesAsync().AsTask <DeviceInformationCollection>();
                break;

            case "DfRobot":
                task = DfRobotBleSerial.listAvailableDevicesAsync().AsTask <DeviceInformationCollection>();
                break;
            }

            if (task != null)
            {
                await task.ContinueWith(listTask =>
                {
                    var result = listTask.Result;

                    foreach (DeviceInformation device in result)
                    {
                        connections.Add(device.Name, device);
                    }
                });
            }
        }
Beispiel #6
0
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();

            this.mqttClient?.Dispose();
            this.mqttClient = null;

            this.sampleTimer?.Dispose();
            this.sampleTimer = null;

            if (this.arduino != null)
            {
                this.arduino.digitalWrite(13, PinState.LOW);
                this.arduino.pinMode(13, PinMode.INPUT);                     // Onboard LED.
                this.arduino.pinMode(9, PinMode.INPUT);                      // Relay.

                this.arduino.Dispose();
                this.arduino = null;
            }

            if (this.arduinoUsb != null)
            {
                this.arduinoUsb.end();
                this.arduinoUsb.Dispose();
                this.arduinoUsb = null;
            }

            db?.Stop()?.Wait();
            db?.Flush()?.Wait();

            Log.Terminate();

            deferral.Complete();
        }
        /// <summary>
        /// Refreshes the connections from the available device sources
        /// </summary>
        /// <returns>Collection of connection objects available to the app</returns>
        public async Task <Connections> RefreshConnections()
        {
            Connections connections = new Connections();

            connections.Clear();

            await BluetoothSerial.listAvailableDevicesAsync().AsTask().ContinueWith(
                listTask =>
            {
                listTask.Result.ForEach(
                    d => connections.Add(new Connection(d.Name, d, ConnectionType.BluetoothSerial)));
            });

            await UsbSerial.listAvailableDevicesAsync().AsTask().ContinueWith(
                listTask =>
            {
                listTask.Result.ForEach(
                    d => connections.Add(new Connection(d.Name, d, ConnectionType.UsbSerial)));
            });

            string previousConnection = App.CurrentAppSettings.PreviousConnectionName;

            if (this.CurrentConnection == null && !string.IsNullOrEmpty(previousConnection) &&
                connections.Any(c => c.DisplayName == App.CurrentAppSettings.PreviousConnectionName))
            {
                await this.Connect(
                    connections.FirstOrDefault(
                        c => c.DisplayName == App.CurrentAppSettings.PreviousConnectionName));
            }

            return(connections);
        }
Beispiel #8
0
 private void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     usbConnection        = new UsbSerial("VID_2A03", "PID_0043");
     arduino              = new RemoteDevice(usbConnection);
     arduino.DeviceReady += Arduino_DeviceReady;
     usbConnection.begin(57600, SerialConfig.SERIAL_8N1);
 }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            _Serial = new UsbSerial(await FindFirstArduinoBoard());

            _Serial.ConnectionEstablished += () =>
            {
                Debug.WriteLine("Serial connection established");
            };

            _Serial.ConnectionFailed += (m) =>
            {
                Debug.WriteLine("Serial connection failed because " + m);
            };

            _Arduino              = new RemoteDevice(_Serial);
            _Arduino.DeviceReady += () => {
                Debug.WriteLine("Device is ready");
                _Arduino.pinMode(12, PinMode.OUTPUT);
                _Arduino.pinMode(3, PinMode.PULLUP);
            };

            _Arduino.DigitalPinUpdated += (p, s) =>
            {
                if (p == 3)
                {
                    _Arduino.digitalWrite(12, s == PinState.HIGH ? PinState.LOW : PinState.HIGH);
                }
                ;
            };

            _Serial.begin(57600);
        }
Beispiel #10
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("hola");
            playing = false;
            DeviceInformation device = null;

            var result = UsbSerial.listAvailableDevicesAsync().AsTask <DeviceInformationCollection>().Result;

            if (result == null || result.Count == 0)
            {
                throw new InvalidOperationException("No USB FOUND");
            }
            else
            {
                // Assume first
                device = result.FirstOrDefault();
            }

            Connection = new UsbSerial(device);

            Firmata = new UwpFirmata();
            Firmata.begin(Connection);
            Arduino = new RemoteDevice(Firmata);
            Connection.ConnectionEstablished += OnConnectionEstablished;

            Connection.begin(BAUD_RATE, SerialConfig.SERIAL_8N1);
        }
Beispiel #11
0
        private async void rad_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton rad = (RadioButton)sender;

            lstDevices.ItemsSource = null;
            if (rad == radBluetooth)
            {
                var bleutoothDevices = await BluetoothSerial.listAvailableDevicesAsync();

                lstDevices.ItemsSource = bleutoothDevices;
            }
            else if (rad == radUSB)
            {
                var usbDevices = await UsbSerial.listAvailableDevicesAsync();

                List <DeviceInformation> _usbDevices = new List <DeviceInformation>();
                foreach (var itm in usbDevices)
                {
                    if (itm.Name.Contains("COM"))
                    {
                        _usbDevices.Add(itm);
                    }
                }
                lstDevices.ItemsSource = _usbDevices;
            }
        }
        public async void Start()
        {

            var aqs = Windows.Devices.SerialCommunication.SerialDevice.GetDeviceSelector();
            var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(aqs);



            try {
                var device = devices.Where(x => x.Id.Contains("VID_1A86&PID_7523") || x.Id.Contains("VID_2341&PID_0043")).FirstOrDefault();
                Debug.WriteLine("Arduino found: " + device.Name);
                Debug.WriteLine("Arduino found: " + device.Id);

                usb = new UsbSerial(device);
                //arduino = new RemoteDevice(usb);

                usb.ConnectionEstablished += Usb_ConnectionEstablished;
                usb.ConnectionFailed += Usb_ConnectionFailed;
                usb.ConnectionLost += Usb_ConnectionLost;

                Debug.WriteLine("Begin USB connection");
                usb.begin(9600, SerialConfig.SERIAL_8N1);
            }
            catch (Exception ex) {
              

            }





        }
Beispiel #13
0
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();

            if (this.arduino != null)
            {
                this.arduino.digitalWrite(13, PinState.LOW);
                this.arduino.pinMode(13, PinMode.INPUT);                     // Onboard LED.
                this.arduino.pinMode(9, PinMode.INPUT);                      // Relay.

                this.arduino.Dispose();
                this.arduino = null;
            }

            if (this.arduinoUsb != null)
            {
                this.arduinoUsb.end();
                this.arduinoUsb.Dispose();
                this.arduinoUsb = null;
            }

            Log.Terminate();

            deferral.Complete();
        }
        public MainPage()
        {
            this.InitializeComponent();

            if (useBluetooth)
            {
                /*
                 * I've written my bluetooth device name as a parameter to the BluetoothSerial constructor. You should change this to your previously-paired
                 * device name if using Bluetooth. You can also use the BluetoothSerial.listAvailableDevicesAsync() function to list
                 * available devices, but that is not covered in this sample.
                 */
                bluetooth = new BluetoothSerial("RNBT-E072");

                arduino = new RemoteDevice(bluetooth);
                bluetooth.ConnectionEstablished += OnConnectionEstablished;

                //these parameters don't matter for bluetooth
                bluetooth.begin(0, 0);
            }
            else
            {
                /*
                 * I've written my Arduino device VID and PID as a parameter to the BluetoothSerial constructor. You should change this to your
                 * device VID and PID if using USB. You can also use the UsbSerial.listAvailableDevicesAsync() function to list
                 * available devices, but that is not covered in this sample.
                 */
                usb = new UsbSerial("VID_2341", "PID_0043");     //I've written in my device D directly

                arduino = new RemoteDevice(usb);
                usb.ConnectionEstablished += OnConnectionEstablished;

                //SerialConfig.8N1 is the default config for Arduino devices over USB
                usb.begin(115200, SerialConfig.SERIAL_8N1);
            }
        }
Beispiel #15
0
        static void UsbSerialDevice_DataReceived(UsbSerial sender, UsbSerial.DataReceivedEventArgs e)
        {
            Debug.Print("USB data received" + e.Data.ToHex());

            //for (int i = 0; i < e.Data.Length; i++)
            //    Debug.Print(e.Data[i].ToString());

            //sender.Write(e.Data);
        }
        public Aktivacija()
        {
            var usb = new UsbSerial("VID_1A86", "PID_7523");

            this.InitializeComponent();
            _arduino              = new RemoteDevice(usb);
            _arduino.DeviceReady += Setup;
            usb.begin(57600, SerialConfig.SERIAL_8N2);
        }
Beispiel #17
0
 public void InitializeConnection(string vid, string pid)
 {
     //currently hardcoded VID_0403 PID_6001
     //usb = new UsbSerial("VID_2341", "PID_0010"); //Arduino available in Lantern
     usb = new UsbSerial("VID_0403", "PID_6001"); //Arduino available in LCD Printer
     usb.ConnectionEstablished += OnConnectionEstablished;
     //usb.begin(250000, SerialConfig.SERIAL_8N1);
     usb.begin(115200, SerialConfig.SERIAL_8N1);
 }
Beispiel #18
0
 public MainPage()
 {
     this.InitializeComponent();
     UsbSerial connection =new UsbSerial("VID_2341", "PID_0043");
     arduino = new RemoteDevice(connection);
     //just start typing this and you can autocomplete using tab
     connection.ConnectionEstablished += Connection_ConnectionEstablished;
     arduino.DeviceReady += TurnOnLight;
     connection.begin(57600, SerialConfig.SERIAL_8N1);
 }
Beispiel #19
0
        public static ArduinoController UsbConnection(DeviceInformation device, uint baudRate = 115200, SerialConfig serialConfig = SerialConfig.SERIAL_8N1)
        {
            UsbSerial Connection1 = new UsbSerial(device);

            Connection1.begin(baudRate, serialConfig);
            var res = new ArduinoController(Connection1);

            res.usbConnection = Connection1;
            res._connType     = ConnectionType.Usb;
            return(res);
        }
Beispiel #20
0
        public static void Usb_Reconnect()
        {
#if HARDWARE
            App.usb     = new UsbSerial("2341", "8036");
            App.arduino = new RemoteDevice(App.usb);
            App.usb.begin(115200, SerialConfig.SERIAL_8N1);
            App.usb.ConnectionEstablished += Usb_ConnectionEstablished;;
            App.usb.ConnectionLost        += Usb_ConnectionLost;
            App.usb.ConnectionFailed      += Usb_ConnectionFailed;
#endif
        }
Beispiel #21
0
        // This is there the Arduino connection is set up via
        // Windows Remote Wiring. The Library is via NuGet
        private void InitializeWiring()
        {
            _serial  = new UsbSerial(_vid, _pid);
            _arduino = new RemoteDevice(_serial);

            _serial.ConnectionEstablished += OnSerialConnectionEstablished;

            _serial.begin(57600, SerialConfig.SERIAL_8N1);

            System.Diagnostics.Debug.WriteLine("Wiring initialized");
        }
Beispiel #22
0
 public static void Usb_Reconnect()
 {
     #if HARDWARE
     App.usb = new UsbSerial("2341", "8036");
     App.arduino = new RemoteDevice(App.usb);
     App.usb.begin(115200, SerialConfig.SERIAL_8N1);
     App.usb.ConnectionEstablished += Usb_ConnectionEstablished; ;
     App.usb.ConnectionLost += Usb_ConnectionLost;
     App.usb.ConnectionFailed += Usb_ConnectionFailed;
     #endif
 }
Beispiel #23
0
        public MainPage()
        {
            this.InitializeComponent();
            UsbSerial connection = new UsbSerial("VID_2341", "PID_0043");

            arduino = new RemoteDevice(connection);
            //just start typing this and you can autocomplete using tab
            connection.ConnectionEstablished += Connection_ConnectionEstablished;
            arduino.DeviceReady += TurnOnLight;
            connection.begin(57600, SerialConfig.SERIAL_8N1);
        }
        // Arduino IDer: USB\VID_1A86&PID_7523

        public MainPage()
        {
            this.InitializeComponent();

            connection                 = new UsbSerial("VID_1A86", "PID_7523");
            arduino                    = new RemoteDevice(connection);
            arduino.DeviceReady       += MyDeviceReadyCallback;
            arduino.DigitalPinUpdated += ButtonUpdateCallBack;
            //connection.ConnectionEstablished += OnConnectionEstablished;
            connection.begin(57600, SerialConfig.SERIAL_8N1);
        }
Beispiel #25
0
        public Alarm()
        {
            Podaci            = new List <string>();
            Uposlenik         = null;
            ProfilZatvorenika = null;
            var usb = new UsbSerial("VID_1A86", "PID_7523");

            _arduino              = new RemoteDevice(usb);
            _arduino.DeviceReady += Setup;
            usb.begin(57600, SerialConfig.SERIAL_8N2);
        }
        public MainPage()
        {
            this.InitializeComponent();

            usb = new UsbSerial("VID_2341", "PID_003D");   //I've written in my device D directly

            arduino = new RemoteDevice(usb);
            usb.ConnectionEstablished += OnConnectionEstablished;

            //SerialConfig.8N1 is the default config for Arduino devices over USB
            usb.begin(57600, SerialConfig.SERIAL_8N1);
        }
Beispiel #27
0
        public PinControl(string VID, string PID, uint BaudRate)
        {
            connection = new UsbSerial(VID, PID);
            baudRate   = BaudRate;

            arduino = new RemoteDevice(connection);
            connection.begin(baudRate, SerialConfig.SERIAL_8N1);

            ftp            = new Chilkat.Ftp2();
            OriginalStates = new string[] { "Off", "Off", "Off", "Off" };
            setXML();
        }
        public MainPage()
        {
            this.InitializeComponent();

            usb = new UsbSerial("VID_2341", "PID_003D");   //I've written in my device D directly

            arduino = new RemoteDevice(usb);
            usb.ConnectionEstablished += OnConnectionEstablished;

            //SerialConfig.8N1 is the default config for Arduino devices over USB
            usb.begin(57600, SerialConfig.SERIAL_8N1);
        }
Beispiel #29
0
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();

            if (instance == this)
            {
                instance = null;
            }

            this.chatServer?.Dispose();
            this.chatServer = null;

            this.bobClient?.Dispose();
            this.bobClient = null;

            this.sensorServer?.Dispose();
            this.sensorServer = null;

            this.xmppClient?.Dispose();
            this.xmppClient = null;

            this.minuteTimer?.Dispose();
            this.minuteTimer = null;

#if GPIO
            this.gpioPin.Dispose();
            this.gpioPin = null;
#else
            if (this.arduino != null)
            {
                this.arduino.digitalWrite(13, PinState.LOW);
                this.arduino.pinMode(13, PinMode.INPUT);                     // Onboard LED.
                this.arduino.pinMode(9, PinMode.INPUT);                      // Relay.

                this.arduino.Dispose();
                this.arduino = null;
            }

            if (this.arduinoUsb != null)
            {
                this.arduinoUsb.end();
                this.arduinoUsb.Dispose();
                this.arduinoUsb = null;
            }
#endif
            db?.Stop()?.Wait();
            db?.Flush()?.Wait();

            Log.Terminate();

            deferral.Complete();
        }
        public MainPage()
        {
            this.InitializeComponent();


            UsbSerial usb = new UsbSerial("VID_2341", "PID_0043");


            arduino = new RemoteDevice(usb);


            usb.begin(57600, SerialConfig.SERIAL_8N1);
        }
Beispiel #31
0
        public MainPage()
        {
            this.InitializeComponent();
            usb = new UsbSerial("VID_2341", "PID_8036");
            List <ConnectTheDotsSensor> sensors_one = new List <ConnectTheDotsSensor> {
                new ConnectTheDotsSensor("2198a348-e2f9-4438-ab23-82a3930662ac", "Temperature", "F"),
            };

            List <ConnectTheDotsSensor> sensors_two = new List <ConnectTheDotsSensor> {
                new ConnectTheDotsSensor("2298a348-e2f9-4438-ab23-82a3930662ac", "light", "C"),
            };

            List <ConnectTheDotsSensor> sensors_three = new List <ConnectTheDotsSensor> {
                new ConnectTheDotsSensor("2398a348-e2f9-4438-ab23-82a3930662ac", "humidity", "Lux"),
            };


            arduino              = new RemoteDevice(usb);
            arduino.DeviceReady += onDeviceReady;
            usb.begin(57600, SerialConfig.SERIAL_8N1);

            ctdHelper1 = new ConnectTheDotsHelper(serviceBusNamespace: "*********",//choice the serviceBusNamespace at here like "exampleIoT-ns"
                                                  eventHubName: "ehdevices",
                                                  keyName: "D1",
                                                  key: "**********************",//copy the key which come from D1 connection of "ehdevices"
                                                  displayName: "Temperature",
                                                  organization: "DFRobot",
                                                  location: "Shanghai",
                                                  sensorList: sensors_one);

            ctdHelper2 = new ConnectTheDotsHelper(serviceBusNamespace: "*********",//choice the serviceBusNamespace at here like "exampleIoT-ns"
                                                  eventHubName: "ehdevices",
                                                  keyName: "D2",
                                                  key: "**********************",//copy the key which come from D2 connection of "ehdevices"
                                                  displayName: "light",
                                                  organization: "DFRobot",
                                                  location: "Shanghai",
                                                  sensorList: sensors_two);

            ctdHelper3 = new ConnectTheDotsHelper(serviceBusNamespace: "*********",//choice the serviceBusNamespace at here like "exampleIoT-ns"
                                                  eventHubName: "ehdevices",
                                                  keyName: "D3",
                                                  key: "**********************",//copy the key which come from D3 connection of "ehdevices"
                                                  displayName: "humidity",
                                                  organization: "DFRobot",
                                                  location: "Shanghai",
                                                  sensorList: sensors_three);

            Button_Click(null, null);
        }
Beispiel #32
0
        public void Dispose()
        {
            if (this.Device != null)
            {
                this.Device.Dispose();
                this.Device = null;
            }

            if (this.SerialPort != null)
            {
                this.SerialPort.Dispose();
                this.SerialPort = null;
            }
        }
        public MainPage()
        {
            this.InitializeComponent();

            usb = new UsbSerial("VID_2341", "PID_8036");

            //Arduino RemoteDevice Constractor via USB.
            arduino = new RemoteDevice(usb);
            //Add DeviceReady callback when connecting successfully
            arduino.DeviceReady += onDeviceReady;

            //Baudrate on 57600 and SerialConfig.8N1 is the default config for Arduino devices over USB
            usb.begin(57600, SerialConfig.SERIAL_8N1);
        }
 private async void connect()
 {
     dt = new DispatcherTimer() { Interval = new TimeSpan(500) };
     dt.Tick += loop;
     var dev = await UsbSerial.listAvailableDevicesAsync();
     foreach (var x in dev)
     {
         System.Diagnostics.Debug.WriteLine("Found " + x.Name);
     }
     usbcomm = new UsbSerial(dev[0]);
     arduino = new RemoteDevice(usbcomm);
     usbcomm.ConnectionEstablished += Comm_ConnectionEstablished;
     usbcomm.begin(57600, SerialConfig.SERIAL_8N1);
 }
Beispiel #35
0
        public void connect()
        {
            String VID = Settings.Instance.VID;
            String PID = Settings.Instance.PID;

            if (VID != null && PID != null)
            {
                UsbSerial usb = new UsbSerial(VID, PID);
                arduino = new RemoteDevice(usb);
                usb.begin(57600, SerialConfig.SERIAL_8N1);

                //"VID_1A86", "PID_7523"
            }
        }
        public MainPage()
        {
            this.InitializeComponent();
            usb = new UsbSerial("VID_2341", "PID_8036");
            List<ConnectTheDotsSensor> sensors_one = new List<ConnectTheDotsSensor> {
                new ConnectTheDotsSensor("2198a348-e2f9-4438-ab23-82a3930662ac", "Temperature", "F"),
            };

            List<ConnectTheDotsSensor> sensors_two = new List<ConnectTheDotsSensor> {
                new ConnectTheDotsSensor("2298a348-e2f9-4438-ab23-82a3930662ac", "light", "C"),
            };

            List<ConnectTheDotsSensor> sensors_three = new List<ConnectTheDotsSensor> {
                new ConnectTheDotsSensor("2398a348-e2f9-4438-ab23-82a3930662ac", "humidity", "Lux"),
            };


            arduino = new RemoteDevice(usb);
            arduino.DeviceReady += onDeviceReady;
            usb.begin(57600, SerialConfig.SERIAL_8N1);

            ctdHelper1 = new ConnectTheDotsHelper(serviceBusNamespace: "*********",//choice the serviceBusNamespace at here like "exampleIoT-ns"
                eventHubName: "ehdevices",
                keyName: "D1",
                key: "**********************",//copy the key which come from D1 connection of "ehdevices"
                displayName: "Temperature",
                organization: "DFRobot",
                location: "Shanghai",
                sensorList: sensors_one);

            ctdHelper2 = new ConnectTheDotsHelper(serviceBusNamespace: "*********",//choice the serviceBusNamespace at here like "exampleIoT-ns"
                eventHubName: "ehdevices",
                keyName: "D2",
                key: "**********************",//copy the key which come from D2 connection of "ehdevices"
                displayName: "light",
                organization: "DFRobot",
                location: "Shanghai",
                sensorList: sensors_two);

            ctdHelper3 = new ConnectTheDotsHelper(serviceBusNamespace: "*********",//choice the serviceBusNamespace at here like "exampleIoT-ns"
                eventHubName: "ehdevices",
                keyName: "D3",
                key: "**********************",//copy the key which come from D3 connection of "ehdevices"
                displayName: "humidity",
                organization: "DFRobot",
                location: "Shanghai",
                sensorList: sensors_three);

            Button_Click(null, null);
        }
Beispiel #37
0
        public MainPage()
        {
            this.InitializeComponent();
            var keepScreenOnRequest = new Windows.System.Display.DisplayRequest();

            keepScreenOnRequest.RequestActive();
            //ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
            DispatcherHelper.Dispatcher  = CoreWindow.GetForCurrentThread().Dispatcher;
            DispatcherHelper.SyncContext = TaskScheduler.FromCurrentSynchronizationContext();

            _usb       = new UsbSerial("VID_1A86", "PID_7523");
            _bluetooth = new BluetoothSerial("TinBot");
            _body      = new Body(_usb);
            //_body = new Body(_bluetooth);
            _commands = new Operations.Commands(media, _body, Ear,
                                                new Dictionary <Storyboard, int>()
            {
                [bravo]          = 200,
                [feliz]          = 100,
                [feliz_verde]    = 100,
                [normal]         = 0,
                [piscadela]      = 0,
                [piscando]       = 0,
                [piscando_duplo] = 0,
                [triste]         = 200
            },
                                                new Dictionary <ETinBotFaces, Storyboard>()
            {
                [ETinBotFaces.Angry]       = bravo,
                [ETinBotFaces.Happy]       = feliz,
                [ETinBotFaces.HappyGreen]  = feliz_verde,
                [ETinBotFaces.Normal]      = normal,
                [ETinBotFaces.UniBlink]    = piscadela,
                [ETinBotFaces.Blink]       = piscando,
                [ETinBotFaces.BlinkDouble] = piscando_duplo,
                [ETinBotFaces.Sad]         = triste
            },

                                                new Dictionary <ETinBotToggle, int>()
            {
                [ETinBotToggle.Green] = 1,
                [ETinBotToggle.Red]   = 2,
                [ETinBotToggle.Blue]  = 3,
                [ETinBotToggle.Laser] = 4
            }
                                                );

            _body.ConnectionNotify += (sender, s) => ExecuteOnMainThread(() => Label.Text = s);
            _body.Setup();
        }
Beispiel #38
0
        public MainPage()
        {
            this.InitializeComponent();
            var keepScreenOnRequest = new Windows.System.Display.DisplayRequest();
            keepScreenOnRequest.RequestActive();
            //ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
            DispatcherHelper.Dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
            DispatcherHelper.SyncContext = TaskScheduler.FromCurrentSynchronizationContext();

            _usb = new UsbSerial("VID_1A86", "PID_7523");
            _bluetooth = new BluetoothSerial("TinBot");
            _body = new Body(_usb);
            //_body = new Body(_bluetooth);
            _commands = new Operations.Commands(media, _body, Ear,
                new Dictionary<Storyboard, int>()
                {
                    [bravo] = 200,
                    [feliz] = 100,
                    [feliz_verde] = 100,
                    [normal] = 0,
                    [piscadela] = 0,
                    [piscando] = 0,
                    [piscando_duplo] = 0,
                    [triste] = 200
                },
                new Dictionary<ETinBotFaces, Storyboard>()
                {
                    [ETinBotFaces.Angry] = bravo,
                    [ETinBotFaces.Happy] = feliz,
                    [ETinBotFaces.HappyGreen] = feliz_verde,
                    [ETinBotFaces.Normal] = normal,
                    [ETinBotFaces.UniBlink] = piscadela,
                    [ETinBotFaces.Blink] = piscando,
                    [ETinBotFaces.BlinkDouble] = piscando_duplo,
                    [ETinBotFaces.Sad] = triste
                },

                new Dictionary<ETinBotToggle, int>()
                {
                    [ETinBotToggle.Green] = 1,
                    [ETinBotToggle.Red] = 2,
                    [ETinBotToggle.Blue] = 3,
                    [ETinBotToggle.Laser] = 4
                }
                );

            _body.ConnectionNotify += (sender, s) => ExecuteOnMainThread(() => Label.Text = s);
            _body.Setup();
        }
        UsbSerial usb; //Handle the USB connction

        #endregion Fields

        #region Constructors

        public MainPage()
        {
            this.InitializeComponent();

            //USB VID and PID of the "Arduino Expansion Shield for Raspberry Pi B+"
            usb = new UsbSerial("VID_2341", "PID_8036");

            //Arduino RemoteDevice Constractor via USB.
            arduino = new RemoteDevice(usb);
            //Add DeviceReady callback when connecting successfully
            arduino.DeviceReady += onDeviceReady;

            //Baudrate on 57600 and SerialConfig.8N1 is the default config for Arduino devices over USB
            usb.begin(57600, SerialConfig.SERIAL_8N1);
        }
        public MainPage()
        {
            this.InitializeComponent();

            //아두이노와 연결하기 위한 준비. 하드웨어 ID를 이용한다.
            connection = new UsbSerial("VID_2A03", "PID_0043");

            //아두이노 연결하기
            arduino = new RemoteDevice(connection);
            //디바이스 장치 준비. 아두이노의 setup과 같은 역할을 한다.
            arduino.DeviceReady += Arduino_DeviceReady;
            //아날로그 핀 업데이트 동작이 생길 시에 진행되는 함수 설정한다.
            arduino.AnalogPinUpdated += Arduino_AnalogPinUpdated;
            //아두이노 연결 작업이 성립되었을 때의 동작을 설정한다.
            connection.ConnectionEstablished += Connection_ConnectionEstablished;
            //커넥션을 연결한다.
            connection.begin(57600, SerialConfig.SERIAL_8N1);
        }
Beispiel #41
0
        // Configure and open Arduino connection
        private void openArduinoConnection()
        {
            Debug.WriteLine("IOConnector.openArduinoConnection");

            // Configure USB connection
            usb = new UsbSerial("VID_" + Storage.GetSetting<string>("VID"), "PID_" + Storage.GetSetting<string>("PID"));
            arduino = new RemoteDevice(usb);

            // Setup callback functions
            usb.ConnectionEstablished += Usb_ConnectionEstablished;
            usb.ConnectionFailed += Usb_ConnectionFailed;
            usb.ConnectionLost += Usb_ConnectionLost;
            arduino.DeviceReady += Arduino_DeviceReady;
            arduino.DeviceConnectionFailed += Arduino_DeviceConnectionFailed;
            arduino.DeviceConnectionLost += Arduino_DeviceConnectionLost;
            
            // Begin arduino connection
            usb.begin(57600, SerialConfig.SERIAL_8N1);

            arduinoSignalTimer.Change(10*ARDUINO_ALIVE_TIMER_PERIOD, ARDUINO_ALIVE_TIMER_PERIOD);
        }
Beispiel #42
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("hola");
            playing = false;
            DeviceInformation device = null;

            var result = UsbSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>().Result;

            if (result == null || result.Count == 0)
            {
                throw new InvalidOperationException("No USB FOUND");
            }
            else
            {
                // Assume first
                device = result.FirstOrDefault();
            }

            Connection = new UsbSerial(device);

            Firmata = new UwpFirmata();
            Firmata.begin(Connection);
            Arduino = new RemoteDevice(Firmata);
            Connection.ConnectionEstablished += OnConnectionEstablished;

            Connection.begin(BAUD_RATE, SerialConfig.SERIAL_8N1);
        }
Beispiel #43
0
        public ConnectionPage()
        {
            playing = false;
            this.InitializeComponent();
            ConnectionMethodComboBox.SelectionChanged += ConnectionComboBox_SelectionChanged;

            Task<DeviceInformationCollection> task = null;
            DeviceInformation device = null;

            task = UsbSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>();
            //task.Wait();

            var result = task.Result;



            if (result == null || result.Count == 0)
            {
                throw new InvalidOperationException("No USB FOUND");
            }
            else
            {
                // Assume first
                device = result.FirstOrDefault();
            }

            Connection = new UsbSerial(device);

            Firmata = new UwpFirmata();
            Firmata.begin(Connection);
            Arduino = new RemoteDevice(Firmata);
            Connection.ConnectionEstablished += OnConnectionEstablished;
            Connection.begin(115200, SerialConfig.SERIAL_8N1);

            //for (int i = 0; i < 500; i++)
            //    System.Diagnostics.Debug.WriteLine(i);

        }
Beispiel #44
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("hi");
            // 
            // TODO: Insert code to start one or more asynchronous methods 
            //
            
            playing = false;
            DeviceInformation device = null;

            var result = UsbSerial.listAvailableDevicesAsync().AsTask<DeviceInformationCollection>().Result;

            if (result == null || result.Count == 0)
            {
                throw new InvalidOperationException("No USB FOUND");
            }
            else
            {
                // Assume first
                // TODO: Might not be first.
                device = result.FirstOrDefault();
            }
            WriteLine("device name: " + device.Name);
            Connection = new UsbSerial(device);

            Firmata = new UwpFirmata();
            Firmata.begin(Connection);
            Arduino = new RemoteDevice(Firmata);
            Connection.ConnectionEstablished += OnConnectionEstablished;


            
            Connection.begin(BAUD_RATE, SerialConfig.SERIAL_8N1);


            // Begin Recording from mic.
            this.StartRecording();

            
        }