如何在vb.net中检测串口中的5伏信号? [英] How to detect a 5 volt signal in serial port in vb.net?

查看:134
本文介绍了如何在vb.net中检测串口中的5伏信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个投币式网吧软件。我希望我的程序在每次插入硬币时检测来自硬币探测器的5伏信号。但是,我一直在搜索谷歌试图找到样本代码,但无济于事。 Pinchange事件不起作用,因为携带信号的导线总是连接到串行端口引脚,即使没有在硬币插槽中插入硬币也会发生pinchange事件。我想只检测硬币检测器在每次插入硬币时发送到串口的5伏信号。请帮帮我。



谢谢你和最好的问候。

解决方案

肯定取决于定义

引用:

硬币检测器在每次插入硬币时发送到串口的5伏信号

- 我想你了无论如何最好从模拟到数字并处理数字状态变化


串口根本不暴露任何电压测量硬件。你不能直接检测5伏特。



该端口确实暴露了引脚上状态变化的存在。如果电压低于阈值电压,则引脚变为低电平,并且您的代码将其视为逻辑低电平或0.如果电压升至阈值电压以上,则引脚变为高电平,或者为1.



阈值电压的大小取决于串行端口的确切规格。有些工作电压为3伏,可承受5伏电压,有些只有5伏电压。



如果你所描述的是你所拥有的唯一文件,很可能这是好的不是一个真正的串行设备,你不会用正常的读写方法在端口上读取一个字节。您可能只会在引脚上更改状态,在这种情况下,您可能正在轮询您将设备连接到的任何引脚的状态。


这将有效:



http://www.cedarlakeinstruments .com / blog / archives / 46 [ ^

I am making an internet cafe software that is coin-operated. I want my program to detect 5 volt signal coming from a coin detector in every insertion of coin. However, I've been searching in google trying to find sample codes to do this but to no avail. Pinchange event doesn't do the trick since the wire that carries the signal is always connected to a serial port pin and pinchange event is always happening even without inserting a coin in the coin slot. I want to detect only the 5 volt signal that the coin detector sends to serial port in every insertion of coin. Please help me on this.

Thank you and best regards.

解决方案

surely that depends on the definition of

Quote:

the 5 volt signal that the coin detector sends to serial port in every insertion of coin

- I think you'd be better off going from analogue to digital anyway and dealing with the digital state change


The serial port doesn't expose any "voltage measurement" hardware at all. You cannot directly "detect 5 volts" as you put it.

The port does expose the presence of a change in state on the pins. If the voltage falls below a threshold voltage, the pin goes low and your code sees it as a logic low, or 0. If the voltage rises above the threshold voltage, the pin goes high, or 1.

What that threshold voltage is is determined by the exact specs of your serial port. Some work on 3 volts and tolerate 5 volts, some only on 5 volts.

If what you describe is the only "documentation" you have, chances are good this is not a real serial device and you're not going to get a byte to read on the port with normal read and write methods. You're probably going to only get a change of state on a pin, in which case, you'll probably be polling for the state of whatever pin you've connected the device to.


This will work:

http://www.cedarlakeinstruments.com/blog/archives/46[^]


这篇关于如何在vb.net中检测串口中的5伏信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆