问题
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.
P.S. Im doing C# programming
回答1:
Not directly. Your port RS323 communicates using digital signals that are always 5 volts. You need an analog-to-digital converter (ADC) between your voltage source and the RS232 port. Check out sparkfun.com for plenty of options.
回答2:
Yes, there are several inputs. First of all which are inputs depends on if the RS232 is a DCE or DTE. Originally this standard was put together to connect a terminal to a modem. The DCE is the model and the DTE is the terminal. You wire the pins 1 to 1. Hence Tx can be a receiver or a transmitter.
A PC is typically a DTE. With that in mind this info may make more sense now: http://en.wikipedia.org/wiki/RS-232
The voltages are a nominal +- 7V. Actual a typical range of +-3V to +-15V. Be warned on a negative voltage is a logic 1.
As for C# you have access to all of the pins. Check out the class SerialPort.
Good luck
Rob
回答3:
Yes it is possible. I did it.
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).
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):
Create a timer with 1ms.
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
I hope this will be helpfull. Sedat K.
来源:https://stackoverflow.com/questions/11606620/any-pins-on-rs232-which-can-be-used-to-detect-voltage-as-input