StevenM

Using Serial commands in IronPython Script

Recommended Posts

In the documentation the last example it opens a serial connection and sends a command.
 

import time
ECig.Track('Last Puff Energy')
motor = Serial.Open('COM10', 9600)
motor.WriteLine('P1: 2047')
time.sleep(1)
ECig['Power Set'] = 20;
ECig.Puff(5)
time.sleep(5)
time.sleep(1)
motor.WriteLine('P1: -2047')
energy = ECig['Last Puff Energy']
ECig.StopTracking('Last Puff Energy')
UI.Message('The last puff energy was {0} milliwatt-hours.'.format(energy))

Using some interspection I find that WriteLine isn't an available command, but Write is. The problem that I am finding with write is that .NET is expecting an Array[Byte], which I do not believe there is a way to convert to in python.

 

motor = Serial.Open('COM4', 9600)

s = u"P=50 W"
b = bytearray()
b.extend(s)

motor.Write( b ,0,6)

The only thing I am trying to do is be able to turn on and off charging on the board. If there is an easy way that works without open a serial port?

Edited by StevenM

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now