1.0.27 • Published 2 months ago
@hot_stove/serial_port v1.0.27
充电桩自检的串口组件
注意事项
- 必须要在带有 HTTPS 协议的环境下运行;
安装方法
npm install @hot_stove/serial_port
更新组件版本
npm update @hot_stove/serial_port
使用示例
主流程示例:
import {SerialPortTool, Protocol, EnteringProductionModeCommand, EnteringProductionModeAnswer} from "@hot_stove/serial_port";
let tool = new SerialPortTool(9600)
// 打开串口
let open_result = await tool.open()
// 打开串口成功
if (open_result === true) {
// 注册接收数据回调事件
tool.on_message(function (msg) {
console.log('接收到数据', msg)
// 接收到数据时的操作 ...
})
// 注册串口关闭事件
tool.on_close(function () {
console.log('串口关闭')
// 串口关闭时的操作 ...
})
// 开启读取循环
tool.start_read_loop()
// 发送进入生产模式
let body = new EnteringProductionModeCommand()
let send_result = tool.send(body)
}
协议列表
- 进入生产模式指令
- 进入生产模式应答
- 开启自检指令
- 开启自检应答
- 上报自检状态
- 上报自检结果
- 配置控制板序列号和桩号指令
- 配置控制板序列号和桩号应答
- 开启充电指令
- 开启充电应答
- 配置功率指令
- 配置功率应答
- 停止充电指令
- 停止充电应答
- 上报监测数据
- 上报交易记录
- 交易记录确认
- 更新余额指令
- 更新余额应答
- 设置费率指令
- 设置费率应答
- 对时设置指令
- 对时设置应答
各个消息包的示例
进入生产模式指令示例
// 发送进入胜场模式指令
import {EnteringProductionModeCommand} from "@hot_stove/serial_port";
let send_result = tool.send(new EnteringProductionModeCommand())
if (send_result) {
// 发送成功
} else {
// 发送失败
}
进入生产模式应答示例
import {EnteringProductionModeAnswer, Protocol, ProtocolType} from "@hot_stove/serial_port";
tool.on_message(function (msg) {
if (msg.type === ProtocolType.EnteringProductionModeAnswer) {
// 芯片ID | 类型: string | 示例值: 667ff5004949894887022825
console.log(msg.chip_id)
}
})
开启自检指令示例
import {StartSelfCheckCommand, Protocol, ProtocolType} from "@hot_stove/serial_port";
let self_check_items = 0
// 需要打开的检测项(不需要打开注释掉对应检测项即可)
self_check_items |= (1 << 0) // 4G模块通信检测
self_check_items |= (1 << 1) // 1枪BL0939模块通信检测
self_check_items |= (1 << 2) // 2枪BL0939模块通信检测
self_check_items |= (1 << 3) // PLC模块通信检测
self_check_items |= (1 << 4) // 3.3V电压检测
self_check_items |= (1 << 5) // 12V电压检测
self_check_items |= (1 << 6) // 配置文件检测
self_check_items |= (1 << 7) // rfid_scanner检测
self_check_items |= (1 << 8) // led灯检测
self_check_items |= (1 << 9) // 温度传感器检测
let command = new StartSelfCheckCommand(self_check_items)
let send_result = tool.send(command)
if (send_result) {
// 发送成功
} else {
// 发送失败
}
开启自检应答示例
import {StartSelfCheckAnswer, Protocol, ProtocolType} from "@hot_stove/serial_port";
tool.on_message(function (msg) {
if (msg.type === ProtocolType.StartSelfCheckAnswer) {
// 开启结果 | 类型: number | 示例值: 1
console.log(msg.start_result)
// 失败原因 | 类型: number | 示例值: 0
console.log(msg.failure_reason_code)
// 判断是否开启成功
if (msg.start_result === StartSelfCheckAnswer.StartResultSuccess) {
// 开启成功的逻辑 ...
}
}
})
维护操作
-- 打包
rollup -c
-- 发布
npm publish
参考:
1.0.26
2 months ago
1.0.25
2 months ago
1.0.24
2 months ago
1.0.27
2 months ago
1.0.22
2 months ago
1.0.23
2 months ago
1.0.19
2 months ago
1.0.21
2 months ago
1.0.20
2 months ago
1.0.18
3 months ago
1.0.17
3 months ago
1.0.16
3 months ago
1.0.15
3 months ago
1.0.14
3 months ago
1.0.13
3 months ago
1.0.2
3 months ago
1.0.1
3 months ago
1.0.9
3 months ago
1.0.8
3 months ago
1.0.7
3 months ago
1.0.6
3 months ago
1.0.5
3 months ago
1.0.4
3 months ago
1.0.3
3 months ago
1.0.11
3 months ago
1.0.10
3 months ago
1.0.12
3 months ago
1.0.0
3 months ago