[bash] synchronizing write/read to serial
Hello all!
I have created an rs323 loop and connected it to my door. When its closed, loop is closed, when door is open loop is open. Trying to create two bash scripts, one of which will write to serial, and the other read from it. Consequently if the read pattern is different to what was sent the door would be marked as open. Write script is relatively easy: Code:
#/bin/bash Here is my read code: Code:
#/bin/bash |
Obviously you are using the serial port in a unusual manner. I could suggest other methods that would be better suited for this type of application but do not know if this is a just for fun, home or a school project.
Have you tried limiting read to a single character? |
Quote:
Quote:
|
Trying using the -n 1 option to read one character. Just some basic reasoning is that the serial port does have a small buffer so your program might still sense the door is closed. Being that the computer loops much faster vs the ports baud rate. Other false alarms are probably being caused by switch bounce or just timing issues. You could use hardware control lines i.e. DTR,RTS but this involves some serial port programming skills. A pullup resister circuit would prevent switch bounce.
I would suggest using the parallel port instead if your computer has one built in and not being used. This will not work with a USB-parallel port adapter. The circuit is a little more complicated but will eliminate false alarms and you would need to write a simple c program. You would use the switch and pullup resister example. The pullup resister helps prevent false alarms and always keeps the circuit in a known state. Using one data line set high for +5V connected to the resister other side going to a status pin through the switch and then ground. There are other programming examples but here is one. http://www.epanorama.net/circuits/parallel_output.html |
All times are GMT -5. The time now is 10:06 PM. |