rs232 上可用于检测电压作为输入的任何引脚 [英] Any pins on rs232 which can be used to detect voltage as input

查看:72
本文介绍了rs232 上可用于检测电压作为输入的任何引脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 rs232 获得电压输入?我现在正在做的是我有 2 台电脑连接到 rs232 以使用 gnd、tx 和 rx 引脚进行通信.我还将 DTR 连接到一个开关,当按下开关时,我无法获得电压输出来驱动 LED.我现在想做的是,当 LED 亮起时,我会以某种方式获得输入并更改 m 编程中的一些内容.有可能这样做吗?提前致谢.

Is there a way i can get a voltage input using rs232? What i am doing now is i have 2 pc hooked up to rs232 to communicate using gnd, tx and rx pin. Ive also connect DTR to a switch and when the switch is pressed im able to get a voltage output to drive a LED. What i want to do now is that when the led lights up, i will somehow get a input and change some stuffs in m programming. Is it possible to do that? Thanks in advance.

附言我在做 C# 编程

P.S. Im doing C# programming

推荐答案

是的,这是可能的.我做到了.

Yes it is possible. I did it.

只需将电源的 -(负,地)连接到 RS232 RX 引脚(请参阅 Internet 上的任何地方以确定 RX 引脚的位置).当您向该引脚提供电压(作为脉冲)时,您会在端口中看到一些无意义的动作.出现一个 OnComm 事件为接收",但它没有开始位,没有停止位,完全没有意义.但是任何监视 RS232(COM 端口)的程序都会显示端口上正在发生某些事情(例如 HEX 中的00"或 ascii 中的[00]").

Just connect the - (minus, ground) of the energy source to RS232 RX pin (Refer to anywhere in Internet to be sure where the RX pin is). When you give voltage (as pulse) to this pin, you see some meaningless actions in your port. There appears an OnComm event as 'Receive' but it has no start bit, no stop bit, it is fully meaningless. But any program which monitors RS232 (COM Ports) will show that something is happening on the port (Such as ' 00 ' in HEX or '[00]' in ascii).

我说过它没有开始和停止位,它的电压不是RS232通信所需的平均电压,所以你必须用这样的子程序来检测它(你不能用任何其他方式处理它):

As I said it has no start and stop bits, its voltage is not the average voltage needed for RS232 communication, so you must detect it with a subroutine like this (you can not handle it any other way):

创建一个 1ms 的计时器.

Create a timer with 1ms.

timer1.enabled = false----不要忘记禁用它如果 mscomm1.inbuffercount > 0 那么-----把你的代码放在这里-----表示RX出现电压-----例如你可以编码'buttonpresscount=buttonpresscount+1'万一等待行动结束:如果 mscomm1.inbuffercount >0 那么----还有一些无意义的电压----等到脉冲结束,所以事件转到等待操作停止万一----不要忘记再次启用定时器timer1.enabled = true

timer1.enabled = false ----Don't forget to disable it if mscomm1.inbuffercount > 0 then -----put your code here -----it means the voltage has appeared at RX -----for example you can code 'buttonpresscount=buttonpresscount+1' end if waitfortheactionend: if mscomm1.inbuffercount >0 then ----there is still some meaningless voltage ----wait until pulse ends, so doevents goto waitfortheactionstop end if ----Don't forget to enable the timer again timer1.enabled = true

我希望这会有所帮助.Sedat K.

I hope this will be helpfull. Sedat K.

这篇关于rs232 上可用于检测电压作为输入的任何引脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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