keller PAA-3XX/80794系列(绝压)压力传感器
一、瑞士 keller(科勒)壓力傳感器
keller英文版通訊協議百度網盤:提取碼:fusc
廣播模式:所有從機都會收到上位機信息
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.
只有單一從機收到:
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.
如下數據格式:
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校驗 低位 |
|---|---|---|---|---|
| DevAddr | 0 Function code | n byte parameters (optional) | CRC16_H | CRC16_L |
| FA | 49 | 01 | A1 | A7 |
· 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校驗 低位 |
|---|---|---|---|---|
| FA | 30 | 04 | 43 |
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校驗 低位 |
|---|---|---|---|---|
| FA | 49 | 01 | A1 | A7 |
返回數據格式為:
| 設備地址 | 方法代碼 | 方法參數 | CRC校驗 高位 | CRC校驗 低位 |
|---|---|---|---|---|
| FA | 49 | 01 | A1 | A7 |
1.3 方法總覽
| 方法代碼 | 16進制形式 | 功能描述(英文) | 功能描述(中文) |
|---|---|---|---|
| F3 | Read out the current pressure and temperature values in MODBUS format | ||
| F30 | 1e | Read out scaling values | 讀取最大值 |
| F31 | 1f | Write scaling values | |
| F32 | 20 | Read out configurations | 讀取配置 |
| F33 | 21 | Write cinfigurations | 寫入配置 |
| F48 | 30 | Initialise devices, whereby the device ID is returned | 初始化設備,返回設備ID,詢問鏈接 |
| F66 | 42 | Programm bus address | 總線地址 |
| F69 | 45 | Read out serial number | |
| F73 | 49 | Read out current pressure and temperature values in floating-point format | 讀取當前浮點型壓力、溫度數據 |
| F74 | 4a | Read out current pressure and temperature values in integer format | 讀取當前壓力溫度整形數據 |
| F95 | 5f | Zeroing functions | 歸零 |
| F100 | 64 | Read out configurations | 讀取配置 |
| F101 | 65 | Write configurations | 寫入配置 |
二、返回數據格式及解析
返回數據格式:
其中 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"]
三、更多
總結
以上是生活随笔為你收集整理的keller PAA-3XX/80794系列(绝压)压力传感器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学而思xPad2ProMax测评:价值不
- 下一篇: 目录扫描&&暴力破解网站