Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Trouble writing to SD card on Nwazet DAQ

nwazet daq sd file IO netduino go

  • Please log in to reply
3 replies to this topic

#1 Seattle Food Geek

Seattle Food Geek

    New Member

  • Members
  • Pip
  • 3 posts

Posted 25 February 2013 - 12:03 AM

I just got a DAQ module from Nwazet, but I'm having trouble writing to its SD card using my Netduino Go.  Here's the setup:

 

DAQ connected to GoPort 1.  Button connected to GoPort 6. I've tried this with several SD cards: 1) 2GB, freshly formatted as FAT, 2) 4GB EyeFi card.  My master plan is to write text logs (suffixed as JPEG files) to the EyeFi card and use it to dump the logs on a server via WiFi.  I'll be awfully proud of myself if I can get it working :-)

 

Code is pretty simple.  Everything in Main() runs and I get a valid value for the amount of free space on the SD card.

 

 public static NwazetDAQ daq;        public static void Main()        {            Debug.EnableGCMessages(true);            Debug.Print("Available RAM: " + Debug.GC(true).ToString() + " bytes.");            daq = new NwazetDAQ();            daq.Initialize(GoSockets.Socket1, 10000);            Debug.Print("DAQ date time: " + daq.GetDateTime().ToString());            daq.FatFs.Mount();            Debug.Print("space: " + daq.FatFs.GetFreeSpace().FreeDiskSpaceKB.ToString());            NetduinoGo.Button btn = new NetduinoGo.Button(GoSockets.Socket6);            btn.ButtonPressed += new NetduinoGo.Button.ButtonEventHandler(btn_ButtonPressed);                                    while (true)            {                Thread.Sleep(250);            }        }        static void btn_ButtonPressed(object sender, bool isPressed)        {            Debug.Print("attempting file write at " + DateTime.Now.ToString());            var fileId = daq.FatFs.OpenFile("test.txt", FileSystem.FileMode.CreateAlways | FileSystem.FileMode.Read | FileSystem.FileMode.Write);            Debug.Print("file opened");            daq.FatFs.WriteString(fileId, "Hello World!rn");            Debug.Print("string written");            daq.FatFs.CloseFile(fileId);            Debug.Print("file closed");            daq.FatFs.SyncFile(fileId);            Debug.Print("finished");                    }

 

[font="arial, helvetica, sans-serif;"]However, the last line I ever see is "attempting file write at [time]".  After that, nothing. No error message, no break... nothing.  [/font]

[font="arial, helvetica, sans-serif;"] [/font]

[font="arial, helvetica, sans-serif;"]The SD cards aren't write protected and they're not full.[/font]

[font="arial, helvetica, sans-serif;"] [/font]

[font="arial, helvetica, sans-serif;"]Any ideas?[/font]

[font="arial, helvetica, sans-serif;"] [/font]

[font="arial, helvetica, sans-serif;"]Thanks in advance, all![/font]

 



#2 Seattle Food Geek

Seattle Food Geek

    New Member

  • Members
  • Pip
  • 3 posts

Posted 25 February 2013 - 12:30 AM

Well, I found a workaround, but I'm not sure exactly why it works. If I move the chunk of code in my button press method into Main(), it works.  My guess is that the thread from Main() comes alive during the execution of the button method and messes things up.

 

So, my NEW question is, how would one implement this sort of fuctionality?  Suppose I just want the NetduinoGo to sit idle until I push the button, then I want it to write to a file?

 

Thanks!



#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 February 2013 - 07:00 AM

Hmm, very interesting. I don't know what the issue is, but if you debug down into the peripheral's driver you can probably find out more... To answer your question, you have a few options for simple workarounds... Here are two ideas: 1. In your main routine you could just poll for the state of the button to change (a basic state machine). When it changes then you can run the code. Basically...a big loop. 2. You could put this logic on a background thread in a loop. And have that loop wait on a static AutoResetEvent. When your button is pressed, .Set() the AutoResetEvent instance and your background thread should be activated in parallel. Then simply return from your interrupt. Chris

#4 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 05 March 2013 - 10:33 PM

Hi Seattle Food Geek,

 

I just notice that the order of the calls is incorrect:

 

 


    [*][color=rgb(0,0,0);]daq[/color][color=rgb(102,102,0);].[/color][color=rgb(102,0,102);]FatFs[/color][color=rgb(102,102,0);].[/color][color=rgb(102,0,102);]CloseFile[/color][color=rgb(102,102,0);]([/color][color=rgb(0,0,0);]fileId[/color][color=rgb(102,102,0);]);[/color]
    [*][color=rgb(102,0,102);]Debug[/color][color=rgb(102,102,0);].[/color][color=rgb(102,0,102);]Print[/color][color=rgb(102,102,0);]([/color][color=rgb(0,136,0);]"file closed"[/color][color=rgb(102,102,0);]);[/color]
    [*][color=rgb(0,0,0);]daq[/color][color=rgb(102,102,0);].[/color][color=rgb(102,0,102);]FatFs[/color][color=rgb(102,102,0);].[/color][color=rgb(102,0,102);]SyncFile[/color][color=rgb(102,102,0);]([/color][color=rgb(0,0,0);]fileId[/color][color=rgb(102,102,0);]);[/color]
    [/list]

    Closing the file invalidates the fileId, and it should not be used afterward.

    [color=rgb(102,102,0);font-size:14px;]Just call SyncFile() before closing the file and things should be OK :)[/color]

     

    I hope this helps.

     

    -Fabien.







Also tagged with one or more of these keywords: nwazet, daq, sd, file IO, netduino go

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.