How to get device serial no/ID in C?

This is a discussion on How to get device serial no/ID in C? within the C Programming forums, part of the General Programming Boards category; Hi, Can anyone help me to get device serial no/ID in C, such as the serial no of HDD:IDE/SCSI, Main ...

  1. #1
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532

    How to get device serial no/ID in C?

    Hi,
    Can anyone help me to get device serial no/ID in C, such as the serial no of HDD:IDE/SCSI, Main Board, Floppy.
    Last edited by zahid; 07-05-2002 at 09:51 PM.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  2. #2
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532
    Category :Windows API

    Question:
    How can I get volume information, such as the serial number,
    from my drivers?

    Answer:
    procedure TForm1.Button1Click(Sender: TObject);
    var
    VolumeName,
    FileSystemName : array [0..MAX_PATH-1] of Char;
    VolumeSerialNo : DWord;
    MaxComponentLength,
    FileSystemFlags : Integer;
    begin
    GetVolumeInformation('C:\',VolumeName,MAX_PATH,@Vo lumeSerialNo,
    MaxComponentLength,FileSystemFlags,
    FileSystemName,MAX_PATH);
    Memo1.Lines.Add('VName = '+VolumeName);
    Memo1.Lines.Add('SerialNo = $'+IntToHex(VolumeSerialNo,8));
    Memo1.Lines.Add('CompLen = '+IntToStr(MaxComponentLength));
    Memo1.Lines.Add('Flags = $'+IntToHex(FileSystemFlags,4));
    Memo1.Lines.Add('FSName = '+FileSystemName);
    end;

    Can anyone translate it into C?
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  3. #3
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532
    GetVolumeInformation In

    Turbo C++
    Version 3.0

    No function found.....
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  4. #4
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532
    hahaha, Yeah.. fossil compiler.
    What is the header file for that function ?
    Do you know the library..

    Anyway.. I will check your links.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  5. #5
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    532
    Code:
    int GetIdeInfo (int Drive, unsigned int *DInfo)
    {
        volatile unsigned int retry;
        int wordno;
    
        /* Wait until controller is not busy */
        retry = UINT_MAX;
        while ((inp(0x1F7) != 0x50) && --retry);
        if (!retry) return 1;
    
        /* Get drive information */
        outp(0x1F6, Drive ? 0xB0:0xA0);
        outp(0x1F7, 0xEC);
    
        /* Wait until data is available */
        retry = UINT_MAX;
    
    while ((inp(0x1F7) != 0x58) && --retry);
        if (!retry) return 1;
    
        /* Read the drive information */
        for (wordno=0; wordno<256; wordno++)
    	DInfo[wordno] = inpw(0x1F0);
    
        /* Return succesful */
        return  (0);
    }
    
    
    const char *ToText (const unsigned int *Data, int Start, int End)
    {
        static char Dest[512];
        int Ctr1, Ctr2;
        int i;
    
        for (Ctr1 = Start, Ctr2 = 0; Ctr1 <= End; Ctr1++, Ctr2 += 2)
        {
    		Dest[Ctr2+0] = (char) (Data[Ctr1] >> 8);
    		Dest[Ctr2+1] = (char) (Data[Ctr1] & 255);
        }
        Dest[Ctr2] = '\0';
    
        for(i=strlen(Dest)-1;i>=0;i--)
    		if(Dest[i]==' ')
    			Dest[i]=0;
    		else
    			break;
    
         return (Dest);
    }
    Any idea on the functions? Specially for Salem.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    104
    Yes, but how do you get the serial for the IDE/SCSI and Main Board?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading from serial device
    By chris24300 in forum Linux Programming
    Replies: 3
    Last Post: 06-16-2009, 01:53 PM
  2. Reading from a serial device
    By chris24300 in forum C Programming
    Replies: 2
    Last Post: 06-16-2009, 01:05 PM
  3. Talking to device over Serial: Write works, Read doesn't
    By theBishop in forum C Programming
    Replies: 2
    Last Post: 07-09-2008, 01:40 PM
  4. Replies: 4
    Last Post: 06-30-2004, 03:11 PM
  5. connecting to a serial device?
    By caefer in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-12-2004, 12:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21