ODOO POS RS232串口称重秤

4

我有一台由本地供应商制造的电子秤。它可以连接到我的PC的RS232串行端口,并且一直以来都运作良好。现在尝试将其与ODOO v8 POS一起使用,但是ODOO无法从该机器读取重量,而其他程序,包括Windows配件-->通信-->超级终端可以。

是ODOO不支持通过RS232读取电子秤的重量,还是我漏掉了什么?

2个回答

0

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


谢谢您的回答,我正在尝试在Odoo V11(CE)中探索它。您能否详细解释一下如何使用连接到我的POS计算机的称重秤?我的POS计算机未运行Odoo服务器,但是是Odoo客户端机器。 - Jayant
您连接设备的机器必须运行Odoo服务器,如“图像构建过程”部分所述。但是,使其工作的最简单方法是购买一个树莓派,它非常便宜,您可以在上面安装由Odoo制作的重建映像。 - switch87

0
Odoo IotBox允许将外部秤连接到Odoo。不幸的是,尽管基础架构已编码以便轻松实现额外的驱动程序,但只提供了两个协议的驱动程序(Mettled Toledo 8217和Adam AZExtra)。
如果您想编写自己的驱动程序,您需要研究您的秤协议,编写一个新的Python文件,并将其放在IotBox的驱动程序目录中(对于IotBox 21.10,路径为/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

上述代码的关键部分包括:
- 协议细节(波特率、数据位、停止位、奇偶校验) - 用于向秤写入、读取、归零的代码(measureCommand、zeroCommand、tareCommand) - 用于捕获响应的正则表达式(measureRegexp) - 函数“supported”将在odoo服务启动时调用,用于识别秤的型号。如果所有可用的识别方法都失败了(或者在IotBox的启动周期中秤被关闭),IotBox将将其标记为Adam AZExtra。
您可以查看https://github.com/ellery-it/odoo-serial-scale-drivers获取有关两个Kern秤的更多详细信息和示例。
免责声明:我是odoo-serial-scale-drivers github页面的所有者。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接