You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
962 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package m9z
import (
"fmt"
)
// RelayStatusData 实际通断状态数据结构
type RelayStatusData struct {
IsOpen bool // 0x01:闭合(true), 0x00:断开(false)
}
// ParseRelayStatusResponse 解析实际通断状态响应
// 响应格式示例: EE 99 01 00 02 01 00 D0 FF
// Data部分: 01 00 (长度为2第一个字节为状态)
func ParseRelayStatusResponse(data []byte) (*RelayStatusData, error) {
if len(data) < 1 {
return nil, fmt.Errorf("invalid data length %d, expected at least 1 byte", len(data))
}
status := data[0]
return &RelayStatusData{
IsOpen: status == 0x01,
}, nil
}
// RelayStatusRead 读取实际通断情况
// CMD = 0x19
func RelayStatusRead(device string) (*RelayStatusData, error) {
// 调用 ReadCmd指令码为 relayStatus (0x19),无索引(0x00)
readRep, err := ReadCmd(device, relayStatus, "读取实际通断情况", 0)
if err != nil {
return nil, err
}
return ParseRelayStatusResponse(readRep.Data)
}