我有一台由本地供应商制造的电子秤。它可以连接到我的PC的RS232串行端口,并且一直以来都运作良好。现在尝试将其与ODOO v8 POS一起使用,但是ODOO无法从该机器读取重量,而其他程序,包括Windows配件-->通信-->超级终端可以。
是ODOO不支持通过RS232读取电子秤的重量,还是我漏掉了什么?
我有一台由本地供应商制造的电子秤。它可以连接到我的PC的RS232串行端口,并且一直以来都运作良好。现在尝试将其与ODOO v8 POS一起使用,但是ODOO无法从该机器读取重量,而其他程序,包括Windows配件-->通信-->超级终端可以。
是ODOO不支持通过RS232读取电子秤的重量,还是我漏掉了什么?
Odoo pos使用邮筒(自v12起的Iot Box)模块与秤进行通信。这些模块被设计为安装在树莓派上,但也可以在您的POS计算机上使用。
我建议升级到较新版本的Odoo,因为仅支持最后3个版本,即10、11、12(以及所有子版本)。
在此处阅读有关posbox的更多信息: https://www.odoo.com/documentation/user/11.0/point_of_sale/overview/setup.html
/root_bypass_ramdisks/home/pi/odoo/addons/hw_drivers/iot_handlers/drivers/
)。from collections import namedtuple
import logging
import re
import serial
import threading
import time
from odoo import http
from odoo.addons.hw_drivers.controllers.proxy import proxy_drivers
from odoo.addons.hw_drivers.event_manager import event_manager
from odoo.addons.hw_drivers.iot_handlers.drivers.SerialBaseDriver import SerialDriver, SerialProtocol, serial_connection
from odoo.addons.hw_drivers.iot_handlers.drivers.SerialScaleDriver import ScaleDriver
_logger = logging.getLogger(__name__)
# Only needed to ensure compatibility with older versions of Odoo
ACTIVE_SCALE = None
new_weight_event = threading.Event()
ScaleProtocol = namedtuple('ScaleProtocol', SerialProtocol._fields + ('zeroCommand', 'tareCommand', 'clearCommand', 'autoResetWeight'))
KernDEProtocol = ScaleProtocol(
name='Kern DE test driver',
baudrate=9600,
bytesize=serial.EIGHTBITS,
stopbits=serial.STOPBITS_ONE,
parity=serial.PARITY_NONE,
timeout=1,
writeTimeout=1,
measureRegexp=b"^[\sM][\s-]\s*([0-9.]+)\skg",
statusRegexp=None,
commandDelay=0.2,
measureDelay=0.5,
newMeasureDelay=0.2,
commandTerminator=b'',
measureCommand=b'w',
zeroCommand=None,
tareCommand=b't',
clearCommand=None,
emptyAnswerValid=False,
autoResetWeight=False,
)
class KernDEDriver(ScaleDriver):
"""Driver for the Kern DE serial scale."""
_protocol = KernDEProtocol
def __init__(self, identifier, device):
super(KernDEDriver, self).__init__(identifier, device)
self.device_manufacturer = 'Kern'
@classmethod
def supported(cls, device):
"""Checks whether the device, which port info is passed as argument, is supported by the driver.
:param device: path to the device
:type device: str
:return: whether the device is supported by the driver
:rtype: bool
"""
protocol = cls._protocol
try:
with serial_connection(device['identifier'], protocol, is_probing=True) as connection:
_logger.info('Try... device %s with protocol %s' % (device, protocol.name))
connection.write(b'w' + protocol.commandTerminator)
time.sleep(protocol.commandDelay)
answer = connection.read(18)
_logger.info('Answer: [%s] from device %s with protocol %s' % (answer, device, protocol.name))
if answer.find(b' kg \r\n')!=-1:
_logger.info('OK %s with protocol %s' % (device, protocol.name))
return True
except serial.serialutil.SerialTimeoutException:
_logger.exception('Serial Timeout %s with protocol %s' % (device, protocol.name))
pass
except Exception:
_logger.exception('Error while probing %s with protocol %s' % (device, protocol.name))
return False