Author Topic: Cannot send string via ser.write() on linux box  (Read 3518 times)

0 Members and 1 Guest are viewing this topic.

cbohart

Cannot send string via ser.write() on linux box
« on: June 25, 2011, 08:13:38 PM »
Here is my problem anyway.

I have boards taking temperature readings and sending them to serial at short intervals.  In eclipse I have written python w/ gui's to receive those readings and do some things.  This works fine on Fedora 14 on two different machines.

I have another board that is set to receive a string ( by incremental char ) and flip switches.  This works perfectly when I send the string through the serial monitor in XP.  The yellow serial led lights up momentarily while the info transfers.  But from the py script on the fedora box - nothing goes.  The blue led blinks once and the yellow led does nada.  I am certain that text encoding is not in play here.  Worse...  the string has in fact gone through occasionally.  After messing with the code it suddenly works and keeps working and then stops.

Here is what I'm using to configure the serial port: 

#! /usr/bin/python2.7
import serial
from Tkinter import*
import time

   
root = Tk()
root.geometry("400x300")

main = Frame(root)   
main.pack()


def sendOnes():
   
    locations=['/dev/ttyUSB0','/dev/ttyUSB1']


    for device in locations:
        try:
            print "Trying...",device
            ser = serial.Serial(device, 9600, timeout=2)
            break
        except:
            print "Failed to connect on",device
           
    time.sleep( 2 )
    str1 = "#,1,1,1$"
    ser.write( str1 )
    time.sleep(1)

   
def sendOs():
   
    locations=['/dev/ttyUSB0','/dev/ttyUSB1']


    for device in locations:
        try:
            print "Trying...",device
            ser = serial.Serial(device, 9600, timeout=2)
            break
        except:
            print "Failed to connect on",device

    time.sleep( 2 )
    str2 = "#,0,0,0$"
    ser.write( str2 )
    time.sleep(1)

   
button1 = Button(root, text="Send 111", command=sendOnes)
button1.pack(anchor=CENTER)   

button2 = Button(root, text="Send 000", command=sendOs)
button2.pack(anchor=CENTER)

 
root.mainloop()

This gives me a gui with buttons so I can "send" repeatedly while looking at board leds.  I placed the additional time.sleep() just in case the machine(s) are taking a while to open the port.

My suspicion is that the linux system is ignoring the baudrate I specify and holding the USB port at some other speed ( I tried some other speeds to no avail).

If you have experience with this please share it with me as I have googled this topic to death and found nothing of use.


barragan

Re: Cannot send string via ser.write() on linux box
« Reply #1 on: July 28, 2011, 06:45:05 PM »
hi Craig this tutorial might help you with the python issue: http://wiring.org.co/learning/tutorials/blender/index.html

ShannonBrady

Re: Cannot send string via ser.write() on linux box
« Reply #2 on: July 30, 2013, 06:50:51 AM »
Here is my problem anyway.

I have boards taking temperature readings and sending them to serial at short intervals.  In eclipse I have written python w/ gui's to receive those readings and do some things.  This works fine on Fedora 14 on two different machines.

I have another board that is set to receive a string ( by incremental char ) and flip switches.  This works perfectly when I send the string through the serial monitor in XP.  The yellow serial led light up momentarily while the info transfers.  But from the py script on the fedora box - nothing goes.  The blue led blinks once and the yellow led does nada.  I am certain that text encoding is not in play here.  Worse...  the string has in fact gone through occasionally.  After messing with the code it suddenly works and keeps working and then stops.

Here is what I'm using to configure the serial port: 

#! /usr/bin/python2.7
import serial
from Tkinter import*
import time

   
root = Tk()
root.geometry("400x300")

main = Frame(root)   
main.pack()


def sendOnes():
   
    locations=['/dev/ttyUSB0','/dev/ttyUSB1']


    for device in locations:
        try:
            print "Trying...",device
            ser = serial.Serial(device, 9600, timeout=2)
            break
        except:
            print "Failed to connect on",device
           
    time.sleep( 2 )
    str1 = "#,1,1,1$"
    ser.write( str1 )
    time.sleep(1)

   
def sendOs():
   
    locations=['/dev/ttyUSB0','/dev/ttyUSB1']


    for device in locations:
        try:
            print "Trying...",device
            ser = serial.Serial(device, 9600, timeout=2)
            break
        except:
            print "Failed to connect on",device

    time.sleep( 2 )
    str2 = "#,0,0,0$"
    ser.write( str2 )
    time.sleep(1)

   
button1 = Button(root, text="Send 111", command=sendOnes)
button1.pack(anchor=CENTER)   

button2 = Button(root, text="Send 000", command=sendOs)
button2.pack(anchor=CENTER)

 
root.mainloop()

This gives me a gui with buttons so I can "send" repeatedly while looking at board leds.  I placed the additional time.sleep() just in case the machine(s) are taking a while to open the port.

My suspicion is that the linux system is ignoring the baudrate I specify and holding the USB port at some other speed ( I tried some other speeds to no avail).

If you have experience with this please share it with me as I have googled this topic to death and found nothing of use.


Hello were you able to sort out the problem.. I have tying a lot to send string via linux box but not successful yet.. Please help me if you can..
« Last Edit: July 31, 2013, 12:17:31 PM by ShannonBrady »