Reading from the 7010SB is really easy, its just plain serial at 2400 baud 8N1 no flow control. The scale spits out data every 1/10 second so you just need to listen for the latest weight.
There are two possible formats for the data, one for each measurement scale. The second byte indicates what scale you are in.
First | Last | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
Lbs/Oz. | 0x02 | 0x0B | 0x80 | 0x80 | lb1 | lb2 | lb3 | oz1 | oz2 | 0x0D |
Grams | 0x02 | 0x0C | 0x80 | 0x80 | g1 | g2 | g3 | g4 | g5 | 0x0D |
- STX character - Hex 0x02, indicates "Start of TeXt"
- Scale indicator - Hex 0xB0 for lb/oz and 0xC0 for grams
- Hex 0x80 (placeholder)
- Hex 0x80 (placeholder)
- First character of weight, ascii format
- Second character of weight, ascii format
- Third character of weight, ascii format
- Fourth character of weight, ascii format - single Ounces in Lb/Oz weight
- Fifth character of weight, ascii format - 1/10th Ounces in Lb/Oz weight
- Finishing carriage return - Hex 0x0D
For example, if we are weighing a box that is 1 lb 4.1 oz this is the output:
Note that the weight shows up in ascii character format (so its 0x31 0x34 0x31 not 0x01 0x04 0x01) If you need to convert to raw number, just subtract hex 0x30
Grams is a little simpler since its metric. It weighs about 390 grams.
You can see the 390 (385-395 g.) printed out. There is no fractional/decimals.
Code Examples for the 7010SB
We like to use python for its cross-platform compatibility. You'll need to install pySerial extension to access the serial port. Under windows the COM port will be whatever the USB adapter shows up as orCOM1 or COM2 if using the built-in ports. For Macs/Linux check under /dev/cu* or /dev/ttyusb* - or run dmesg after plugging in the adapter for hints about what the device is called.SERIALPORT = "COM1" # this uses pySerial found here http://pyserial.sourceforge.net/ # it currently exists for python 2.5 import serialser = serial.Serial(SERIALPORT, 2400, timeout=1) while True: while True:x = ser.read() if (ord(x) == 13): breakstart = ord(ser.read()) # this is always 2 if the scale is on (i think - not totally sure what this is) mode = ord(ser.read()) # 176 = oz/lbs #192 = grams nonce1 = ord(ser.read()) nonce2 = ord(ser.read()) if start != 2 or nonce1 != 128 or nonce2 != 128: continue value0 = int(ser.read()) # only used for lbs * 10 value1 = int(ser.read()) value2 = int(ser.read()) value3 = int(ser.read()) value4 = int(ser.read()) if mode == 176: #oz weight = ((value0 * 10 + value1) * 16) + (value2 * 10 + value3) + (value4 * 0.1) unit = 'oz' elif mode == 192: #grams weight = value1 * 1000 + value2 * 100 + value3 * 10 + value4 unit = 'g' print str(weight) + unit ser.close(
Text editor powered by tinymce.