func LED_PlayVoice(VoiceText string) { Buff := make([]byte, 255) //分配缓冲数组 TextBuff := []byte(VoiceText) //把string类型字符串读取到字节数组里面。注意字符串编码必须是GB2312 WINDOWS代码页为936 Pos := 0 TextLen := len(TextBuff) //获取字符串数组的长度 var CRC uint16

if (6 + 1 + TextLen + 2) >= 255 { //一个数据包最大不能超过255长度
    return
}

/*0.填充显示命令参数*/
Buff[Pos] = 0x00 //显示屏地址
Pos++
Buff[Pos] = 0x64 //固定参数
Pos++
Buff[Pos] = 0xFF //包序列
Pos++
Buff[Pos] = 0xFF //包序列
Pos++
Buff[Pos] = 0x30 //指令
Pos++
Buff[Pos] = byte(1 + TextLen) //数据长度
Pos++
Buff[Pos] = 0x01 //播放选项
Pos++
/*1.复制语音文本内容到缓冲区*/
for i := 0; i < TextLen; i++ {
    Buff[Pos] = TextBuff[i]
    Pos++
}
/*2.计算校验码*/
CRC = MB_CRC16(&Buff, Pos)
Buff[Pos] = byte(CRC & 0xff) //校验码低字节
Pos++
Buff[Pos] = byte((CRC >> 8) & 0xff) //校验码高字节
Pos++

/*3.最后在这里把Buff的内容发送出去,长度为Pos */
//....

}

static void LED_PlayVoicestring VoiceText byte Buff = new byte255;分配缓冲数组 byte TextBuff = SystemTextEncodingDefaultGetBytesVoiceText; 把string 类型字符串 读取到字节数组里面注意字符串编码必须是GB23

原文地址: https://www.cveoy.top/t/topic/b1i6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录