Serial Communication

This is the place for queries that don't fit in any of the other categories.

Serial Communication

Postby Jimmer » Sun Feb 09, 2014 1:28 am

HI, I'm totally new to Python. I'm using version 2.7.

I'm having a hard time with PySerial. I am trying to write my own GUI, so far with some success. To explain I am using an arduino to log data and save to a file on an SD card. From here it is sent via Bluetooth to a dongle on the pc. Currently I'm using Putty, which works great to retrieve the data. Only I want to skip the step of using putty and have something serial within my GUI. I am completely lost with this part. I would like for the user to be able to select the ComPort but nothing else as the Bluetooth has been set to 57600 Baud by default so the program will also be set to that, making it needless for the user to select.

Please help, I've been scouring the web for over a week and haven't found anything close to helping me. I have found this bit of code:

Code: Select all
ser = serial.Serial(
            port='COM13',\
            baudrate=57600,\
            parity=serial.PARITY_NONE,\
            stopbits=serial.STOPBITS_ONE,\
            bytesize=serial.EIGHTBITS,\
             timeout=100)
       

        print("connected to: " + ser.portstr)
       

        line = []

        while True:
            for c in ser.read():
                line.append(c)
                if c == '\n':
                    print(line)
                   
                    line = []
                    break

        ser.close()


This works to open a serial port(only the one specified) and its prints the data out to the python shell. However it prints each individual character with 'x' so serial prints as 's' 'e' 'r' 'i' 'a' 'l' as you can see that doesn't work...I would like to write the incoming data to a textbox where it can be saved. (The saving part I have figured out, and I'm able to open already saved files and display all of the data in graph forms)

The Serial port thing is just beyond my 3 weeks total of python. (the fact I'm 40 and this is the first time I've ever tried data processing I feel good about what I've done so far, with your help I hope to finish this project soon!)
THanks everyone!
Last edited by Yoriz on Sun Feb 09, 2014 3:31 am, edited 1 time in total.
Reason: First post lock, Added code tags
Jimmer
 
Posts: 2
Joined: Sun Feb 09, 2014 1:18 am

Re: Serial Communication

Postby Yoriz » Sun Feb 09, 2014 3:31 am

Hi welcome to the forum, please read the new users read this link in my siganture.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1049
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Serial Communication

Postby Jimmer » Sun Feb 09, 2014 3:33 am

I've changed the code to :

Code: Select all
 ser = serial.Serial(
            port='COM13',\
            baudrate=57600,\
            parity=serial.PARITY_NONE,\
            stopbits=serial.STOPBITS_ONE,\
            bytesize=serial.EIGHTBITS,\
             timeout=100)
       

        line = []

       
        while True:
            line = ser.readline().decode('utf-8')[:-2]
            self.rtb.SetValue(line)
            if line:
                print(line)
               
            if line == '520':
                subprocess.call(["xte", "key Up"])
            elif line == '620':
                subprocess.call(["xte", "key Down"])
            elif line == '110':
                break

        ser.close()

This now prints the incoming data in the correct CSV format. So now I am struggling with getting the incoming data to print to my textctrl box, and still need help to sort out how to allow the user to select ComPort.
Please and thanks!
Last edited by Jimmer on Sun Feb 09, 2014 3:47 am, edited 1 time in total.
Jimmer
 
Posts: 2
Joined: Sun Feb 09, 2014 1:18 am

Re: Serial Communication

Postby Yoriz » Sun Feb 09, 2014 3:34 am

Please change your previous post to show the code using code tags, this ensure indentation of the code is maintained.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1049
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], W3C [Linkcheck] and 7 guests