Python Forum

Full Version: Read Data from Serial Port
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Team

I am new to this forum

I need to Read Data from Serial port and put data to Entry Widgest
This is the code that I used
It display unwanted text with actual text So please advice to remove unwanted text like (b'\x01')

The data coming from Serial port is 1.2,4,5,6

import serial
import time
from tkinter import *

root = Tk()
root.title("D Cube Serial Read")
e = Entry(root,width = 35, borderwidth = 5)
e.grid(row = 0, column = 0, columnspan = 3,padx = 10,pady = 10)

ser = serial.Serial('COM3',baudrate = 9600, timeout = 1)
time.sleep(2)


for x in range (10):
    s = ser.read()
    m = str(s)
    n = list(m)
    #print(m)
     
    e.delete(0,END)
    e.insert(0,m)
    

root.mainloop()
Please advice
x01 is a data control and shouldn't be shown, it stands for SOH, (Start of header) and is part of the communications protocol.
There may be a debug mode on this D Cube. You should read the docs, search for control characters, rew data, or debug and see it you can find a way to disable at the source.

you can read: https://en.wikipedia.org/wiki/Control_character to get a better understanding of how these codes are used to frame a packet.
Hi Larz

Thanks for the reply and advise
This is the characters printed out


b'\x01'     #Hear x01 is the real data   
b'\r'b      #Unwanted control characters 
b'\n'       #Unwanted control characters 
b'\x02'     #Hear x02 is the real[quote]
I want to remove unwanted control characters

Please advice
Hi
I found following Widgets

 l = s.strip()
now n/t/ removed but following characters is showing with actual data
data here is x00

b''
b'\x00'
b''
Please advice with code to remove above unwanted characters

Thanks in advanced