serial write a command and print output to file

1

I am new to serial programming in Python. Basically, doing the same command I would do in Putty or some other terminal. Get output from Putty after running command "dz 0x80000000 4096" to a TiVa processor but not with Python3.6.5 program I wrote below. Get no output as if it didn't write the command. Also didn’t print output to screen after running the write command.

Program below:

    import logging
    import serial
    import serial.threaded
    import threading
    import time
    timeout = time.time() + 15 #may have to adjust, 10 seconds from now
    import sys
    import csv
    from datetime import datetime


    ser= serial.Serial('COM19', baudrate = 115200,parity=serial.PARITY_NONE, 

stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS,rtscts=True,timeout=2,writeTimeout=5)

    def getvalues():
        ser.write(b'dz 0x80000000 4096') #printed 18, not sure if it ran the command?
        IQ_data = ser.readline().decode('ascii')
        return IQ_data


    while(1):  

        with open("E:/HigherGround_Home/Pyserial_Gurb/log.txt","w") as f:  
        writer = csv.writer(f)
        writer.writerow(getvalues())
        if time.time() > timeout:
           break
    f.close()

Can someone please help me get my program to correctly print to a file?

Thanks, Gurb

serial-port
asked on Stack Overflow Nov 21, 2018 by user3313975 • edited Nov 21, 2018 by user3313975

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0