如何通过串口与python进行通信?

时间:2016-07-18 17:27:30

标签: python-3.x

我正在创建一个带有python的太阳能阵列模拟器来模拟以不同角度和强度的太阳光创建的电压和电流,因为卫星围绕地球运行。我有一个非常简单的程序,只用角度输出电压和电流(还没有轨道参数)。但是,我需要它通过串口传送E4350B型太阳能电池阵列模拟器产生的输出,我不知道从哪里开始。我已经安装了pip并用它来安装PySerial但不知道该怎么办。如何通过COM端口将电压和放大器输出传送到模拟器?这是我运行模拟器的程序所拥有的。

from math import sin,radians,pi
import time

'''Needed information:
   Voc (per one cell) = 2,680mV
   Vmp (per one cell = 2,325mV
   Isc (per one cell) = 453mA
   Imp (per one cell) = 434mA
   angular velocity = .05d/s'''

#Timer eclipse set for total eclipse tim ein seconds
timeEclipse = 1800
#total eclipse time = 30 mins
#Timer sun set for how many seconds it takes to change one degree
timeSun = 20
#Total sun exposer time = 60 mins
#Find the Vmp, Voc, Imp, and Isc from Beta angles 0 - 180
def Exposure():
    tSun = timeSun
    for x in range(0,181):
       angle = sin(radians(x))
       Voc = 2680 * angle
       Vmp = 2325 * angle
       #Amps are going to be a function of voltage
       Isc = 453 * angle
       Imp = 434 * angle
       #
       print('At angle ',x,' Vmp = ',Vmp,
         'mV, Voc = ',Voc,'mV, Isc = ',Isc,'mA, and Imp = ',Imp,'mA')
   time.sleep(tSun)

#Simulate time during eclipse
#Outputs nothing
def Eclipse():
    tEclipse = timeEclipse
    time.sleep(tEclipse)

#Run loop through Exposure and eclipse
def Run():
    run = True
    while(run):
        Exposure()
        Eclipse()

P.S。对于任何涉及一点物理学的人来说,我需要一种方法来找到电流作为每个角度电压的函数。

0 个答案:

没有答案