Python:两次打开序列号

Python:两次打开序列号,python,port,python-import,pyserial,Python,Port,Python Import,Pyserial,我正在编写Python代码,希望从另一个Python文件导入函数。 问题是,在这两个文件中,我都打开了串行连接 main.py: import numpy as np # import numpy for calculations import matplotlib.pyplot as plt # import matplotlib for plotting from IPython

我正在编写Python代码,希望从另一个Python文件导入函数。 问题是,在这两个文件中,我都打开了串行连接

main.py:

import numpy as np                                 # import numpy for calculations
import matplotlib.pyplot as plt                    # import matplotlib for plotting
    
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib','qt')    # to open the plots in an external window

import time as tm                                  # for the time delays, to ensure that the hardware can complete its tasks

import sys                                         

import serial as ser                               # for communicating with the Arduino
arduino = ser.Serial('COM3',9600)                  # initializing the Arduino with a baudrate of 9600
tm.sleep(3.5)


from myFunctions import query 
from myFunctions import switch, resetMUX
myFunctions.py:

import sys                                         
import time as tm                                  # import time module

import serial as ser                               # for communicating with the Arduino

arduino = ser.Serial('COM3',9600)                  # initializing the Arduino with a baudrate of 9600
在运行main.py之后,当导入函数query、switch和resetMUX时,我收到一个错误,我相信这是因为我打开了两次串行端口。如何调整myFunctions.py文件中的代码,以避免再次打开串行端口

谢谢大家!