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

Detect Eject SD card in VB.net


  • Please log in to reply
5 replies to this topic

#1 Novice Alex

Novice Alex

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts

Posted 10 August 2012 - 01:30 AM

Hi Guys,

Anyone familiar with VB.net can help with some code on how to detect the SD card been ejected?
I am following this topic, but I can do the same in VB.net. Please help and thanks in advance.

Links on how to detect presence of SD card

#2 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 10 August 2012 - 01:44 AM

Hi Guys,

Anyone familiar with VB.net can help with some code on how to detect the SD card been ejected?
I am following this topic, but I can do the same in VB.net. Please help and thanks in advance.

Links on how to detect presence of SD card


This code is from Stefan's post converted to VB.
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports Microsoft.SPOT
Imports Microsoft.SPOT.IO
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus
Namespace SdCard
	Public Class Program
		Public Shared Sub Main()
			RemovableMedia.Insert += New InsertEventHandler(RemovableMedia_Insert)
			RemovableMedia.Eject += New EjectEventHandler(RemovableMedia_Eject)
			Thread.Sleep(Timeout.Infinite)
		End Sub
		Private Shared Sub RemovableMedia_Eject(sender As Object, e As MediaEventArgs)
			Debug.Print("Ejected")
		End Sub
		Private Shared Sub RemovableMedia_Insert(sender As Object, e As MediaEventArgs)
			Debug.Print("Inserted")
		End Sub
	End Class
End Namespace
I don't have anyway to test here, I am working out of state and staying in a hotel. :(
Chuck

#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 10 August 2012 - 06:33 AM

This code is from Stefan's post converted to VB.

I don't have anyway to test here, I am working out of state and staying in a hotel. :(
Chuck


That code won't work in VB.NET since it works differently with events. This would work:
Module Module1

    Sub Main()
        AddHandler Microsoft.SPOT.IO.RemovableMedia.Eject, AddressOf RemovableMedia_Eject
        AddHandler Microsoft.SPOT.IO.RemovableMedia.Insert, AddressOf RemovableMedia_Insert
        Thread.Sleep(Timeout.Infinite)
    End Sub

    Sub RemovableMedia_Eject(sender As Object, e As Microsoft.SPOT.IO.MediaEventArgs)
        Debug.Print("Ejected")
    End Sub

    Sub RemovableMedia_Insert(sender As Object, e As Microsoft.SPOT.IO.MediaEventArgs)
        Debug.Print("Inserted")
    End Sub

End Module

"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 10 August 2012 - 09:49 AM

Thanks, Stefan, I tried to help, but all I could do was to try and convert the code he had. Should have known better. Chuck

#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 10 August 2012 - 10:05 AM

I tried to help, but all I could do was to try and convert the code he had. Should have known better.

Oh no worries! I like seeing people beeing helpful!
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 Novice Alex

Novice Alex

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts

Posted 11 August 2012 - 08:19 AM

That code won't work in VB.NET since it works differently with events. This would work:

Module Module1

    Sub Main()
        AddHandler Microsoft.SPOT.IO.RemovableMedia.Eject, AddressOf RemovableMedia_Eject
        AddHandler Microsoft.SPOT.IO.RemovableMedia.Insert, AddressOf RemovableMedia_Insert
        Thread.Sleep(Timeout.Infinite)
    End Sub

    Sub RemovableMedia_Eject(sender As Object, e As Microsoft.SPOT.IO.MediaEventArgs)
        Debug.Print("Ejected")
    End Sub

    Sub RemovableMedia_Insert(sender As Object, e As Microsoft.SPOT.IO.MediaEventArgs)
        Debug.Print("Inserted")
    End Sub

End Module


Hi Carb & Stefan,

Thank you for your great helps.

Cheers!




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.