private void InitFirmata()
    {
      //USB\VID_2A03&PID_0043&REV_0001
      //create a serial connection
      //var devices = await UsbSerial.listAvailableDevicesAsync();
      //var devList = devices.ToList();

      serial = new UsbSerial("VID_2A03", "PID_0043");

      //construct the firmata client
      firmata = new UwpFirmata();
      firmata.FirmataConnectionReady += Firmata_FirmataConnectionReady;
      firmata.StringMessageReceived += Firmata_StringMessageReceived;

      //last, construct the RemoteWiring layer by passing in our Firmata layer.
      arduino = new RemoteDevice(firmata);
      arduino.DeviceReady += Arduino_DeviceReady;

      //if you create the firmata client yourself, don't forget to begin it!
      firmata.begin(serial);

      //you must always call 'begin' on your IStream object to connect.
      //these parameters do not matter for bluetooth, as they depend on the device. However, these are the best params to use for USB, so they are illustrated here
      serial.begin(57600, SerialConfig.SERIAL_8N1);

    }
Example #2
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);
            }
        }
Example #3
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);
        }
Example #4
0
        public static async void Init()
        {
            var deviceList = await UsbSerial.listAvailableDevicesAsync();
            var device = deviceList.First();
            connection = new UsbSerial(device);
            firmata = new UwpFirmata();
            firmata.begin(connection);
            App.Arduino = new RemoteDevice(firmata);

            connection.ConnectionEstablished += OnConnectionEstablished;
            connection.ConnectionFailed += OnConnectionFailed;
            connection.begin(115200, SerialConfig.SERIAL_8N1);

            //start a timer for connection timeout
            timeout = new DispatcherTimer();
            timeout.Interval = new TimeSpan(0, 0, 30);
            timeout.Tick += Connection_TimeOut;
            timeout.Start();
        }
Example #5
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            usb = new UsbSerial("VID_2341", "PID_0042");//Arduino MEGA

            //construct the firmata client
            firmata = new UwpFirmata();
            arduino = new RemoteDevice(firmata);
            firmata.begin(usb);

            //we do not care about inputs in this example
            //firmata.startListening();

            usb.begin(115200, SerialConfig.SERIAL_8N1);
            arduino.DeviceReady            += Stepper_Usb_ConnectionEstablished; //usb.ConnectionEstablished
            arduino.DeviceReady            += Drive_Usb_ConnectionEstablished;   //usb.ConnectionEstablished
            arduino.DeviceConnectionFailed += Arduino_DeviceConnectionFailed;

            deferral = taskInstance.GetDeferral();
            //pwmController = (await PwmController.GetControllersAsync(PwmPCA9685.PwmProviderPCA9685.GetPwmProvider()))[0];
            //pwmController.SetDesiredFrequency(300); // Check if this is the correct frequency for Talon
            //motorPin = pwmController.OpenPin(13);
            //drive.RampUp(motorPin, .34);
            drive = new FirmataDriveController(firmata);
            step  = new StepperController(firmata);

            var carImpl = new CarImplementation(step, drive);

            carRC.implementation = carImpl;


            await Task.Run(async() =>
            {
                while (!stepperUsbSetup && !driveUsbSetup)
                {
                    //wait
                    await Task.Delay(1);
                }

                carRC.Start();
            });
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            // Create Firmata
            this.mkr1000_firmata = new UwpFirmata();

            //Create MKR1000 Device
            mkr1000 = new Microsoft.Maker.RemoteWiring.RemoteDevice(mkr1000_firmata);

            //Establish a network serial connection. change it to the right IP address and port
            wificonnection = new Microsoft.Maker.Serial.NetworkSerial(new Windows.Networking.HostName("192.168.1.42"), 3030);

            //Attach event handlers
            wificonnection.ConnectionEstablished += NetWorkSerial_ConnectionEstablished;
            wificonnection.ConnectionFailed += NetWorkSerial_ConnectionFailed;

            //Begin Firmata
            mkr1000_firmata.begin(wificonnection);

            //Begin connection
            wificonnection.begin(115200, Microsoft.Maker.Serial.SerialConfig.SERIAL_8N1);
        }
Example #7
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            // Create Firmata
            this.mkr1000_firmata = new UwpFirmata();

            //Create MKR1000 Device
            mkr1000 = new Microsoft.Maker.RemoteWiring.RemoteDevice(mkr1000_firmata);

            //Establish a network serial connection. change it to the right IP address and port
            wificonnection = new Microsoft.Maker.Serial.NetworkSerial(new Windows.Networking.HostName("192.168.1.42"), 3030);

            //Attach event handlers
            wificonnection.ConnectionEstablished += NetWorkSerial_ConnectionEstablished;
            wificonnection.ConnectionFailed      += NetWorkSerial_ConnectionFailed;

            //Begin Firmata
            mkr1000_firmata.begin(wificonnection);

            //Begin connection
            wificonnection.begin(115200, Microsoft.Maker.Serial.SerialConfig.SERIAL_8N1);
        }
Example #8
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();
        }
Example #9
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);
        }
Example #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);
        }
Example #11
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();

            
        }
Example #12
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);

        }