refactor of serial port check and read
A square wave generating script