How to communicate through a serial port with python?
<p>I am creating a Solar Array Simulator with python to simulate the voltage and current being created with different angles and intensities of sunlight as a satellite orbits around the earth. I have a very simple program that outputs the voltage and current just with the angle (no orbiting parameters yet). However, I need it to communicate the outputs generated with a E4350B model solar array simulator through a serial port, and I don't know where to start. I have installed pip and used that to install PySerial but do not know what to do from there. How do I communicate the voltage and amp outputs to the simulator through COM ports? Here is what I have for my program that runs the simulator. </p>

<pre><code>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()
</code></pre>

<p>P.S. For anybody who dabbles in a little bit of physics, I need a way to find the current as a function of the voltage at every angle. </p>