Monday 15 January 2018

Linux Driver for Ultraship U2 Scales

We use MyWeigh Ultraship U2 postal scales in our warehouse. They have given excellent service, and this is in no small part due to the USB connectivity they offer.

As no drivers were available for Ubuntu Linux, we developed our own. We're happy to share our code here, but cannot provide full installation instructions.

CAUTION: We purchased a second set of Ultraship scales, but found the USB connection was fundamentally different to the scales we already had. Our driver only works with scales having a device signature of 04D9:E002.

Overview

We setup the scales with a UDEV rule, then use a PERL driver to read the scales and simulate keypresses using xautomation. We simply add the PERL driver as a start up application in Unity. There may be some issues if multiple users are logged in simultaneously, but this is not a scenario we needed to cater for.

The Driver


Pre-requisites

$ sudo apt-get install xautomation

/etc/udev/rules.d/90_ultraship.rules

SUBSYSTEM=="hidraw", DEVPATH=="*04D9:E002*", SYMLINK+="ultraship", MODE="0666"

/ultraship/driver.pl

#!/usr/bin/perl

use Time::HiRes qw(gettimeofday);
$t=gettimeofday;

$xte = `which xte`;
$xte =~ s/\n//g;
if (!$xte) { die "This script requires xautomation to run"; }

while () {
 if (open(my $scales,'<','/dev/ultraship')) {
  while (read $scales,$rawdata,8) {
   $time_gap=gettimeofday-$t;
   if ($time_gap>0.3) { # prevents double send
    if ($rawdata=~'^([+|-])(\s+)(\d+)$') {
     $weight=$3.$g;
    } else {
     $weight="SET SCALE TO GRAMS";
    }
    system($xte.' "str '.$weight.'"');
    system($xte.' "key Return"'); 
   }
   $t=gettimeofday;
  }
 } else {
  sleep 3;
 }
 close $scales;
}

exit;

start up command 

perl /ultraship/driver.pl

alternative start up command

perl /ultraship/driver.pl -g