![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 6
| Raw volume access to SD Card (USB adapter) I'm new in this Forum and has following Issue: I need to read and write to an sd Card at raw level (without FAT). I read and write Data Sectorwise (512Bytes) with a µC to the SD Card. This Data I need on the PC. It's a SD card in a card reader. There are API Funktions to do that, but I never used API Funktions. I found an old Thread in this Forum: Raw volume access (to a usb volume) Has anybody solved this? Thanks! |
| hans75 is offline | |
| | #2 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,927
| |
| abachler is offline | |
| | #3 |
| Registered User Join Date: Nov 2009
Posts: 6
| Thanks for the reply! I use followinf funktion: Code: void tmain(void)
{
HANDLE hFile;
DWORD dwBytesRead = 0;
char ReadBuffer[BUFFER_SIZE] = {0};
hFile = CreateFile("\\.\E:",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("Could not open file (error %d)\n", GetLastError());
return;
}
// Read one character less than the buffer size to save room for
// the terminating NULL character.
if( FALSE == ReadFile(hFile, ReadBuffer, BUFFER_SIZE-2, &dwBytesRead, NULL) )
{
printf("Could not read from file (error %d)\n", GetLastError());
CloseHandle(hFile);
return;
}
if (dwBytesRead > 0)
{
ReadBuffer[dwBytesRead+1]='\0'; // NULL character
_tprintf(TEXT("Text read from %s (%d bytes): \n"), dwBytesRead);
printf("%s\n", ReadBuffer);
}
else
{
_tprintf(TEXT("No data read from file %s\n"));
}
CloseHandle(hFile);
}
Code: if (hFile == INVALID_HANDLE_VALUE) What can I do? |
| hans75 is offline | |
| | #4 |
| Registered User Join Date: Nov 2009
Posts: 6
| Does nowbody have an idea? Now I use following parameters for this function: Code: hFile = CreateFile("\\.\E:",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING,NULL);
|
| hans75 is offline | |
| | #5 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,927
| remember that visual studio views characters preceded by a \ as a switch. The proper text is Code: hFile = CreateFile("\\\\.\\E:",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
| | #6 |
| Registered User Join Date: Nov 2009
Posts: 6
| Thanks a lot!! It worked! |
| hans75 is offline | |
| | #7 |
| Registered User Join Date: Nov 2009
Posts: 6
| Hello, I have one more question to this issue. Following code example works fine to read all data from the SD-Card. Each reading goes one sector forward. But how can I read from different sectors, for example sector 34? Code: private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
if( FALSE == ReadFile(hFile, ReadBuffer, BUFFER_SIZE, &dwBytesRead, NULL) )
{
CloseHandle(hFile);
return;
}
if (dwBytesRead > 0)
{
String ^ str = gcnew String(ReadBuffer);
textBox1->AppendText(str);
while(ReadBuffer[2] != 0x00) // reads until the end
{
ReadFile(hFile, ReadBuffer, BUFFER_SIZE, &dwBytesRead, NULL);
String ^ str = gcnew String(ReadBuffer);
textBox1->AppendText(str);
}
}
else
{
MessageBox::Show("No data read from volume");
}
}
|
| hans75 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Vector out of range program crash. | Shamino | C++ Programming | 11 | 01-18-2008 05:37 PM |
| C functions to access USB port. | nethunter | Networking/Device Communication | 1 | 04-10-2006 02:25 PM |
| How to Access Ethernet Card From C++ | DrMario | C++ Programming | 6 | 03-24-2005 05:38 PM |
| Onboard video card memory access | HermioneFan | Game Programming | 1 | 05-28-2003 09:53 AM |
| How to access Network Card using C | vadiv | A Brief History of Cprogramming.com | 0 | 10-17-2001 01:47 AM |