威纶通官方论坛

关于宏指令问题

[复制链接]
发表于 2014-2-28 11:30:20 | 显示全部楼层 |阅读模式
在威纶通网站上找到的free protocol例子中,其中宏指令有这样一条语句,
address = 0
address = address * 16
HIBYTE(address, command[2])
LOBYTE(address, command[3])

read_no = 1//  read 0x, 1 words
read_no = read_no << 4  //  see protocol
HIBYTE(read_no, command[4])
LOBYTE(read_no, command[5])
这里的address为什么要*16,还有read_no=read_no<<4是什么意思,请教!谢谢

相关帖子

发表于 2014-2-28 14:07:44 | 显示全部楼层
address = 0
address = address * 16
你这个应该是通过MODBUS协议读取位地址状态的宏指令。
上面的 address 指的是第几个寄存器,   *16以后就代表读取的是第几个寄存器的第一个位,默认16位为一个寄存器。

read_no = 1//  read 0x, 1 words
read_no = read_no << 4  //  see protocol

read_no = 1  表示读取一个寄存器。
read_no << 4   表示这个数据向左移4位,这样上面的1就变成了二进制的10000  就是16.这样就表示读取连续的16个位。
您需要登录后才可以发帖 登录 | 注册

本版积分规则

回复帖子

Archiver|小黑屋|威纶通官网 ( 粤ICP备06054553号 )

GMT+8, 2025-5-13 04:49

Powered by Discuz! X3.4

© 2001-2023 Comsenz Inc.

快速回复 返回顶部 返回列表