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?
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.
@ .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.
@ 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.
@ 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:
@ .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.
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.
@ 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 !!!