联系我们

与泰克代表实时聊天。 工作时间:上午 9:00 - 下午 5:00(太平洋标准时间)。

电话

致电我们

工作时间:上午9:00-下午5:00(太平洋标准时间)

下载

下载手册、产品技术资料、软件等:

下载类型
型号或关键字

反馈

How do I monitor the state of a contact switch using a digital I/O board?

问题:

How do I monitor the state of a contact switch using a digital I/O board?

答案:

The digital inputs on the digital I/O board monitor digital high or low states. The input can be connected to +5 volts through a resistor of approximately 10kOhms, making the digital input high. If a contact switch is connected between digital ground and the input, the input will read high until the switch is closed, pulling the input low, as shown in Figure 1.


Figure 1

Most digital inputs on the digital I/O board come in groups of 8 lines. When these groups are read in software, the states of the 8 input lines are represented by an 8-bit decimal number from 0 to 255. This value is equal to the sum of the decimal weightings of each bit that is high. A value of 0 means that all lines are low, while a value of 255 means that all 8 lines are high. The states of individual lines can be determined by performing a bitwise AND with the value corresponding to that bit shown in Figure 2.


Figure 2

For example, if a value of 139 is read in the software and this value is ANDed with 128 (bit8), the answer would be 128, which means that bit8 is high. If 139 is also ANDed with 8 (bit4), we get 8, which means that bit4 is also high. Now, if we AND 139 with 16 (bit5), we get 0, which means that bit5 is low.

The sum of 139 corresponds to 128+8+2+1, so we can determine that bits 1, 2, 4, and 8 are all high.


此常见问题适用于:

无产品系列

产品:

常见问题 ID 70581

查看所有常见问题 »