Script console serial port

Ok, then it's a good practice to open and close it.

What about delays within system.serial.port?

There are many time.sleep(0.001) commented in the code. I've notice that opening a port, running instructions, and closing the port, always takes around 5 seconds. That's without any sleep() in it.