On 25/11/2011 22:20, Brendan Simon (eTRIX) wrote:
On 26/11/11 12:12 AM, David Hughes wrote:
On 25/11/2011 11:22, Brendan Simon (eTRIX) wrote:
Anyone know how to retrieve the unique serial number of a usb storage
device using python on OS X ??
How about using

system_profiler SPUSBDataType
I treid the system_profiler and got the following results when I plugged
a couple of usb flash sticks in.
I couldn't see anything that resembles a unique usb storage device
serial number :(  I think it is supposed to be a 12 digit (hex) number.

Either system_profiler doesn't report it, or these devices don't have
unique serial numbers (unlikely), or I am missing something (not unlikely).

Any thoughts ??

Strange, I just tried it here and got a serial number as usual (OS X 10.7.2 and also 10.6.8):

            STORE N GO:

              Capacity: 4 GB (4,001,366,016 bytes)
              Removable Media: Yes
              Detachable Drive: Yes
              BSD Name: disk1
              Product ID: 0x3623
              Vendor ID: 0x13fe  (Phison Electronics Corp.)
              Version: 1.10
              Serial Number: 079A1111814F57E3
              Speed: Up to 480 Mb/sec
              Manufacturer: Verbatim
              Location ID: 0xfa130000 / 6
              Current Available (mA): 500
              Current Required (mA): 200
              Partition Map Type: MBR (Master Boot Record)
              S.M.A.R.T. status: Not Supported
              Volumes:
                DEVELOPER:
                  Capacity: 4 GB (3,997,237,248 bytes)
                  Available: 3.76 GB (3,759,636,480 bytes)
                  Writable: Yes
                  File System: MS-DOS FAT32
                  BSD Name: disk1s1
                  Mount Point: /Volumes/DEVELOPER
                  Content: DOS_FAT_32

To check if your device does have a serial number can you run the attached python script using Windows?
The above device reports:

USB Device Id is USB\VID_13FE&PID_3623\079A1111814F57E3 (VBscript)

--
Regards

David Hughes
Forestfield Software



import sys, os

def usbid_script(usbstring=''):
    """ Return True if usbid string matches (any) USB mass storage device
        Information is obtained from WMI via a VBscript that is run by Windows 
CScript.exe 
    """
    script = 'temp_script.vbs'
    fi = open(script, 'w')
    s = [ 'Set wbemServices = GetObject("winmgmts:")\n',
          'Set wbemObjectSet = wbemServices.InstancesOf("Win32_PnPEntity")\n',
          'For Each wbemObject In wbemObjectSet\n',
          'If wbemObject.Name = "USB Mass Storage Device" Then\n',
          'WScript.Echo wbemObject.PNPDeviceID\n',
          'End If\n',
          'Next\n' ]
    fi.writelines(s)
    fi.close()

    usb_isok = False
    script_error = False
    numlines = 0
    fo = os.popen('CScript %s  //NoLogo' % script , 'r')
    for device in fo.readlines():
        numlines += 1
        script_error = (device.lower().find('error') >= 0)
        if usbstring:
            usb_isok = compare_strings(usbstring, device.strip(), 2)
            if usb_isok: break
        else:
            print 'USB Device Id is %s (VBscript)' % device.strip()
    fo.close()
    os.remove(script)
    if script_error or numlines == 0:
        usb_isok = None             # script failed
    return usb_isok

usbid_script('')
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

Reply via email to