Ejemplo n.º 1
0
def reset(port):
    try:
        com = Serial(port, 1200)
        com.dtr = False
        com.close()
        return True
    except:
        return False
Ejemplo n.º 2
0
    def toggle_flash(self, event):
        """
        Display the folder to regist script. Return a dictionary of the
        settings that may have been changed by the admin dialog.
        """
        regist_box = RegisterWindow(self.view)
        result = regist_box.exec()
        if (result == 0):
            return

        # Display sending message
        self.editor.show_status_message(_("Updating..."))

        # Display sending message
        reg_info = regist_box.get_register_info()
        reg_num = reg_info[0]

        tab = self.view.current_tab
        usr_file = os.path.join(HOME_DIRECTORY, WORKSPACE_NAME, 'studuinobit',
                                'usr' + reg_num + '.py')
        save_and_encode(tab.text(), usr_file, tab.newline)

        # Send script
        device_port, serial_number = self.find_device()
        serial = None
        exp_flag = False
        try:
            serial = Serial(device_port, 115200, timeout=1, parity='N')
            filename = os.path.basename(usr_file)
            microfs.put(usr_file, 'usr/' + filename, serial)
            microfs.execute([
                'import machine',
                'machine.nvs_setint("lastSelected", {0})'.format(reg_num),
            ], serial)
            time.sleep(0.1)
            serial.write(b'\x04')
        except Exception as e:
            logger.error(e)
            exp_flag = True
        finally:
            if serial is not None:
                serial.dtr = True
                serial.close()

        self.toggle_repl(None)
        self.toggle_repl(None)

        # dlg_msg.close()
        if not exp_flag:
            self.editor.show_status_message(
                _("Finished transfer. \
                Press the reset button on the Studuino:bit"))
        else:
            self.editor.show_status_message(_("Can't transfer."))
Ejemplo n.º 3
0
def open_upy(port, baud):
    log.debug("Entering")
    log.info("Opening port and resetting ESP into run mode.")
    upy = Serial(port, baud)
    upy.reset_input_buffer()
    upy.rts=1
    upy.dtr=0
    upy.rts=0
    log.info("Sending ^c after 500ms.")
    sleep(0.5)
    upy.write(b'\x03')
    upy.flush()
    log.debug(upy.read_until(b'>>> ').decode(errors='ignore'))
    sleep(0.01)
    if upy.in_waiting:
        log.debug(upy.read_until(b'>>> ').decode(errors='ignore'))
    return upy
Ejemplo n.º 4
0
def reset_avr(ser_port):
    try:  # try to initiate serial port connection on PORT with 1200 baudrate
        ser = Serial(port=ser_port,
                     baudrate=1200,
                     parity=PARITY_NONE,
                     stopbits=STOPBITS_ONE,
                     bytesize=EIGHTBITS)
    except SerialException as e:
        print("pySerial error:", e)
        sys.exit(1)

    try:  # try to open PORT
        ser.isOpen()
        ser.dtr = False
    except SerialException:
        print("pySerial error:", e)
        sys.exit(1)

    ser.close()
Ejemplo n.º 5
0
Archivo: base.py Proyecto: Naf3tS/mu
    def open(self):
        """
        Open the serial link
        """

        logger.info("Connecting to REPL on port: {}".format(self.port))

        if not self.serial.open(QIODevice.ReadWrite):
            msg = _("Cannot connect to device on port {}").format(self.port)
            raise IOError(msg)

        self.serial.setDataTerminalReady(True)
        if not self.serial.isDataTerminalReady():
            # Using pyserial as a 'hack' to open the port and set DTR
            # as QtSerial does not seem to work on some Windows :(
            # See issues #281 and #302 for details.
            self.serial.close()
            pyser = Serial(self.port)  # open serial port w/pyserial
            pyser.dtr = True
            pyser.close()
            self.serial.open(QIODevice.ReadWrite)
        self.serial.readyRead.connect(self._on_serial_read)

        logger.info("Connected to REPL on port: {}".format(self.port))
Ejemplo n.º 6
0
import time
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style

#serial libraries
import struct
from serial import Serial

ser = Serial()
ser.port = 'COM6'
ser.baudrate = 115200
ser.timeout = 0.5
ser.dtr = 0
ser.open()
print("Is Serial Port Open:", ser.isOpen())

fig = plt.figure()
ax = fig.add_subplot(111)
fig.show()

i = 0
x, y1, y2 = [], [], []

while True:

    #Read echo Parameters
    serialvar = struct.pack('<BBHHHHHHHdddHHdddHHdHHH', 69, 21, 1, 60, 120,
                            250, 150, 10, 200, 2.5, 2, 2.4, 5, 200, 2.5, 2,
                            2.4, 10, 8, 2.5, 20, 120, 0)
    ser.write(serialvar)
Ejemplo n.º 7
0
data_checksum = sum(data) & 0xFF
data_base = word_to_bytes(int(data_base, 0))
data_len = word_to_bytes(len(data))

upload_maindata = prog_base + prog_len + data_base + data_len + prog + data
num_acks = (len(prog) // 16) + (len(data) // 16)
upload_checksums = [prog_checksum, data_checksum]
init_addr = word_to_bytes(init)

print("Opening serial port...")
port = Serial(serial_port, baud, timeout=0, dsrdtr=False)

data = port.read(10000) # Read as much data is available

print("Resetting...")
port.dtr = 1
time.sleep(0.5)
port.dtr = 0
time.sleep(0.5) # Wait to enter bootloader

data = port.read(10000) # Read as much data is available

if data != [0x5]:
    print("Failed to reset automatically. Please manually reset the microcontroller.")
    data = b""
    while len(data) == 0:
        time.sleep(0.1)
        data = port.read(10000)

    print("Reset detected")
    time.sleep(0.5)
Ejemplo n.º 8
0
# https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial
# See docs/Datalogger MeteoLOG TDL14.pdf page 28.
dmm = Serial(port='/dev/ttyUSB0',
             baudrate=9600,
             bytesize=SEVENBITS,
             parity=PARITY_EVEN,
             stopbits=STOPBITS_ONE,
             xonxoff=False,
             rtscts=False,
             dsrdtr=False,
             inter_byte_timeout=None)
# https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial.rts
dmm.rts = False
# https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial.dtr
dmm.dtr = True
# Clear the queue so that data doesn't overlap and create erroneous data points
dmm.flushInput()

while True:
    try:
        # https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial.readline
        # Lines are concluded with "CR LF". See docs/Datalogger MeteoLOG TDL14.pdf page 20.
        # https://developer.mozilla.org/de/docs/Glossary/CRLF
        #print(dmm.readline())
        ser_bytes = dmm.readline()
        decoded_bytes = str(ser_bytes[0:len(ser_bytes) - 2].decode("utf-8"))
        print(decoded_bytes)
        # You want unbuffered output whenever you want to ensure that the output
        # has been written before continuing.
        stdout.flush()