Call the CloseHandle function to close a serial port when an application is done using it. CloseHandle has one parameter, which is the handle returned by the CreateFile function call that opened the port.