keller PAA-3XX/80794系列(绝压)压力传感器

一、瑞士 keller(科勒)压力传感器
  1. 广播模式:所有从机都会收到上位机信息
    Broadcasting This mode of communication enables the master to transmit a message to all slaves
    simultaneously. The master does not receive a reply, however, and is thus unable to check
    whether the message has been correctly received by every slave.

  2. 只有单一从机收到:
    Data interchange This mode of communication enables the master to communicate with a single slave. This
    normally involves the transmission of two messages: the master transmits a request and
    the slave responds to this request. Only the master is permitted to request a response. The
    request is received by every slave, but only the selected slave responds. The response
    must be received within a stipulated time, otherwise the master will assess the attempt as
    failed and must transmit the request again.

  3. 如下数据格式:
    The data are transmitted serially via the bus. The following format applies:
    1 start bit
    8 data bits (the least significant bit first)
    1 stop bit
    The parity bit can be set for devices of Class.Group = 5.20
    9600 baud or 115’200 Baud (only with devices of Class.GrouThis results in 10 bits (11 bits with active parity bit) per transmission byte.

一、构建命令
  • 命令字符串格式:

Note on the presentation of messages: Each box presents 1 data byte consisting of 8 bits, unless otherwise stated.
Each message sent by the master possesses the following format:

设备地址方法代码方法参数CRC校验 高位CRC校验 低位
DevAddr0 Function coden byte parameters (optional)CRC16_HCRC16_L
FA4901A1A7

· DevAddr: Address of the device.
Address 0 is reserved for broadcasting.
Addresses 1...249 can be used for bus mode.
Address 250 is transparent and reserved for non-bus mode. Every device can be contacted with this address.
Addresses 251...255 are reserved for subsequent developments.
· Function code: Function number
A function is selected and executed by the device via the function number. The function number is encoded in 7 bits. Bit 7 is
always 0. The functions are described further below.
· Parameters:
The parameters required by the function (n = 0 .. 6, according to function)
· CRC16: 16-bit checksum
These two check bytes serve to verify the integrity of the received data. If an error is established, the entire message will be
discarded. The principle employed for CRC16 calculation is described in the appendix. The CRC16 standard is applied here.
Note: The length of a message from the master is at least 4 bytes.

1.1 初始化设备-询问链接状态命令

每一个方法参数有 0-6 可选,类似modbus协议

Function:48 (16进制为:30)
F48: Initialise devices, whereby the device ID is returned
命令:FA 30 04 43

设备地址方法代码方法参数CRC校验 高位CRC校验 低位
FA300443
1.2 查询浮点型压力、温度命令

Function:73 (16进制为:49)
F73: Read out current pressure and temperature values in floating-point format
命令:FA 49 01 A1 A7
(还有其他方法根据自己所需数据自己去协议找)

设备地址方法代码方法参数CRC校验 高位CRC校验 低位
FA4901A1A7

返回数据格式为:

1226829-20190522222306025-607947802.png

设备地址方法代码方法参数CRC校验 高位CRC校验 低位
FA4901A1A7
1.3 方法总览
方法代码16进制形式功能描述(英文)功能描述(中文)
F3Read out the current pressure and temperature values in MODBUS format
F301eRead out scaling values读取最大值
F311fWrite scaling values
F3220Read out configurations读取配置
F3321Write cinfigurations写入配置
F4830Initialise devices, whereby the device ID is returned初始化设备,返回设备ID,询问链接
F6642Programm bus address总线地址
F6945Read out serial number
F7349Read out current pressure and temperature values in floating-point format读取当前浮点型压力、温度数据
F744aRead out current pressure and temperature values in integer format读取当前压力温度整形数据
F955fZeroing functions归零
F10064Read out configurations读取配置
F10165Write configurations写入配置
二、返回数据格式及解析
  • 返回数据格式:
    1226829-20190522222811845-1958976598.png

其中 B3、B2、B1、B0 一个八个十六进制字符,48 = 32 位,按照IEEE754规则表示的浮点数
其中第0位符号位S:1-9 一共8位(bytes)阶码E 9-32 一共23位表示尾数M 小数位 如:0.xxxxxx
整数位默认省略1,所以最后计算需要(-1)S
(1+M)*2E-127

遵循IEEE754 浮点数定义:
IEEE754转化浮点数

  • python 现成代码:楼主自己项目里面使用的
    def parsePressure(pressure):
        """
        压力数据格式为:FA 49 B3 B2 B1 B0 STAT CRC16_H CRC16_L
        FA 49 3F 81 61 ee 00 11 6f
        解析返回压力,统一返回千帕-kpa,保留7位小数
        0:KPA | 1: MPA | 3 PA | 5 bar
        :param pressure:
        :return:
        """
        UNIT = {
            "KPa": 1,
            "MPa": 1000,
            "Pa": 0.001,
            "Bar": 100
        }
        pressure16 = pressure[4:12]
        binAll = str(bin(int(pressure16, 16)))[2:]
        # binAll = binAll[2:]
        data = [x for x in binAll[:-24:-1]]
        data.reverse()
        binE = binAll[:-23]
        E = int(binE, 2) - 127
        total = 1
        for i, v in enumerate(data):
            total = total + int(v) * (2 ** -(i + 1))
        pressure = total*(2**E)
        return pressure*UNIT["Bar"]
串口模块

SeriaPort 类为继承serial 模块复写write/read 方法,(pip install pyserial)

from Lib.SerialPort import *
import time
import os
import threading
import binascii
import re


class PressureSensor(object):
    """
    压力传感器型号为:keller  PAA-3XX/80794(绝压)
    协议类型: KELLER protoco (类MODBUS 协议)
    Each message sent by the master possesses the following format:
    DevAddr | 0 Function code | n byte parameters (optional) |CRC16_H CRC16_L
    """
    def __init__(self,com='COM14' ):
        self.seria = SerialPort(com,9600)
        self.last_str = "FA493F8161ee00116f"
        print('PressureSensor初始化成功')

    def readPressure(self):
        self.seria.Write(bytes.fromhex("FA 49 01 A1 A7"))
        pressurestr = str(binascii.b2a_hex(self.seria.Read()).decode())
        self.last_str = pressurestr if pressurestr != '' else self.last_str
        return self.parsePressure(self.last_str)

    def parsePressure(self, pressure):
        """
        压力数据格式为:FA 49 B3 B2 B1 B0 STAT CRC16_H CRC16_L
        FA 49 3F 81 61 ee 00 11 6f
        解析返回压力,统一返回千帕-kpa,保留7位小数
        0:KPA | 1: MPA | 3 PA | 5 bar
        :param pressure:
        :return:
        """
        UNIT = {
            "KPa": 1,
            "MPa": 1000,
            "Pa": 0.001,
            "Bar": 100
        }
        pressure16 = pressure[4:12]
        binAll = str(bin(int(pressure16, 16)))[2:]
        # binAll = binAll[2:]
        data = [x for x in binAll[:-24:-1]]
        data.reverse()
        binE = binAll[:-23]
        E = int(binE, 2) - 127
        total = 1
        for i, v in enumerate(data):
            total = total + int(v) * (2 ** -(i + 1))
        pressure = total*(2**E)
        return pressure*UNIT["Bar"]
三、更多

1226829-20190522231641693-1291015172.png

1226829-20190522231659212-847573449.png

1226829-20190522231827681-1891805071.png

转载于:https://www.cnblogs.com/shiqi17/p/10909097.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值