Reading the weight from an Ohaus Defender 5000 scale with PHP

Defender 5000 scales can be equipped with a WiFi or wired Ethernet interface. The scale acts as a TCP server and your script establishes a connection as a TCP client. You can then use one of the supported commands to request the weight or simply wait for the scale to send the weight (e.g. when the operator presses the print button).

You can easily test this by using PuTTY in “raw” mode and connecting to the scale:

PuTTY raw tcp connection
The WiFi dongle uses port 6060 (wired Ethernet: port 9761), the IP address is assigned via DHCP by default.
Defender 5000 scale: weight in PuTTY
IP (immediate print) command used to request the weight and reply sent by the scale (N: net weight, G: gross weight, T: tare weight).

Using PHP to communicate with the scale

For demonstration purposes, I’ve adapted example #2 (simple TCP/IP client) from the official documentation:

<?php
error_reporting(E_ALL);

echo "TCP/IP Connection\n";

/* Ohaus Defender 5000 WLAN interface uses port 6060 by default, Ethernet interface uses port 9761 */
$service_port = 6060;

/* IP address of the scale, can be displayed/set in the menu */
$address = "192.168.0.195";

/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
    echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
    echo "OK.\n";
}

echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
    echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
    echo "OK.\n";
}

$in = "IP\r\n"; //IP command (Immediate Print) - supported commands depend on the manufacturer, model and LFT settings
$out = '';

echo "Sending command...";
socket_write($socket, $in, strlen($in));
echo "OK.\n";

echo "Reading response:\n\n";
while ($out = socket_read($socket, 2048)) {
    echo $out;
}

echo "Closing socket...";
socket_close($socket);
echo "OK.\n\n";

It produced the following output:

Defender 5000 weight requested with PHP

You can modify the output template through the menu of the scale or by using the Ohaus Scale Mate software, e.g. to send just the net weight and date/time:

Ohaus Defender 5000 custom template

You’ll find a list of commands supported by the scale in the user manual. In the script, I used the IP (immediate print) command, which tells the scale to send the weight immediately (whether it is stable or not). This command is available on all newer Ohaus scales. One notable exception are legal-for-trade (LFT) models, which only support the P command (similar to pressing the print button) and in some cases the SP command (stable print, send weight as soon as it has stabilized). The Defender 5000 also supports many MT-SICS commands (which is the closest thing to a communication standard that the weighing industry currently has).

Please note that I’m not a PHP expert and that this is not a recommendation to use PHP. It is only supposed to be a very basic demonstration (as a potential customer asked me if it was possible to use PHP to communicate with the scale). Other programming languages such a C#, Java, JavaScript or Python may be more suitable. I’m frankly not even sure why the script works the way it does, as I would have expected it to fill the buffer (2048 bytes) before outputting any received data.


The header photo shows a Defender 5000 communication test case (a hard case with a built-in Defender 5000 indicator with all optional communication interfaces installed).

Using Ohaus Defender 5000 scales with BarTender

BarTender from Seagull Scientific is “the world’s leading design and print software for labels, barcodes, cards and RFID tags.” In this article, I’ll show you how to capture the net weight and tare weight from an Ohaus Defender 5000 scale with BarTender.

Notes:

  • This guide applies to the new generation of Ohaus Defender 5000 scales (2018 or later).
  • It was created using BarTender 2019 R8 and version 1.05 of the Ohaus Defender 5000 firmware. It may not apply to future versions.
  • I’m not a BarTender expert, if you think that you have a better solution, please let me know in the comments.

BarTender communicates with a scale by requesting the weight and – if supported – the tare weight in short intervals (every 250 ms by default). The received data is then parsed using regular expressions.

Unfortunately, the “Ohaus” protocols defined in BarTender do not work with the default settings of the current Defender 5000 scales. They also don’t support requesting the tare weight. Therefore, we’ll use the MT-SICS protocol instead. As you’ll see below, this is a very straightforward solution. However, for a limited number of multi-interval Defender 5000 scales, we’ll need to modify the regular expressions used by BarTender.

Note for legal-for-trade applications (verified scales): If you’re planning to use the alibi memory (SD card) installed in the Defender 5000 indicator, please note that the solution proposed here does not create alibi records. To do so, you would have to use the Ohaus “P” (print) command instead of the MT-SICS command to request the weight. However, this would create an alibi entry every 250 ms, which is probably not what you want either. In my opinion, the communication method used by BarTender is not well suited for use with verified scales and alibi records.

Configuring your Ohaus Defender 5000 scale

Note: This guide assumes that you’ve already connected your scale to your PC. I used the standard RS-232 port found on all current Defender 5000 models. Using the optionally available USB or Bluetooth interface (SPP) would be almost identical.

Apparently, you do not need to change the configuration of the scale, as it already supports MT-SICS commands in its default “Demand” mode. However, if you want to explicitly set it to the MT-SICS protocol, press and hold the Menu button, then press 7 to enter the Communication menu, select the interface you’re using, press 2 for Setup and then change the Assignment from “Demand” to “SICS”:
Ohaus Defender 5000 scale SICS

The other settings on this screen should not matter, as they’re irrelevant for the selected protocol.

Configuring BarTender

Add Scale Wizard Step 1

Start Bartender Designer, select Administer>Weighing Scale Setup and Add Scale. This will launch the Add Scale Wizard. Click on Next.

BarTender Add Scale Wizard 1

As mentioned, simply selecting “Ohaus 5000 Series” (or any other Ohaus model) will not work with the current Defender 5000 scales. Instead, select Define a model not listed above and click on Next.

Add Scale Wizard Step 2

BarTender Add Scale Wizard 2Select “Ohaus” as the manufacturer and enter a model name (e.g. “Defender 5000 SICS”).

If your scale is a single interval scale (which means that the readability does not change over the entire weighing range), select the “Mettler Toledo (MT-SICS Level 1)” protocol and click on Next. Then skip to step 3 of this guide far below.

If your scale is a multi-interval scale, things may get a bit more complicated. It all depends on the readability (aka “graduation”, “d” or “e”) of your scale. If it has the same number of decimal places over all intervals when using the default unit (kg), you can also go to step 3. If the number of decimal places is not the same, continue reading here.

Example:

Ohaus Defender 5000 scale dual interval
0.005 kg = 3 decimals, 0.01 kg = 2 decimals

Creating a new protocol

For multi-interval scales that don’t have a constant number of decimal places, we have to make a tiny change to the regular expressions defined in BarTender’s MT-SICS Level 1 protocol. Since we can’t modify existing protocols, click on New to create a new one.

BarTender Add Scale Wizard 3

Give the new protocol a name (e.g. “SICS”) and click on Copy existing Protocol.

BarTender Add Scale Wizard 4Select “Mettler Toledo (MT-SICS Level 1)” and confirm with OK. All fields for the commands and response patterns should now be filled in.

BarTender Add Scale Wizard 5

In every single response pattern except for the last one, locate the following string:

\x20(?<Units>

Change it to:

\x20+(?<Units>

By adding a plus sign, the regular expression now matches strings which contain one or more spaces (\x20) in between the weight (or tare) value and the unit. This is necessary because some multi-interval Defender 5000 scales use two spaces after switching to the second interval:

RegexBuddy weight values with defaul MT-SICS regex

Note how the second line contains two spaces after “22.25”. With the default regular expression defined in BarTender, this weight value (and all others in the same interval) would not be captured.

I don’t know if BarTender was too strict or if Ohaus was too lax in implementing the MT-SICS protocol. I believe it’s better if I don’t comment on this any further. According to the MT-SICS protocol documents I’ve reviewed, the weight should be right-aligned and separated from the unit with one space character. However, the descriptions of MT “DeltaRange” multi-interval balances mention that the last digit is replaced by a space when the number of decimal places changes:

mt-sics
Source (PDF)

Therefore, it seems that Ohaus did nothing wrong and the regular expression in BarTender did not account for this scenario.

Note: If you’re regularly dealing with regular expression, I highly recommend the wonderful RegexBuddy software.

Your user-defined protocol should now look like this:
BarTender: Add scale wizard 6Click on OK.

BarTender Add Scale Wizard 7

Select the protocol we’ve just defined and click on Next.

BarTender Add Scale Wizard 8Everything in this dialog should be correctly configured for the use of a serial port (RS-232, USB or Bluetooth SPP). Click on Next.

Add Scale Wizard Step 3

BarTender Add Scale Wizard 9

Welcome back, my lucky readers who did not have to deal with protocols and regular expressions. Change the name of the scale if you feel like it and then click on Next.

BarTender Add Scale Wizard 10

In this dialog, you must specify the COM port on your computer that is used to connect to your Ohaus Defender 5000 scale.

BarTender Add Scale Wizard 11

This is it! We’re done! Click on Finish, but don’t bring out the champagne just yet.

Testing your Ohaus Defender 5000 scale

Bartender weigh scale setup

Back in the Weighing Scale Setup, select the scale you’ve just added and click on Properties.

BarTender weighing scale setup properties

Click on Test Connection. If everything is correct, BarTender should show the Net Weight and Tare Weight received from your scale:

BarTender Weighing Scale Connection TestIn that case, congratulations, you succeeded. You can now use the values from your scale in BarTender.

Should you not see any weight values, you’ll find some troubleshooting information below.

Troubleshooting a scale connection

Unfortunately, communication problems with scales can have many causes and are often difficult to solve. I can’t give you extensive troubleshooting instructions here, but I’ll tell you the same thing I also tell our software users: Download HTerm, a simple terminal program. Then try to communicate with your scale using HTerm instead of BarTender:

HTERM used for scale troubleshooting (MT-SICS protocol)

Change the following settings in HTerm:

  • COM port,
  • Baud to 9600,
  • Newline at to “CR+LF” (optional, looks nicer),
  • Send on enter to “CR-LF” (required).

Click on the Connect button at the top (shown as Disconnect in the screenshot as I had already clicked on it). Then type the “SI” (send immediately) command manually into the input field (lower red arrow) and press enter.

You should see the command you just sent under Transmitted data and the reply from the scale under Received Data (marked green on the screenshot).

If communication is successful with HTerm but not with BarTender, the problem is with BarTender. If you’ve changed the regular expression as described above, double-check that you’ve not made any mistakes. Contact Seagull Scientific for further support. Please don’t ask me for help in the comments.

If you can’t communicate with your Defender 5000 scale using HTerm, something is wrong with your setup. In my experience, the most likely culprits are:

  • Wrong COM port.
  • Wrong interface parameters (baud rate, etc.).
  • Wrong type of serial cable.

Please understand that I cannot diagnose these problems for you remotely. You may want to contact your Ohaus dealer or pay a specialist to help you.


Did this article save you a lot of time? Please consider supporting my work by buying a PDF version for US$2/copy (contains no additional information).


Last updated on August 14, 2020: Added information concerning the MT-SICS response format.

Which compact platform scale is the thinnest?

This article is based on an actual question asked by a potential customer*:

In the technical data of the Kern DE scale the dimensions are given as follows: 318 x 308 x 75 mm. I would like to know how high the scale is when it is standing on a straight surface, i.e. whether anything needs to be added to the 75 mm height.

Although I was not quite sure what the last sentence meant, I took the opportunity to confirm the height of the base of this scale. The Kern DE 60K10D I measured was around 77 mm high:

Kern DE scale base height

This is not much, but we sell an even thinner compact platform scale: The smallest scales in the Ohaus Catapult 5000 series are specified as 310 x 270 x 40 mm. The C51XE30R I measured was only around 42 to 43 mm thick:

Ohaus Catapult 5000 scale base height

While the base of the R-series Ohaus Catapult 5000 models is super slim, please note that the indicator is relatively bulky and that the stainless steel platform is not removable:

Ohaus Catapult 5000 R scale

Another option would be the simpler Ohaus SD scales, which are also around 42 mm high (most compact models).

Thin scales can be advantageous if you plan to integrate them into a packing table (or other type of furniture), but keep in mind that they may not be as robust and serviceable as larger platform scales.

Links to the manufacturers’ websites:


* I mentioned this so you don’t think I’m getting bored during the lockdown and just going around and measuring things.

Despite Coronavirus: Rapid delivery of a verified scale to a hospital pharmacy

Thanks to the good cooperation between our company, the scale manufacturer Ohaus, UPS and DB Schenker, our customer received a verified class III scale with a 50 × 50 cm platform and  a capacity of 60 kg only 4 working days after placing the order.

Scales of this type are individually adjusted to the gravity at the place of use during initial verification. The customer can immediately use the scale for the purposes listed in directive 2014/31/EU (article 1).

New 2019 Ohaus Navigator scales

The new Ohaus Navigator series consists of a total of 18 scales (incl. 4 LFT models) with a maximum capacity from 220g up to 22kg and a readability starting at 0.01g. As usual in this segment, all scales use load cells with strain gages.

ScaleCapacity [g]Readability [g]
NV2222200.01
NV4224200.01
NV6226200.01
NV2212200.1
NV6216200.1
NV120112000.1
NVT220122000.1
NVT620162000.1
NVT220022201
NVT620062001
NVT12000120001
NVT22000220001
LFT scaleCapacity [g]Readability [g]
NVT1601M16001
NVT3200M32002
NVT6400M64005

Note: Available models and characteristics may differ depending on your region. This article refers to scales available in Europe as of May 2019.

Differences to the previous Navigator scales

The NVL series (Navigator XL) with its unusual elongated shape is no longer available:

Phased out Ohaus Navigator scales
From left to right: Old Navigator XT scale (NVT), old Navigator XL scale (NVL), old Navigator scale (NV)

On all new scales, the upper side of the housing is now white, and the red display framing is more discreet. Another difference is the even higher contrast of the display:

Old vs. new Ohaus Navigator scales
Old NVT scale (left) and new NVT scale (right)

The touchless IR sensor has been removed from all scales except the LFT models.

Interface options and accessories continue to be available

Numerous interface options are available, making these scales particularly interesting for data transfer to a computer: RS-232, USB device (virtual COM port) and Ethernet.

Ohaus Navigator scale with optional USB interface installed
Ohaus Navigator scale with optional USB interface installed

You can easily use the scales with the free Serial Port Data Collection (SPDC) software available from Ohaus as well as with our 232key keyboard wedge and Simple Data Logger software:

Ohaus Navigator device profile in Simple Data Logger
Ohaus Navigator device profile in Simple Data Logger (SDL)

As standard, all scales are supplied with a plug-in power supply and can alternatively be operated with batteries. An optional lead battery is also available for the larger NVT models.

A carrying case is available to make the scales even more portable:

Ohaus Navigator 30467963 carrying case
Ohaus Navigator carrying case (30467963)

Further information on the new 2019 Ohaus Navigator scales


Note: The photos for this article were not provided by the manufacturer. If you would like to use them on your website or in other publications, please contact us to acquire a license.