send the output from a print command to another window
by RonHof from LinuxQuestions.org on (#4QWPS)
I have the following Python code that reads a serial string and decodes it. I would like to send the output to a window and display it in a large high contrast format. In this case I want it to display 0.92. I've had no luck finding any tutorials on this.
Code:#!/usr/bin/env python
import time
import serial
import string
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate = 4800,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
while 1:
Str = ser.readline(8)
print ("encoded string: ")
print (Str)
Str = Str.decode('cp1252','strict')
print ("decoded string: ")
print (Str)
time.sleep(10)the output looks like this
encoded string:
b' 0.92\r'
decoded string:
0.92
Code:#!/usr/bin/env python
import time
import serial
import string
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate = 4800,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
while 1:
Str = ser.readline(8)
print ("encoded string: ")
print (Str)
Str = Str.decode('cp1252','strict')
print ("decoded string: ")
print (Str)
time.sleep(10)the output looks like this
encoded string:
b' 0.92\r'
decoded string:
0.92