Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read Data from Serial Port
#1
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
Reply
#2
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.
Reply
#3
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
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Waiting for input from serial port, then move on KenHorse 3 1,015 Apr-17-2024, 07:21 AM
Last Post: DeaD_EyE
  MCU reboots after opening Serial port when ran from Raspberry PI zazas321 3 432 Mar-19-2024, 09:02 AM
Last Post: zazas321
  Help with to check an Input list data with a data read from an external source sacharyya 3 403 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 3,911 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Serial Port As Global Prasanjith 2 1,493 Mar-23-2023, 08:54 PM
Last Post: deanhystad
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 819 Mar-21-2023, 10:06 PM
Last Post: deanhystad
  Correctly read a malformed CSV file data klllmmm 2 1,928 Jan-25-2023, 04:12 PM
Last Post: klllmmm
  Read nested data from JSON - Getting an error marlonbown 5 1,358 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Read data via bluetooth frohr 9 3,356 Jul-10-2022, 09:51 AM
Last Post: frohr
  Write and read back data Aggie64 6 1,865 Apr-18-2022, 03:23 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020