Python Forum
sending arduino data to python and use a parity check
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sending arduino data to python and use a parity check
#7
Use exception handling and skip the lines, which do not have enough fields.

import serial


def do_something(a, b):
    print(a, b)


def read_loop(ser):    
    while True:
        dat = ser.readline().decode()
        localtime = time.asctime(time.localtime(time.time()))
        try:
            a,b,c,d,e,f,g,h = dat.split(" ; ")
        except ValueError:
            print('Incomplete data, skipping')
        do_something(a, b)

        
with serial.Serial('/dev/ttyACM0', 9600) as ser:
    ser.flushInput()
    read_loop(ser)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: sending arduino data to python and use a parity check - by DeaD_EyE - Aug-03-2019, 10:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  send a byte of data by bluetooth to arduino using python. x1cygnus 1 6,359 Mar-13-2020, 04:54 PM
Last Post: VerlaHiltz

Forum Jump:

User Panel Messages

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