#!/usr/bin/perl

# Find FTDI USB device

open (LSHAL, "lshal |");
$LookForState=0;
while (<LSHAL>){

#Look for serial number:
#udi = '/org/freedesktop/Hal/devices/usb_device_403_6001_FTSC89JG_if0_serial_usb_0'
if ($LookForState==0 and $_ =~ m/^udi =/ and $_ =~ m/_403_6001_/){
  #print "\tfound serial=".$_;
  $LookForState=1;
}

#Look for:
#  usb_device.serial = 'FTSC89JG'  (string)
if ($LookForState==1 and $_ =~ m/usb.serial/){
  @array = split(" ",$_);
  $USBDeviceSerial=@array[2];
  print "Serial=".$USBDeviceSerial;
  $LookForState=2;
}

#Look for linux.device_file:
if ($LookForState==2 and $_ =~ m/linux.device_file/){
  @array = split(" ",$_);
  $LinuxDeviceFile=@array[2];
  print "\tDev=".$LinuxDeviceFile."\n";
  $LookForState=0;
}
}

close LSHAL;
