Yes of course you can do it. There are several lines on the serial port that can be used as GPIOs. One of them (on pin9, I think) is RING, which is used in old serial modes to signal incoming calls.
You can read it as follows:
unsigned mask = TIOCM_RNG; unsigned status; int fd;
You also need to create a voltage that you can apply to the ring line. One cheap way to do this is to transfer some stream of alternating bits. For instance. send 0x55 at any baud rate.
Then you can click on the voltage from the TX pin. Separate the positive and negative voltages using two diodes, and be careful when using two capacitors. This will give you positive and negative voltages compatible with the ring line.
Here is a diagram that should work. Adjust the diodes and capacitors to taste, but don't go crazy about the capacitor. 10μF should be maximum.

source share