Previous “Sartorius” device profile renamed to “Sartorius (legacy)” and modified to set flow control to “RTS/CTS” automatically. This profile works with older Sartorius balances which require hardware flow control.
These improvements were possible thanks to the feedback from our customers.
For this article we assume that your scale is equipped with an interface and that it sends the date, time and weight in the following format:
Time 11:58:45 AM
Gross 376.5 g
We present two methods for transferring these values to Excel.
1. Use a keyboard simulation (virtual keyboard wedge)
You can use our software 232key to enter the values into Excel (or any other application) as if you had typed them on your keyboard. However, by default, 232key captures the first number in each line, which means it would only type the values shown in blue:
While the weight has been captured correctly, the date and time are incomplete. This can be fixed in 232key Plus as follows.
1. In the Input tab, set the device to “Barcode alphanumeric extended*:
This enables 232key to type all printable ASCII characters including the slash and colon we need for the date and time.
2. Modify the regular expression 232key uses to capture data by clicking on the Customize button. Replace the existing expression with the following one:
This expression will capture the date, time (in 12h AM/PM format) or weight. This only works if the values are transferred in individual lines, as in our example.
3. In the Output tab, instruct 232key to send “TAB” after the two first values and “Enter” after the third one:
232key will then write the date, time and weight in separate columns and jump to the next row:
2. Write the weight to a file (with date and time) and later open it in Excel
As an alternative to the “keyboard simulation” method described above, you can use our software Simple Data Logger (SDL) to write the weight to a file. This file can later be opened in Excel (or other applications).
This approach has two advantages:
Other keyboard operations can’t interfere with data acquisition and
Excel does not have to be open and running in the foreground (it does not even have to be installed on the same computer).
It is therefore particularly suitable for long-running unattended operations.
Concerning the date and time, you have two options when using SDL: Use the computer’s date and time or use the date and time sent by your scale.
a) Use the computer’s date and time
You’d usually choose this option if your scale only sends the weight or if the date and time format used by your scale does not match your requirements.
1. Choose a file in the Output tab in SDL. Click on the Set values button to set the default date and time formats (you can also directly modify the format strings, e.g. to use a 24h time format):
2. To make sure that only the weight is captured (and not the date and time sent from the scale), go to the Input tab, click on the Customize… button and add “\s*g” to the regular expression:
Now, only values expressed in grams [g] will be captured:
3. Even though they’re not captured, the other two lines sent from the scale (date and time) will still be written to the file as empty lines. In SDL Plus, we can combine all 3 lines into one row in the Process tab:
The CSV file generated by SDL can later be opened in Excel by simply double-clicking on it:
As mentioned above, the two empty columns preceding the weight appear due to the date and time values which were sent from the scale, but were not captured. You can simply delete them.
b) Using the date and time sent by your scale
The procedure is very similar to what we did with 232key above.
1. In the Input tab, set the device to “Generic text device” to prevent SDL from treating the captured values as numbers:
2. Replace the regular expression by clicking on the Customize… button:
Our free software 232key enables you to easily transfer the weight from your scale or balance to any application running on your PC (as simulated keystrokes). It contains a list of compatible devices that we are constantly expanding.
However, we cannot possibly test every scale or balance on the market. Using a practical example, this blog post will show you how to determine whether your balance is compatible with our software.
As of version 2018.1.0, the following requirements can be found on our 232key homepage (under “limitations”):
Data sent by your device has to be in ASCII format.
Your device has to send each line of data only once, not continuously (by pressing a key on the device or automatically).
These requirements may change in future version. We recommend that you always consult our 232key.com website first.
Step 1: Prerequisites
Scale or balance
You’ll need your scale, of course. For this example we used an Excell FD130 scale which we found among our samples:
At the time of the writing of this post, this scale did not have a predefined device profile in 232key.
It’s a good idea to try to find or download the user manual for your scale. As you’ll see below, you’ll most likely need it.
Your scale must be equipped with an interface which can be connected to a COM port on your PC (or appears as a COM port when connected). The FD130 has a DB25F port:
Cables and converters
We used a straight (1:1) DB25M to DE9F RS-232 cable with an FTDI US232R-10 converter plugged into a USB port on our PC:
Your scale will probably require a different cable. If you’re lucky, the user manual contains further information. We’ll address the topic of finding the right serial cable in an upcoming post (it can be quite complicated).
Caution: Some scales use interfaces for other things than transferring data (e.g. for relay outputs or as a way to supply power to peripherals). Connecting such a scale to your PC with an incompatible cable could damage both devices.
Before using an unlisted device with 232key, it’s a good idea to get it to work with a terminal program. Just like 232key, a terminal program requires that you make a few settings before connecting to your scale:
Flow control (handshaking)
Only one COM port was shown on PC (created when the FTDI converter was plugged in). If you have the choice between multiple ports, consult the Windows Device Manager to determine the correct one.
We found the following interface parameters in the user manual of our FD130 scale:
1200, 2400, 4800 or 9600 baud (no default value was specified)
8 data bits
1 stop bit
No flow control
To determine the correct baud rate, we accessed the scale’s RS-232 configuration (we couldn’t have done this without the user manual):
After all settings were made, we pressed the “Connect” button in HTerm and immediately saw a lot of data coming from the scale:
The data contained a stability and net weight indication, a polarity sign, the weight and the unit, then a carriage return and finally a line feed character:
Setting “Newline at” to “LF” in HTerm made things a bit clearer:
Concerning the requirements mentioned above, we confirmed that the data was sent in ASCII format. However, the scale was continuously sending 4 values per second, which is not suitable for use with 232key as all these values would be typed (you could, however, use it with our Simple Data Logger application).
We again consulted the manual and found that the setting could be changed from “rnP 2 – continuous transmission” to “rnP 4 – press the ⏎ key to transmit”. As the description says, in this mode the user has to press the ⏎ key on the scale to send the weight to the connected PC (once).
Another mode suitable for use with 232key was “rnP 1 – stable transmission”. In this mode, the scale sent each (stable) weight once. This is often referred to as “auto print on stability”.
Your scale may or may not have several different transmission modes. Please refer to your manual for further information. Unfortunately, there are some scales which only support continuous transmission and are therefore not suitable for use with 232key (at this time).
Tip: Check whether your scale has a print button. If so, it can probably be used with 232key.
If the output in the terminal program contains no human readable data, you’ll have to fix this before trying to use the scale with 232key. As an example, setting the baud rate in HTerm to a wrong value (e.g. 4800) resulted in the following output (with “Show errors” selected):
If you’ve confirmed that all interface parameters in HTerm match those of your scale and still can’t read the output, the scale might not be sending data using the ASCII format. If no ASCII mode is available, it cannot be used with 232key.
Other values than the weight
Instead of sending only the weight as shown on the display, some scales send a lot of data to the connected PC. Below you can see the output when we set our scale to a ticket format meant to be used with a printer (“rnP 6”):
If the data sent by your scale contains numbers other than the weight, they will also be captured and typed by 232key. This is usually not what you want.
There are two ways you can try to fix this:
Configure the scale. Refer to the manual to find out if it’s possible to change the output format to a more simple one that sends only the weight.
As we were able to read the output in HTerm and had fixed the continuous transmission issue, we proceeded to configure 232key for use with our Excell FD130 scale:We selected “generic measuring instrument” as the device and set the COM port and all interface parameters to the same values as in HTerm. As the terminator, we selected “LF”, the last character in each line of data sent by the scale (as seen above).
In the output tab, we instructed 232key to send an enter key after typing the weight (this is of course up to you and your application).
We then pressed the start button and switched to Word for testing purposes. By pressing the ⏎ key on the scale, the weight was typed by 232key:
Received data and captured/typed values could also be seen in the event log in 232key:
Our software 232key was originally designed to make it as easy as possible to capture the weight sent by a scale or balance (and then transmit it to another application as simulated keystrokes). As most weighing instruments also include the unit and possibly other characters, 232key assumes that the first (decimal) number it encounters is the weight. If you also want to capture the date and time sent from a scale, this can lead to unwanted results.
Capturing the net weight
Let’s look at a simple example first. Below you’ll see the data received from an Ohaus Scout STX scale configured to transmit only the net weight (as it appears in the event log in 232key):
Net: 302.4 g ? N<13><10>
The blue characters were captured by 232key using the “Ohaus” device profile. In this example, 232key managed to successfully capture the weight.
Capturing the net and tare weight
If we set the scale to send both the net and tare weight, the event log shows that 232key still captures both values:
Net: 302.4 g ? N<13><10>
Tare: 7.9 g T<13><10>
To have them appear in separate columns in spreadsheet applications like Excel, OpenOffice Calc or Google Sheets, we can go the output tab and modify the end with settings as shown below:
Alternating the “TAB” with the “Enter” key every 2 value will produce the desired result (shown in Google Sheets):
Capturing date and time
Things get significantly more complicated if we configure the scale to also send the date and time. The event log now looks as follows:
Net: 302.4 g N<13><10>
Tare: 7.9 g T<13><10>
Using its default strategy of capturing the first number in each line, 232key only captures “11” and ignores the rest of the combined date/time line (as the backslash cannot be a part of a decimal number).
We can try to fix this by going to the device tab and setting the device to “Barcode alphanumeric extended” (available in the Plus version). This device appears in italics, which means that it is a “text” device instead of a “numeric” device. Note: Do notclick the set defaults button after making this change.
As the scale is now sending three lines of data, we should also enter the number “3” in the end with settings in the output tab:
If we press the print button on the scale again, the event log will show that all data has been captured by 232key:
Net: 302.2 g N<13><10>
Tare: 7.9 g T<13><10>
The output in Google Sheets looks as follows:
If we simply wanted to record all data sent from the scale, this would be fine. However, it is not ideal for further processing for two reasons:
Date and time appear together in one column.
The measurement values are not recognized as numbers because the cells contain additional text.
232key does currently not support extracting multiple values from one line of data, so there’s nothing we can do about the first issue. Unfortunately, our Ohaus Scout STX scale cannot send the date and time in separate lines.
The second issue can be fixed using custom regular expressions. To do this, go to the device tab, click on the customize button and replace the existing regular expression with the following one:
Note: This regular expressions assumes the scale is using the 24 hour time format.
The event log and the output in the spreadsheet now look as follows:
15:38:40 11/17/2017 15:39:01<13><10>
15:38:40 Net: 302.2 g N<13><10>
15:38:40 Tare: 7.9 g T<13><10>
The cells containing the net and tare weights are recognized as numbers and can be used for further calculations.
If we just wanted to capture the time (and maybe add a “date” column manually), we could use the following regular expression:
The regular expressions above have been customized to work with the Ohaus Scout STX scale (configured to send the date, time and weight). They might not work with other scales and balances.
As we’re now using a “text” device, the computation and rounding settings in the process tab have been disabled (you can’t round non-numeric characters).
The option to change the decimal separator from a dot to a comma is also no longer available (and our custom regular expression does not capture decimal numbers using a comma as the separator).
For data logging purposes, consider using our new Simple Data Logger software instead of 232key. It has the ability to add the date and time to each weight. The CSV files it produces can be easily opened in Excel and other spreadsheet apps.
232key uses pre-defined regular expressions to match the data coming from the connected device and to capture the value you’re interested in. In this article, we’ll demonstrate the use of custom regular expressions (available in the paid Plus version) to capture the (net) weight from a balance and avoid capturing values we do not want to be typed. The instructions posted below can be applied to all kinds of serial devices (not only balances and scales).
When 232key captures too many values
For this example, we’ll be using an Adam Equipment HCB 3001 portable precision balance. It’s equipped with an RS-232 and USB interface. Either one works with 232key:
232key comes with a device profile for this balance. When you select it in the input tab and then press “Set defaults” to set the interface parameters, the following message appears:
This message asks you to modify the balance’s output format so that it only sends the (net) weight to the connected PC. If you change this setting, you won’t have to modify the regular expression in 232key as shown below. However, many other balances and scales have a fixed output format which cannot be modified (you can find multiple real-life example in our support forum). To simulate this problem, we’re keeping the balance set to output format 1 (default setting). As we’re about to see, this output format is not ideal for use with 232key.
In the output tab, we instruct 232key to press the enter key after typing the weight (clearly separating the captured values as they’re being typed):
If we now place an object on the balance, switch to an application like Notepad and press the print key, 232key types not just the weight, but 3 values, e.g.:
108.6 1 108.6
Weighing a second object leads to the following output:
83.0 2 191.6
A look at the event log in 232key reveals the problem with output format 1: The scale does not only send the weight over the interface, but also the number of accumulations and the total accumulated weight, each in a separate line. 232key captures and types all of these values (as it has no way of knowing which value you’re interested in). This is indicated by the characters in blue in the event log (note how they correspond to the output above):
Capturing the right value
To make sure that 232key only captures the weight from the first line and nothing else, we have to find out what makes this line unique. One candidate would be the unit (“g”), but unfortunately it also appears on the third line:
GS 108.6 g
Total. 108.6 g
However, only the first line starts with “GS” (which – according to the user manual – stands for “gross weight”). Therefore, we have to make sure that 232key only matches lines starting with “GS”. To do so, we go to the input tab and click on “Customize…”. This brings up a dialog which lets us modify the regular expression associated with this device:
The regular expression shown above captures the first (decimal) number it encounters. You don’t have to fully understand it, it’s sufficient to add “GS” in front of it to make sure 232key only matches lines where these characters appear before the desired value:
When weighing the same two objects again, 232key now only captures the weight from the data sent by the balance (as highlighted in blue in the event log):
In many cases, it’s really that easy to prevent 232key from capturing too many values. All you have to do is find out what makes the line containing the desired value(s) unique and modify the regular expression accordingly. However, as discussed below, sometimes things can get a bit more complicated.
White space and negative values
The space characters sent by the balance after “GS” are currently being matched by the “\s*” expression inside the parentheses. (“\s*” means “match a whitespace character between zero and unlimited times”):
If the balance were to send a negative value, the fact that “\s*” appears after “[-+]” in the regular expression could become a problem. This depends on the position of the minus sign in the data sent by the balance:
“GS– 108.6 g” would be matched,
“GS –108.6 g” would not.
If you encounter this kind of problem, add another “\s*” right after the characters you’ve added before:
The regular expression above instructs 232key to look for “GS” and white space characters (between zero and unlimited times) ahead of the weight (and ahead of a potential minus or plus sign). Do we need it for the Adam Highland balance used in this example? We can’t say, because unfortunately it refused to send (“print”) any negative weights at all. For the following examples, we’ll be reverting to our previous regular expression.
Alternations and capture groups
There’s something else we did not consider: Remember that “GS” stands for gross weight? What happens if we tare a container, place an object inside and then press the print key? 232key does not type anything! A look at the event log reveals that the scale sent “NT” for net weight instead of “GS”. As this does not match our regular expression, 232key ignores the entire line:
This can be fixed by using an alternation that matches either “GS” or “NT”:
However, testing this new expression shows that we’ve made things worse. Not only did 232key not type anything, the event log also contains several error messages:
We forgot to consider that 232key will always capture and process the data from the first capture group only. A capture group is marked by round parentheses and we’ve just inadvertently added a new one which captures either “GS” or “NT”. 232key then tried to convert these characters into a number, which obviously had to fail.
The solution is to mark it as a non-capturing group by adding “?:” as the first characters inside the parentheses. This means that the group is used for matching, but not for capturing data:
Testing this expression shows that 232key now works as expected and also captures the net weight:
This article describes how you can capture the weight from a weighing instrument with differentiated digits using 232key Plus.
What are differentiated digits (a.k.a. an “auxiliary indicating device”)?
When looking at the display of an approved class I or class II weighing instrument, you might notice that one or more digits are visually differentiated from the others:
This is supposed to remind the user that on these instruments, the actual scale interval (d) is a multiple of the verification scale interval (e). For the scale shown above, e is 0.1 g and d is 0.01 g. Since e is used to determine the maximum permissible error, we can consider the differentiated digit(s) to be less accurate (but that’s not the topic of this article).
How to use 232key to capture differentiated digits
Some scales do not only visually differentiate the last digit(s), they also use a separator when transmitting them to a PC (or a printer). Instead of receiving a string like “250.01”, the software running on the PC would receive something like “250.0/1” or maybe “250.0”.
As far as our virtual keyboard wedge software 232key is concerned, this additional separating character will prevent it from capturing the entire weight value. Instead, it would only capture “250.0” (highlighted in blue in 232key’s event log):
1. Modify the regular expression to ensure all required characters are captured
Let’s continue using “/” (slash) as a separator for this example. By default, most device profiles in 232key are meant to capture numbers and therefore 232key will stop capturing when it encounters the first non-numeric character. We have to change this behavior to make sure that 232key captures the digits preceding the separator, the separator itself and the following digit(s).
To do so, we first select the device profile we want to use (we’ll go with “Generic measurement instrument” in this example), and then click on the “Customize…” button to open the regular expression dialog:
The current regular expression captures the first number it encounters (which can be positive or negative and have a dot or comma as a decimal separator):
By expanding it as below we can instruct 232key to match a slash (“/”) and the following digits, too:
Depending on the selected device profile, the regular expression shown in the dialog might look different. What’s important is that it has to be expanded to include the separator and the differentiated digits.
2. Remove the separator
Thanks to the modified regular expression, 232key is now able to capture the entire value sent from the scale, including the separator. However, it would then either show a number format error (if we’ve selected a numeric device in the input tab) or type the data including the separator into the target application (if we’ve selected a text device). Both of these outcomes are not desirable.
Therefore, we also have to instruct 232key to remove the separator from the captured data by going to the “Process” tab and entering it in the “Remove” text field:
Once this second step is completed, 232key handles differentiated digits correctly: When the scale sends “250.0/1”, 232key types “250.01” into the target application (e.g. a spreadsheet):
Obviously, you might have to adapt these instructions to match the separator sent by your scale. As mentioned, you’ll also need a paid 232key Plus license to enable the functionality shown in this article. Please don’t hesitate to contact us should you need a trial license. For assistance, please email us or post in our support forum.