與我們聯絡

與 Tek 業務代表即時對談。 上班時間:上午 6:00 - 下午 4:30 (太平洋時間)

致電

請致電

與 Tek 業務代表即時對談。 上班時間:上午 8:30 - 下午 5:30 (太平洋時間)

下載

下載手冊、產品規格表、軟體等等:

下載類型
機型或關鍵字

意見回饋

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

檢視所有常見問答集 »