Read Flash Serial Number - eVC
Notice of Deprecation
We have deprecated this code. While this example will work for the 8-byte ID returned by current flash chips, it would not work with other sizes that could be used in the future.
Below is a code snippet showing how to read the 64-bit serial number of the on-board flash of some ADS systems (see Topic 1242 for support info).
#include "windows.h"
#define IOCTL_READ_FLASH_ID 0x10
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow )
{
BOOL bRet;
ULONG BytesRet;
HANDLE hPort = INVALID_HANDLE_VALUE;
// Open a handle to the Flash driver
hPort = CreateFile (TEXT("FSH1:"),
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
// sanity check
if (hPort == INVALID_HANDLE_VALUE)
{
RETAILMSG(1,(L" ReadFlashID: Could not open File %s.\\r\\n",TEXT("FSH1:")));
return FALSE;
}
BYTE a[1];
USHORT b[4];
// read the flash ID through an IOCTL
bRet = DeviceIoControl( hPort,
IOCTL_READ_FLASH_ID,
a, // not used, but can't be NULL
0,
b,
sizeof(b),
&BytesRet, // not actually set to any valid number
NULL);
RETAILMSG(1,(L" \\r\\n ReadFlashID: "));
if(! bRet)
{
RETAILMSG(1,(L" \\r\\n Failed\\r\\n"));
return 0;
}
TCHAR id[20];
// output the ID
_stprintf(id, _T("%04X %04X %04X %04X"), b[0], b[1], b[2], b[3]);
RETAILMSG(1,(_T("%s\\r\\n"), id));
MessageBox(NULL, id, _T("Flash ID"), 0);
// close the driver
if(hPort != INVALID_HANDLE_VALUE)
{
CloseHandle(hPort);
hPort = INVALID_HANDLE_VALUE;
}
// exit
return 0;
}
Edited by akidder 12-May-2008: Add notice of deprecation.