I am using a FEZ Spider kit and have used Glide to create a 3x4 keypad on the touchscreen. When a user touches one of the numbers, I would like to save that number in a file to reference later. What is the best way to output to a text file? I have tried using the StreamWriter structure but am getting unhandled exceptions that prevent the program from running. Here is the code for the method attempting to handle a tap event for the button labelled num1:
As Justin said, there’s no C: driver in the system. His reference is standard .NETMF code.
Using SD with Gadgeteer, there’s another slightly different option - using the Gadgeteer.StorageDevice class instead of the PersistentStorage. Here’s some code that I’m using
I had issues running my SD code from my Doimino on my Spider, it keep blowing up on the opening of the stream. Switching to the StorageDevice class remedied that.
So I’m not sure if my old code had issues or if there are compatibility issues between plain ol’ NETMF and Gadgeteer.
@ mhectorgato, I love how simple it looks to do it through the Gadgeteer.StorageDevice class. What extra code do I need to use other than the snippet you included? I’m getting an error with the bolded words below telling me that none of them exist in the current context.
Thanks, Mike! logPage solved that problem. I am still struggling with the other 2 because the Program.generated.cs doesn’t seem to work with the code I’ve written. I apologize, I’m new with this so I am unsure how these files are supposed to work together. It continuously regenerates the auto code with a line stating program.ProgramStarted(); but that is no where in the code I have written so there is an argument there as well as not recognizing sdCard or Info. Eventually when the button number 1 is pressed, I would like the number 1 to be written into a file on the SD card (I have a full keypad created so in then end hopefully it will work for all buttons).
Here is my code:
using System;
using System.Threading;
using System.IO;
using System.Text;
using Gadgeteer;
using Gadgeteer.Modules.GHIElectronics;
using GHIElectronics.NETMF.Glide;
using GHIElectronics.NETMF.Glide.Display;
using GHIElectronics.NETMF.Glide.UI;
using TouchTest;
namespace Test
{
public class Program
{
static Window window;
namespace TouchTest
{
public partial class Program : Gadgeteer.Program
{
// GTM.Module defintions
Gadgeteer.Modules.GHIElectronics.UsbClientDP usbClient;
Gadgeteer.Modules.GHIElectronics.Display_T35 display;
Gadgeteer.Modules.GHIElectronics.SDCard sdCard;
public static void Main()
{
//Important to initialize the Mainboard first
Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
Program program = new Program();
program.InitializeModules();
program.ProgramStarted();
program.Run(); // Starts Dispatcher
}
private void InitializeModules()
{
// Initialize GTM.Modules and event handlers here.
usbClient = new GTM.GHIElectronics.UsbClientDP(1);
sdCard = new GTM.GHIElectronics.SDCard(5);
display = new GTM.GHIElectronics.Display_T35(14, 13, 12, 10);
}
}
@ jwsail - You’re supposed to leave Program.Generated.cs alone, it auto-generates code with object instances to match the module’s you’ve got connected in the Program.Gadgeteer design diagram, but you can otherwise ignore it and not worry about it. Your code goes in Program.cs, and the entry point in that is ProgramStarted() not Main(). You don’t need to add a Main yourself. GHI’s Getting Started guide for Spider Start Kit is [here].
Thank you, that helped sort out all of the consistency issues between the names in both parts. I know not to touch the auto-generated code, I just couldn’t figure out why all the names weren’t lining up. That’s fixed now. There are 2 errors left that I can’t figure out, even after reading through the guide and I think it’s because I don’t fully understand the different reference types.
The first has to do with the line where sdCard is used: _storage = sdCard.GetStorageDevice();
I am getting this error: An object reference is required for the non-static field, method, or property ‘TouchTest.Program.sdCard’
The next has to do with a line in the auto-generated code: program.ProgramStarted();
I am getting this error: Member ‘TouchTest.Program.ProgramStarted()’ cannot be accessed with an instance reference; qualify it with a type name instead
Never mind, I was able to correct those errors by removing the ‘static’ in the function declarations. The program builds now!
When I press the number 1 on the touchscreen, I get this error: An unhandled exception of type ‘System.ArgumentException’ occurred in System.IO.dll
and it points to this line: StreamWriter sw = new StreamWriter(“C:\log.txt”, true);
Wow, I’ve been staring at this for so long that I can’t even find my own dumb mistakes like that! That was a line of old code that I forgot to take out. It all works great now, thank you all for your help!