Main Site Documentation

USB Eject event error on NEtmf 4.3


#1

Hello
I want to execute some code on removableMedia.Eject event
but when I remove the usb This Occurs :

what is the problem?
thanks


#2

Please provide a complete minimal example showing this behavior.


#3

ok this is my code:


private void rfid_CardIDRecieved(RFIDReader sender, string ID)
        {
            if (!processing)
            {

                RenderUIView(UIView.LoginView);

                try
                {
                    byte[] passData = System.Text.Encoding.UTF8.GetBytes(ID);
                    WebRequest request = WebRequest.Create(URLHelper.ConfigInfoURL);
                    request.Method = "POST";
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.ContentLength = passData.Length;

                    #region Add Headers
                    request.Headers.Add("RFID", ID);
                    #endregion
                    Stream dataStream = request.GetRequestStream();
                    dataStream.Write(passData, 0, passData.Length);
                    dataStream.Close();
                    WebResponse response = request.GetResponse();
                    string userName = ((HttpWebResponse)response).Headers["UserName"];
                    response.Close();

                    if (userName != "unAuthenticatedUsers")
                    {
                        RFIDIsValid = true;
                        txtuserName = new Text(fnt, userName);

                        Canvas.SetTop(_HomeViewLogo, 5);
                        Canvas.SetLeft(_HomeViewLogo, 70);
                        canvas.Children.Add(txtuserName);
                        Canvas.SetLeft(txtuserName, txtuserNameX);
                        Canvas.SetTop(txtuserName, txtuserNameY);
                        _UserRFID = ID;
                        RenderUIView(UIView.InsertUSBView);
                        processing = true;
                    }
                    else if (userName == "unAuthenticatedUsers")
                    {
                        RFIDIsValid = true;
                        txtuserName = new Text(fnt, "Unauthenticated User");
                        Canvas.SetTop(_HomeViewLogo, 5);
                        Canvas.SetLeft(_HomeViewLogo, 70);
                        canvas.Children.Add(txtuserName);
                        Canvas.SetLeft(txtuserName, txtuserNameX);
                        Canvas.SetTop(txtuserName, txtuserNameY);
                        _UserRFID = ID;
                        RenderUIView(UIView.InsertUSBView);
                        processing = true;

                    }
                    else
                    {
                        RFIDIsValid = false;
                        txtuserName = new Text(fnt, "not valid...");
                        txtuserName.Visibility = Visibility.Visible;
                        canvas.UpdateLayout();
                        RFIDIsValid = false;
                    }
                }
                catch
                {
                    processing = false;


                }

            }

public void RemovableMedia_Insert(object sender, MediaEventArgs e)
        {
            if (RFIDIsValid)
            {
                try
                {
                    savedVolInfo = e.Volume;
                    rootDirectory = savedVolInfo.RootDirectory;
                   
                }
                catch(Exception ex) 
                {
                    Debug.Print(ex.StackTrace);

                }
            }
        }

 public void RemovableMedia_Eject(object sender, MediaEventArgs e)
        {
            try
            {
               rootDirectory = "";
                RFIDIsValid = false;
            }
            catch { }
        }



#4

that is your code, not a minimal example - please test an example that doesn’t rely on your RFID card reader but still shows the situation.


#5

no matter… this is a very simple example :


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.IO;
using System.IO;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp1
{
    public partial class Program
    {
        int Number = 0;
        void ProgramStarted()
        {
            RemovableMedia.Insert += RemovableMedia_Insert;
            RemovableMedia.Eject += RemovableMedia_Eject;
        }
       
        void RemovableMedia_Insert(object sender, MediaEventArgs e)
        {
            Number++;
        }
        void RemovableMedia_Eject(object sender, MediaEventArgs e)
        {
            Number--;
        }

    }
}

That error again occurs… :frowning:
Actually this dialog box appears :


#6

@ Ehsan Ansari - What board are you using and what modules are connected in the designer?


#7

@ John -
It is a Raptor with following modules :
USB Host
Ethernet ENC28
USB Client DP
Displat T35
RFID Reader
SD Card Module


#8

@ Ehsan Ansari - This should be fixed in the next SDK.