11 Replies - 2653 Views - Last Post: 20 August 2013 - 08:40 AM Rate Topic: -----

#1 Carbon_kid85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-August 13

SD card raw IO data access question

Posted 16 August 2013 - 01:46 AM

Hi im trying to write a vb.net application to read and write raw data to and from an SD card.

I'm a bit of a newby so bare with me.

ive downloaded a class library written in c++ form http://www.planet-so...=7856&lngWId=10

I've got as far as adding this to the project and referencing it. I just need some help and advice on how to impliment it.

Many thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: SD card raw IO data access question

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9501
  • View blog
  • Posts: 35,849
  • Joined: 12-June 08

Re: SD card raw IO data access question

Posted 16 August 2013 - 06:40 AM

What do you mean by 'raw io'? Will 'streamreader' or 'file reader' namespaces do?
Was This Post Helpful? 0
  • +
  • -

#3 Carbon_kid85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-August 13

Re: SD card raw IO data access question

Posted 16 August 2013 - 06:49 AM

View Postmodi123_1, on 16 August 2013 - 06:40 AM, said:

What do you mean by 'raw io'? Will 'streamreader' or 'file reader' namespaces do?


By raw i mean i file system that is not formatted.

I am trying to write an application to read the data from an sdcard that has been used by a micro controller. We have system in the field that save their configuration to an sdcard.

I'm trying to make this application so the field engineers can record the configuration from the systems and eventually edit it on their laptops.

But obviously when you insert the sdcard into your computer windows wants to format it. But google says its possible to do what im trying to achieve.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9501
  • View blog
  • Posts: 35,849
  • Joined: 12-June 08

Re: SD card raw IO data access question

Posted 16 August 2013 - 07:08 AM

Hmm.. that's odd.

Are you all just jamming this into a laptop or something? I hear sometimes sd card readers get around this. The other alternative is why not format the cards first and then use them in the devices second?

The large problem is if your OS cannot recognize a drive is there then there's a problem using managed code like .NET. You would need to either flip to just c++ for the read/write of the file, or start mucking around in P/Invoke Createfile.

http://msdn.microsof...y/aa363858.aspx
http://msdn.microsof...v=vs.85%29.aspx
Was This Post Helpful? 0
  • +
  • -

#5 Carbon_kid85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-August 13

Re: SD card raw IO data access question

Posted 16 August 2013 - 07:43 AM

View Postmodi123_1, on 16 August 2013 - 07:08 AM, said:

Hmm.. that's odd.

Are you all just jamming this into a laptop or something? I hear sometimes sd card readers get around this. The other alternative is why not format the cards first and then use them in the devices second?

The large problem is if your OS cannot recognize a drive is there then there's a problem using managed code like .NET. You would need to either flip to just c++ for the read/write of the file, or start mucking around in P/Invoke Createfile.

http://msdn.microsof...y/aa363858.aspx
http://msdn.microsof...v=vs.85%29.aspx


The embedded system writes to secors of the card starting from 0 so as soon as you put it in the system overwrites any fat table created on the card and the formatting will be destroyed.

Ive never done any programming in c++ so that is why I'm attempting to use the library someone else has created (hard stuff done). But like all home made code it come with no documentation so im struggling to impliment it.
Was This Post Helpful? 0
  • +
  • -

#6 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: SD card raw IO data access question

Posted 16 August 2013 - 12:29 PM

Do you have an compiled library, or can you compile it? If so, using it is pretty straightforward.. this should work..

    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        Dim contents() As Byte
        Dim myStream As New RAW.DISK.streamer = RAW.DISK.CreateStream("C:", FileAccess.Read)
        contents = RAW.DISK.ReadSector(0, 512, myStream)
        'do whatever you want with these bytes
        RAW.DISK.DropStream(myStream)
    End Sub


If you don't have a compiled library, you'll have to get one or translate the C++ code into VB.Net and make your own library. Perhaps someone on the C++ help forum could lend a hand with that.
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 838
  • View blog
  • Posts: 2,463
  • Joined: 20-March 10

Re: SD card raw IO data access question

Posted 18 August 2013 - 03:56 AM

Hi,

The solution is actually written in C#

but should work for managed code vb.net, C# and C++.net.

I will attach the compiled .dll

Attached File  RAW.zip (2.56K)
Number of downloads: 150

Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#8 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: SD card raw IO data access question

Posted 18 August 2013 - 07:49 AM

View Postsnoopy11, on 18 August 2013 - 04:56 AM, said:

but should work for managed code vb.net, C# and C++.net.

I will attach the compiled .dll

Got it. Thanks.

The good news is that it does work. The bad news is that it apparently will not work on all drives. I have tried it on my "C:" drive. No go. On my "J:" drive, which is an external (USB) drive. No go. I'm pretty sure that Big Brother er... Windows 7 is blocking direct access to some drives.

I also tried it on a Micro SD card, plugged into a USB adapter, that that was successful. I'll give it a try on a few other things, and if anything looks interesting, I'll let you know. Here's what I used.

Option Strict On
Imports RAW
Imports System.IO

Public Class Form1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim contents(512) As Byte
        Dim myStream As New RAW.DISK.streamer
        myStream = RAW.DISK.CreateStream("I:", FileAccess.Read)
        contents = RAW.DISK.ReadSector(0, 512, myStream)
        'do whatever you want with these bytes
        RAW.DISK.DropStream(myStream)
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#9 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: SD card raw IO data access question

Posted 18 August 2013 - 11:45 PM

Further inverstigation tells me that at least one of the reasons for failure to open the stream is that the disk is in use esewhere. If I plug an SD card into the reader, I can read it. However, if I open it in Windows Explorer (actually in xplorer2), it will fail. You can check for success with myStream.isError, as shown in the following code.

To run this, make two Button (ReadSect and ReadNext), a small TextBox for the drive letter, and a large one for the Hex Dump. Make the TextBox Font Courier New (monospaced).

Run it, enter a drive letter, click the button, and see what your drive contains.


Option Strict On
Imports RAW
Imports System.IO

Public Class Form1
    Private sector As Integer = 0

    Private Sub ReadSect_Click(sender As System.Object, e As System.EventArgs) Handles ReadSect.Click
        ReadSector(sector)
    End Sub

    Private Sub ReadNext_Click(sender As System.Object, e As System.EventArgs) Handles ReadNext.Click
        sector += 512
        TextBox2.Clear()
        ReadSector(sector)
    End Sub

    Private Sub ReadSector(ByVal sect As Integer)
        Dim contents() As Byte
        Dim myStream As New RAW.DISK.streamer
        myStream = RAW.DISK.CreateStream(TextBox1.Text, FileAccess.Read)
        If myStream.isERROR Then
            MessageBox.Show("Could not create file handle")
        Else
            contents = RAW.DISK.ReadSector(sector, 512, myStream)
            Dump(contents, sector)
            'do whatever you want with these bytes
        End If
        RAW.DISK.DropStream(myStream)
    End Sub

    Private Sub Dump(ByVal contents() As Byte, ByVal sect As Integer)
        Dim tempadd As String
        Dim tempdata As String
        For i = 0 To 496 Step 16
            tempadd = "00000000" & Hex(i + sect)
            tempdata = "00" & Hex(contents(i))
            TextBox2.Text += tempadd.Substring(tempadd.Length - 8) & "   " & tempdata.Substring(tempdata.Length - 2)
            'Application.DoEvents()

            For j = i To i + 15
                If j Mod 4 = 0 And j > i + 2 Then TextBox2.Text += " "
                tempdata = "00" & Hex(contents(j))
                TextBox2.Text += " " & tempdata.Substring(tempdata.Length - 2)
                'Application.DoEvents()
            Next

            TextBox2.Text += "  "

            For j = i To i + 15
                If contents(j) >= 32 And contents(j) <= 126 Then
                    TextBox2.Text += ChrW(contents(j))
                    'Application.DoEvents()
                Else
                    TextBox2.Text += "."
                    'Application.DoEvents()
                End If
            Next

            TextBox2.Text += vbNewLine
            'Application.DoEvents()
        Next
    End Sub

End Class


Edit: Fixed error in loop counter.

This post has been edited by lar3ry: 19 August 2013 - 09:29 AM

Was This Post Helpful? 0
  • +
  • -

#10 Carbon_kid85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-August 13

Re: SD card raw IO data access question

Posted 20 August 2013 - 06:55 AM

Hi all thanks for all you help.

It seems to me that windows is the weakest link in what I'm trying to achieve with this project. I managed to read an sd with a very old usb reader but it was very flaky. and as the engineers have a mixture of xp, 7 and even one 8 machines, this needs to work reliably.

We have now settled upon a new approach we are going to pick up some arduino or arduino like boards with a micro sd slot and write some code to squirt the contents of the sdcard out of the uart. and I'll write an application to capture that.

Whilst trying to do this project I found other forums with people trying to do the same thing. I'll post the links below as they might be able to help someone else.

Again thank you for all your help.

http://www.codeproje...k-Sector-Readin
http://social.msdn.m...o-an-executable
http://stackoverflow...n-instance-of-a
Was This Post Helpful? 0
  • +
  • -

#11 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: SD card raw IO data access question

Posted 20 August 2013 - 08:08 AM

Glad to be of assitance!

I agree that Windows rather gets in the way. In some respects, that isn't a bad thing, as it helps protect the integrity of the OS. Getting around that is always difficult, and I think you are wise to go the Arduino route. It's simple, cheap, and will probably do the trick. I haven't looked at the SD library at all, so I don't know if the solution will be easy or difficult, but it has to be easier than trying to make a VB.Net solution for all platforms.
Was This Post Helpful? 0
  • +
  • -

#12 Carbon_kid85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-August 13

Re: SD card raw IO data access question

Posted 20 August 2013 - 08:40 AM

View Postlar3ry, on 20 August 2013 - 08:08 AM, said:

I haven't looked at the SD library at all, so I don't know if the solution will be easy or difficult, but it has to be easier than trying to make a VB.Net solution for all platforms.



I've looked at the SD card library on the arduino website and someone has done a lot of hard work to make it work with fat16 and fat32. Shame I'll only be reading the hex from the first sector. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1