Hi!
I'm currently implementing a program in Python to send files to an EEPROM and came across the problem of automatically detecting the board.
In this topic, I will show how to solve the problem using Python Programming Language and PySerial Library.
So if you connect a Teensy to PC and launch this code:
You'll return:
This is the base of this function:
So I created a little example to do the basis:
Teensy not founded:
Teensy founded:
This code works on Windows but I don't know the effects in others Operational Systems... I'm not so good at programming, so... if you have suggestions/corrections feel free to interact. I'm glad this code can help you with your projects!
Bye!
I'm currently implementing a program in Python to send files to an EEPROM and came across the problem of automatically detecting the board.
In this topic, I will show how to solve the problem using Python Programming Language and PySerial Library.
So if you connect a Teensy to PC and launch this code:
Code:
from serial.tools import list_ports
list(list_ports.comports())
You'll return:
Code:
[('COM5', 'Teensy USB Serial (PJRC.COM) (COM5)', 'USB VID:PID=16C0:0483 SNR=12345')]
This is the base of this function:
Code:
def getTeensyPort():
"""Discover where is Teensy."""
ports_avaiable = list(list_ports.comports())
teensy_port = tuple()
for port in ports_avaiable:
if port[1].startswith("Teensy"):
teensy_port = port
if teensy_port:
return teensy_port
So I created a little example to do the basis:
Code:
import sys
import serial
from serial.tools import list_ports
class TeensySerial:
def __init__(self, baudrate):
self.teensy_port = self.getTeensyPort()
self.teensy = serial.Serial(self.teensy_port[0], baudrate)
def getTeensyPort(self):
"""Discover where is Teensy."""
ports_avaiable = list(list_ports.comports())
teensy_port = tuple()
for port in ports_avaiable:
if port[1].startswith("Teensy"):
teensy_port = port
if teensy_port:
return teensy_port
def close(self):
if self.teensy.isOpen():
self.teensy.close()
if __name__ == "__main__":
print "Welcome to Example: Autodetect Teensy!"
try:
teensy = TeensySerial(115200)
print "Connected to: %s" % teensy.teensy_port[1]
teensy.close()
except TypeError:
print "Cannot find a Teensy board connected..."
Teensy not founded:
Teensy founded:
This code works on Windows but I don't know the effects in others Operational Systems... I'm not so good at programming, so... if you have suggestions/corrections feel free to interact. I'm glad this code can help you with your projects!
Bye!
Last edited: