Fake Your Scales in Windows XP VM

So today I had a…

Login

Blog History

So today I had a task to find out if some legacy Weigh Bridge software would be capable of taking longer inputs for some field values

Being proprietary software the answer is no...

But in the process I had to fire up a Windows XP Virtual Machine and somehow convince the Weighbridge software that it was receiving input from a weighbridge.

So for my memory. The special sauce was

  • Using com0com which ties two virtual comm ports together with a virtual null modem connection
  • Configure the Weighbridge software to use one of the com0com ports
  • and then the other comm port is used to send fake Weighbridge data via the following perl script

So you have Weighbridge Software <==> COM5 <== virtual null modem cable ==> COM6 <== fakeScale.pl

# fakeScale.pl
# For Linux
#use Device::SerialPort;
#my $port = Device::SerialPort->new("/dev/ttyUSB3");

# For Windows. You only need one or the other.
# Uncomment these for Windows and comment out above
use Win32::SerialPort;
use Time::HiRes qw(usleep);
my $port = Win32::SerialPort->new("COM4");

$port->baudrate(4800); # Configure this to match your device
$port->databits(8);
$port->parity("none");
$port->stopbits(1);

while(1) {
    # 1 space after ' then three spaces after 2224 = 22.24t
    # keys commands for Toledo scale
    # <CTRL+B>4<SPACE><SINGLE QUOTE * 2><SPACE>
    # 2224 <SPACE * 3>000<CR><CTRL+C>
    $port->write("\cB4 \'\' 2224   000\r\cC");
    usleep (1500);
}

# never get here but keeping this in case 
# I need to read one day
while (1) {
    my $char = $port->lookfor();
    if ($char) {
        print "Received character: $char \n";
    }
    $port->lookclear; # needed to prevent blocking
    sleep (1);
}

# Writing to the serial port
# $port->write("This message going out over serial");

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.