I would like to make a simple device to communicate to my computer via RS232 using Delphi 7. That circuit is just simple, a button with the 220 oh resistor, 0.1uF capacitor, +5VDC power, RS232 connector, and USB to RS232 adapter. The output of the simple circuit will be connected to pin 2 (Rx pin) in the computer side. Whenever I press the button, then counter will be incremented by 1. As comparison, in Arduino just needs few lines code to do the task.
Another info that maybe required: I have CPortLib and CiaComPort installed on my Delphi 7. Both I have tested, they are working to receive data. Using ComPort (one module of the CPortLib), I can send and receive data to my own computer by loop back it, the Pin2 (Rx) and Pin3 (Tx) of the RS232 is looped. To receive I use command ComPort1.ReadStr(Str, Count); (to send data I use command: ComPort1.WriteStr(Str);) Means, the AddOn ComPort module is working fine.
You can't receive switch input using RS232 receive line because a switch can't send serial data.
What you can do is to use the wires normally dedicated to modem controls. RS232 library have functions the sense those signals. I never used RS232 like that.
Since you talk about Arduino, which has digital inputs as well as analog inputs, I would write a small Arduino program communicating with the PC by RS232 thru the USB connection. When the Arduino sense a change in his digital or analog input, it send a message thru the RS232. Arduino program should handle anti bounce of the switch.
There are very small and cheap Arduino boards that would do the job.
The code in Delphi would be very simple using CiaComPort
component (and probably any other): Drop the component on a form, set baud rate, parity, stop bits the same value as the Arduino (I suggest 9600 bauds). Set LineMode
to TRUE and LineEnd
to CRLF. Then assign an OnDataAvailable
event where you call Receive method to get the data sent by the Arduino. Arduino should send a message with the input line (or lines) status and a CRLF pair so that the LineMode
work as expected and you receive a single DataAvailable
for each Arduino message.
The parse the Arduino message and act as required.