Quantcast
Channel: FedoraForum.org
Viewing all articles
Browse latest Browse all 36189

I cant use Serial.serial.read() on ubuntu12.04 but it is working fine on ubuntu10.04

$
0
0
I was using ubuntu 10.04 and now updating to ubuntu 12.04 but one of my python code was working fine in ubuntu 10.04 but not in ubuntu 12.04.(Ubuntu 10.04: python version = 2.6.5, Ubuntu 12.04: python version = 2.7.3)

Here is my code.

class FTSensor:
def __init__(self, dev, baudrate=19200):
print 'FTSensor: opening serial port (baudrate =', baudrate, ')'
self.ftcon = serial.Serial(dev,timeout =0.1)
print 'FTSensor: setting properties'
self.ftcon.setBaudrate(baudrate)
self.ftcon.setParity('N')
self.ftcon.setStopbits(1)
self.ftcon.open()

#self.RESET_INTERVAL=1.0 #seconds until transmittion is reset to fix bug
count = 0
self.reset_time = None
self.reset()
while not self._start_query():
rospy.logwarn('FTSensor: resetting')
count = count + 1
self.reset()
if count == 10:
rospy.logfatal('FTSensor.__init__: Too many resets. Try manually restarting FT sensors.')

#self.last_access = time.time()
self.last_value = []

def read(self):
#rospy.logwarn('READ')

current_value = self.last_value

#rospy.logwarn(current_value)

#rospy.logwarn('READ-BEFORE while')
while current_value == self.last_value:
#rospy.logwarn('READ-INSIDE while')
t = self.ftcon.read(19)
leng = t[0]
print leng
rospy.logwarn(t)
#if we get an error message, restart
if len(t) < 1 or ord(t[0]) != 0 or len(t) < 10:
rospy.logwarn('READ-WHILE-if')
#pass
#self.reset()
print 'exiting due to if len(t) < 1 or ord(t[0]) != 0 or len(t) < 10'
print 't is', t
exit()
while not self._start_query():
#self.reset()
print 'exiting due to not self._start_query()'
print 't is', t
exit()
break
else:
#rospy.logwarn('READ-WHILE-else')
current_value = t
#current_value = binary_to_ft(t)

self.last_value = current_value
return current_value

.... ... I did not put the main function but the one I highlighted(t = self.ftcon.read(19)) was the problem. From ubuntu 10.04 it was fine but from ubuntu 12.04, it gives strange values like "D R .cracked letter" The type of t is list so it wouldnt give me a number but I have no idea where D and R came from.

Is there something in particular I need to check? If there is, could you please explain in detail?

Thanks.

---------- Post added at 02:30 PM ---------- Previous post was at 02:27 PM ----------

Sorry I actually don't know how to upload the codes with indentation

Viewing all articles
Browse latest Browse all 36189

Trending Articles