XBee Toolkit that supports API in W10 IoT?

Ok, so I have it setup with the XBee module in socket 2, I get a blinking assoc light, my RSSI light flashes once per minute (which is how often my XBee endpoint is configured to send data), and this is my code:


using System;

using System.IO;
using Windows.Devices.SerialCommunication;
using Windows.Devices.Enumeration;

using System.Net.Http;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

using GT = GHIElectronics.UWP.GadgeteerCore;
using GTMB = GHIElectronics.UWP.Gadgeteer.Mainboards;
using GTMO = GHIElectronics.UWP.Gadgeteer.Modules;

using NETMF.OpenSource.XBee;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace SparkPlant
{
    /// <summary>
    /// TEST THE MOISTURE LEVEL OF MY DESK PLANT ONCE A DAY AND SEND A STATUS EMAIL
    /// </summary>
    public sealed partial class MainPage : Page
    {
        private GTMB.FEZCream mainboard;
        private GTMO.Moisture moisture;
        private GTMO.Button hardwareButton;
        private GTMO.LEDStrip ledstrip;
        private GTMO.Load load;

        private DispatcherTimer timer;
        private DispatcherTimer buttonWatcher;

        private XBeeApi xbee;
        private SerialDevice serport;
        private int MaxMoisture = 75;

        #region PRIVATE
        //SPARKPOST CONFIG
        private const string SparkPostAPIKey = "e0ab7986833c861b7d002c550e0ed1f91dd1808d";
        private const string SparkPostBaseURI = "https://api.sparkpost.com/api/v1/";
        #endregion

        public MainPage()
        {
            this.InitializeComponent();

            this.Setup();
        }

        private async void Setup()
        {
            this.mainboard = await GT.Module.CreateAsync<GTMB.FEZCream>();
            this.moisture = await GT.Module.CreateAsync<GTMO.Moisture>(this.mainboard.GetProvidedSocket(5));
            this.hardwareButton = await GT.Module.CreateAsync<GTMO.Button>(this.mainboard.GetProvidedSocket(3));
            this.ledstrip = await GT.Module.CreateAsync<GTMO.LEDStrip>(this.mainboard.GetProvidedSocket(4));
            this.load = await GT.Module.CreateAsync<GTMO.Load>(this.mainboard.GetProvidedSocket(8));

            string deviceQuery = SerialDevice.GetDeviceSelector();
            var deviceInfo = await DeviceInformation.FindAllAsync(deviceQuery);

            string serialSelector = SerialDevice.GetDeviceSelector();
            var devices = await DeviceInformation.FindAllAsync(serialSelector);
            if (devices != null && devices.Count > 0)
            {
                var device = devices[0];
                serport = await SerialDevice.FromIdAsync(device.Id);
                if (serport != null)
                {
                    serport.DataBits = 8;
                    serport.StopBits = SerialStopBitCount.One;
                    serport.Parity = SerialParity.None;
                    serport.BaudRate = 9600;

                    xbee = new XBeeApi(serport);
                    xbee.Open();
                    // ... party on ...
                }
            }

            this.ProgramStarted();
        }

        private void ProgramStarted()
        {
            //this.button.Pressed += Button_Pressed;
            this.hardwareButton.TurnOnLed();

            this.hardwareButton.Released += Button_Pressed;

            this.timer = new DispatcherTimer();
            this.timer.Interval = TimeSpan.FromDays(1);
            this.timer.Tick += Timer_Tick;
            this.timer.Start();

            xbee.DataReceived += Xbee_DataReceived;

            CheckMoisture();
        }

        private void Xbee_DataReceived(XBeeApi receiver, byte[] data, NETMF.OpenSource.XBee.Api.XBeeAddress sender)
        {
            var dataStr = data.ToString();
            System.Diagnostics.Debug.WriteLine(dataStr);
        }

The problem is that at this line:


   if (serport != null)

The serport is indeed null. Sorry I’m new to this, but what would you suggest for debugging?

@ squeebee - the required serial device may not be the first in the list, set a break point @ 60 and manually step through and check the details …

I will try and replicate. What build did you use for win-iot (on PI2 I assume) and what cream sdk ?

Xbee version ?

Well, first thing is, are you running version 10586, the most recent release of Win10 IoT? This is the first and only version in which the onboard UART works. I am also using socket 2 with a gadgeteer xbee adapter.

One other difference is that I started my code in mainpage’s Loaded callback - I wouldn’t think that should matter, but maybe it does.

What is the length of ‘devices’? Perhaps your native serial port is not in [0]. My example code is hardcoded to [0], but a proper implementation might examine the properties of each device in the ‘devices’ array to select the correct (native UART) instance. Connecting any sort of USB serial interface makes this enumeration longer, and the native port is not necessarily the first one.

EDIT: Peter is right - the most likely culprit is that you are not running a UART-enabled version, or are using the wrong serial port.

@ all - where did you get the cram xbee driver from ? Any link ?

I installed from 10556.0.150925-0019.TH2_RELEASE_IOTCoreRPi_armFRE.ISO

I’m attaching the devices object in the debug view, it’s from a breakpoint on

 but if I step into the next two, serport comes back null.

@ .Peter. - not sure what you mean by ‘cram xbee driver’. The driver he is using is from here : [url]https://github.com/VerdantAutomation/GBee[/url] It is an adaptation of @ ransomhall’s earlier XBee Gadgeteer driver work.

Is that what you meant?

@ Squeebee - As they say on Mythbusters, “Well, there’s your problem”. You need 10586. 10556 does not support the native UART port that socket 2 requires.

10586.0.151029-1700.TH2_Release_IOTCoreRPi_armFRE

@ mcalsyn - did I type cram, oops I ment cream. I assumed that it functioned using a cream xbee module driver support, but having a closer look at the code I realized it was something else. :wall:

And yes the link is very helpful, thanks.

I’ve got 10586 on my pi so I’ll give a shot …

@ .Peter. - Before I move this to production nuget, I do plan to make it look like the rest of the Cream drivers. There’s also a lockup that may occur if you don’t activate the logdebug level of debugging (see earlier posts). Some thread is not getting enough love I guess. I need to fix that too before I can declare victory.

Well there you go, thanks! I could have sworn I downloaded the UART supporting version, but maybe I forgot to install it. :wink:

This is your new best friend : [url]Bing

That will download the new IoT Core Dashboard, which downloads the latest version and flashes your sd card all in one step.

@ mcalsyn - you mean this one - if all was that easy, getting gbee to work ain’t trivial to me … but keeps me from getting bored …

Looks like this version comes with a required update to VS Update 1, but I’m sure when that’s done I’ll at least be able to open the XBee, then on to figuring out how to parse IO data.

GBee isn’t exactly extensively documented from the looks of things.

@ GHI - Any news from the Cream team ? Any new module drivers support ?

I’ll leave it up to you guys to guess which one can be put on the most wanted list … :whistle:

Hmm, anyone else run into this after an upgrade to 10586?

Edit: Nevermind, once I checked the “Uninstall and re-install” option in the project’s Debug tab it worked.

Did you update VS as well ?

Edit: Cool 8)

@ .Peter. - Yeah, it seems it just needed the rebuild to be happy.

That said, my default app now says 10.0.586.0 but I still have a null serial port…

I do have 1 element in my devices collection, the devices[0] does have an ID that references UART0.

But for some reason, it doesn’t come back with a serialdevice.

@ Squeebee - Yep, now I got the same situation as well.

But, after a not wanted disconnect of the power source on the PI and the obligatory reboot, I all of a sudden got a nice access violation. And thereafter again your (or better our) little serialPort in the collection but not addressable …

Wasn’t there a statement from GHI somewhere they wanted to block off the UART in the Cream until it is properly supported ?

Maybe you can try the USB/UART (disconnect the cream) and see if you got the same reaction. Or wire xbee directly to the pi expansion without the cream.

@ Squeebee - … it all of a sudden bit me in the … well, you know where …

Have you checked your manifest and included serialcommuncation … I remember that from BLE some time ago, now that can be done per GUI on the manifest but not serial communication. You have to hand edit that. File in your project is the package.appxmanifest. Simply right click and view code. and add inside the capabilities. After that I could easily establish the serial comm. Good luck !!!

2 Likes

@ .Peter. - I’m amazed that you caught that! It worked!

Now to get it handling IO Data packets.