Keeping track of lab supplies Jan 2016

There’s this nasty thing with electronics: There Are So Many Kinds Of Tiny Little Components!

If you’re into hardware and building circuits, you’ll quickly find out that not only are there so many different resistors, capacitors, semiconductors, chips, sensors, LEDs, actuators, fasteners, wires, and so on… some of those SMD parts are also minuscule! - way too easy to lose track of.

At JeeLabs, there are now about a hundred cardboard boxes filled with little plastic envelopes, mostly from DigiKey, but more and more also ordered directly from China:

Over 2,000 different components. Enough to go insane when trying to find something again!

As always, there are many ways to address this problem. There are online sites which let you manage a parts inventory, and no doubt at least as many specialised applications for that task.

At JeeLabs, for many years now, a custom-made “ShopBase” has been in use. Implemented with FileMaker Pro, a commercial but very convenient and powerful database & front-end. But powerful as it may be, it was a drag to start up each time to find one specific component.

Online solutions have the same drawback, and besides… what’s the point of placing that information in the cloud when you only need it while standing next to those lab supplies?

There’s a much simpler solution. It’s extremely fast, trivial to build, and easily adapted and extended for any particular context: text files with a Unix shell script, using standard Unix tools. All running on Mac OSX in this case, but it would work equally well on Linux, and probably also on Windows with Mingw tools, etc. It’s called “labby”, because it’s a bit like a loyal Labrador?

$ labby 
JeeLabs Lab Supplies
Usage:
  labby <text> - find the specified search text (case insensitive)
  labby w <id> - open web page for specified product id
  labby a <box> <id> - add information about an item to the specified box

Let’s say we need to use a zener diode - which ones do we have lying around?

$ labby zener
c12     DK-568-5804-1-ND  DIODE ZENER 47V 500MW DO-35    20-07-2011
c13     DK-1N5229BFSCT-ND  DIODE ZENER 4.3V 500MW DO-35    03/11/2011
c13     DK-1N5227B-TPCT-ND  DIODE ZENER 500MW 3.6V DO35    03/11/2011
c13     DK-1N5239BFSCT-ND  DIODE ZENER 9.1V 500MW DO-35    03/11/2011
c13     DK-1N5242BFSCT-ND  DIODE ZENER 12V 500MW DO-35    03/11/2011
$

That took 10 milliseconds. No application launch, no internet access. There seem to be five different versions, one in box “c12”, the rest in box “c13”. All the parts are from DigiKey, and there’s the part number in there.

Note that locations are very coarse, it only mentions the box, not where inside the box the component can be found. That’s intentional. It’s no big deal rummaging through one little box to find the item, and this way we don’t need to track and type in any extra details. It also means we can put the item (i.e. the bag) back after use, and simply stick it in the front. Each box thus ends up ordered in LRU order. No muss, no fuss.

What if we need to find out more about one of those parts? Easy:

$ labby w DK-1N5229BFSCT-ND

And up pops a web browser window, with the full details:

Here’s how it’s done: there’s an area with text files, one per storage box, containing lines of tab-separated text: product-id, description, notes, date-added. The workhorse for searching is grep - it searches all these files and reports the matches, including the file name.

Everything is implemented as a simple shell script (did you know bash supports functions?):

#!/bin/bash
cd ~/Documents/JeeLabs/Supplies

usage() {
cat <<'EOF'
JeeLabs Lab Supplies
Usage:
  labby <text> - find the specified search text (case insensitive)
  labby w <id> - open web page for specified product id
  labby a <box> <id> - add information about an item to the specified box
EOF
}

openPage() {
  case "$1" in
    DK-*) s="http://www.digikey.nl/product-search/en?keywords=${1#DK-}" ;;
    EB-*) s="http://www.ebay.com/itm/$1" ;;
    FL-*) s="http://nl.farnell.com/jsp/search/productdetail.jsp?SKU=${1#FL-}" ;;
    MR-*) s="http://nl.mouser.com/ProductDetail/${1#MR-}" ;;
    # use DigiKey if there is no supplier prefix
    *)    s="http://www.digikey.nl/product-search/en?keywords=$1" ;;
  esac
  open $s  # opens a web browser window on Mac OSX, since $s is a URL
}

addItem() {
  case "$1" in
    "") echo "Usage: labby a <box> <supplier-partid> ?<optional-notes>?"
        return ;;
  esac
  if [ ! -f data/$1 ]; then
    echo "'$1' is not an existing box, you need to create it first as 'data/$1'"
    return
  fi
  case "$2" in
    DK-*) ;;
    *) echo "Please specify a supplier and part id, e.g. 'DK-1N5239BFSCT-ND'"
       return ;;
  esac
  echo "whoops, this feature is not working yet..."
}

case "$1" in
  "") usage ;;
  w)  openPage $2 ;;
  a)  addItem $2 $3 ;;
  *)  cd ./data; grep -i "$*" * | sed -e "s/	/  /g" -e "s/:/	/" ;;
esac

This first version was whipped up in an hour, and as you can see, it’s not complete. The most important missing feature is the ability to add more items. What we’d like is to supply only the box name (i.e. location) and the product id (including supplier prefix) - then this script should perform a web request to the supplier’s site to grab the description with curl or wget, and then massage the result a bit to append as one text line to the proper box file.

For the time being, new items will have to be added manually, using a text editor.

But hey: Instant Search ! - and perhaps just as important: instant tweaking as the need arises.

Sure - this could all have been implemented with a web server, MySQL or SQLite, and some programming language to tie it all together and render the results. But this is about finding information quickly, and coming up with a convenient workflow. And there - for several decades now - The Unix Way is still hard to beat. It’s a wonderfully malleable toolbox.

Weblog © Jean-Claude Wippler. Generated by Hugo.