I have a Mettler Toledo Ariva-S scale connected in COM port-> USB port on a raspberry pi.
I’ve configured the Mettler Toledo scale to use the Dialog 06 protocol.
I’m coding in python and I’m trying to get the weight from the scale but I’m not succeeding. The scale only replies b”.
The scale is connected to the raspberry’s /dev/ttyUSB0 serial port.
pi@raspberrypi:~ $ find -L /dev/serial/by-path/ -samefile /dev/ttyUSB0
/dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-port0
The principle of the Dialog 06 protocol is to send the unit price of the product weighed, as well as any tare values, directly to the scale.
The scale returns the measured weight and the final price of the product weighed (minus the tare).
This eliminates the need for price manipulations to remove the tare at a later stage, once the weight has been recovered.
In my code, I only try to send the unit price of the product to the scale, but I get no response.
I don’t understand at all why the scale doesn’t answer me.
Does anyone have any idea what I’m doing wrong?
Here’s my code:
import serial
port_config = {
baudrate': 9600,
bytesize': 7,
stopbits': 1,
parity': 'O',
timeout': 1
writeTimeout': 1
}
path = '/dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-port0'
# --------------------------------------------------------
# Establishing the connection with the scale
# --------------------------------------------------------
connection = serial.Serial(path, port_config)
_logger.info("Connection dict : {}".format(connection.__dict__))
Logs
Connection dict = {‘is_open’: True, ‘portstr’: ‘/dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-port0’, ‘name’: ‘/dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-port0’, ‘_port’: ‘/dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-port0’, ‘_baudrate’: 9600, ‘_bytesize’: 7, ‘_parity’: ‘O’, ‘_stopbits’: 1, ‘_timeout’: 1, ‘_write_timeout’: 1, ‘_xonxoff’: False, ‘_rtscts’: False, ‘_dsrdtr’: False, ‘_inter_byte_timeout’: None, ‘_rs485_mode’: None, ‘_rts_state’: True, ‘_dtr_state’: True, ‘_break_state’: False, ‘_exclusive’: None, ‘fd’: 13, ‘pipe_abort_read_r’: 14, ‘pipe_abort_read_w’: 15, ‘pipe_abort_write_r’: 16, ‘pipe_abort_write_w’: 17}
# --------------------------------------------------------
# Ask the scale weight with the unit price
# --------------------------------------------------------
unit_price = "001000"
message_to_send = "{}{}{}{}{}{}".format(protocol.eot_stx,protocol.record_01,protocol.esc,unit_price,protocol.esc,protocol.etx).encode("utf-8")
# EOT = End of Transmission = x04
# STX = Start of Text = x02
# ESC = Escape = x1B
# ETX = End of Text = x03
# RECORD_01 = 01
# COMMNAND_DELAY = 0.2
# {x04x02}{RECORD_01}{x1B}{unit_price}{x1B}{x03}
connection.write(message_to_send)
_logger.info("message_to_send : {}".format(message_to_send))
Logs
message_to_send : b’x04x0201x1b001000x1bx03′
# --------------------------------------------------------
# Get the scale response
# --------------------------------------------------------
time.sleep(protocol.commandDelay)
answer = []
while True:
char = connection.read(1)
if not char:
break
else:
answer.append(bytes(char))
response = b''.join(answer)
_logger.info("answer : {}".format(response))
Logs
answer : b”
I’ve never tried to code message exchanges with a scale so I guess I’m doing something wrong but I can’t put my finger on the problem at all.
I used the Ariva-S documentation (pages 17-19) to configure the scale, and descriptive document for the Dialog 06 protocol to code the message exchange in python.
I thank in advance anyone who can help me or point me in the right direction.