add lock in serial port write method