WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-22-2009, 03:19 AM
krimble krimble is offline
Member
 
Join Date: Nov 2006
Location: Nijmegen
Posts: 63
pyserial + vizard

Hi all,
I'm wondering if somebody can help me with a communication problem I have with a hardwareDevice connected to my serial port. We would like to connect a bike to Vizard and use the cycleData to control the camera. (we already have the protocol information and we are able to print correct data in Delphi)

I found the pyserial recommendation in the Worldviz-Knowledgebase. But I can't get it to work properly. When I try to print x nothing happens.

Does anybody have experience with pySerial in Vizard.

Thank you so much!

Code:
import serial 
import viztask

viz.go()

#hex(255)[2:] = ff
#int('ff',16) = 255

start_flag = int('F1',16)
stop_flag = int('F2',16)
cmdGetSpeed = int('A5',16)
cmdSetGear = int('2D',16)

ser = serial.Serial(
     port=0,
     parity=serial.PARITY_NONE,
     bytesize=serial.EIGHTBITS,
     stopbits=serial.STOPBITS_ONE,
     timeout=0,
     xonxoff=0,
     rtscts=0,
     baudrate=9600
   )


def mykeyboard(key):
	if key == "s" :
		viztask.schedule(serialComTask())


def serialComTask() :
	ser.write(start_flag)
	ser.write(cmdGetSpeed)
	ser.write(cmdGetSpeed)
	ser.write(stop_flag)
	print "sended"
	yield viztask.waitTime(2)
	print "waited 1 sec"
	x = ser.read(4) 
	print x

def onExit():
	print "quiting"
	ser.close() 			# close port
	pass

viz.callback(viz.KEYBOARD_EVENT,mykeyboard)
viz.callback(viz.EXIT_EVENT,onExit)
Reply With Quote
  #2  
Old 09-22-2009, 03:32 AM
Moh200jo Moh200jo is offline
Member
 
Join Date: Feb 2009
Posts: 99
try x=ser.readline()
Reply With Quote
  #3  
Old 09-22-2009, 05:44 AM
krimble krimble is offline
Member
 
Join Date: Nov 2006
Location: Nijmegen
Posts: 63
Hi Moh200jo,
thanks for your reply. But it doesn't make a difference.

Do you maybe already have written a vizardScript were you use pySerial in. If so, you would be really helpful if I could take a look at it.
If you don't want to post it here this is my email:
j.derks@psych.ru.nl

Thanks so much!

Farshizzo do you have an idea how to use pyserial?
Reply With Quote
  #4  
Old 09-22-2009, 11:04 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
What do you mean "nothing happens" when you call print x? Are you sure the data isn't just space characters? Try replacing print x with the following:
Code:
print 'Received',len(x),'bytes'
Reply With Quote
  #5  
Old 09-23-2009, 04:00 AM
krimble krimble is offline
Member
 
Join Date: Nov 2006
Location: Nijmegen
Posts: 63
Hi farshizzo,
now It's printing "Received 0 bytes". Is there maybe a script available were I can take a look at?
The baudrate etc. parameters are having the same values as in the delphi program. That's why I'm wondering if there's something wrong with the rest of my script.

Thanks!
Reply With Quote
  #6  
Old 09-23-2009, 05:31 AM
Moh200jo Moh200jo is offline
Member
 
Join Date: Feb 2009
Posts: 99
HI
I had a problem to send int data. So, I correct the problem is that pyserial does not work with int("FF",16) function. You can send Hex data to see if your code is correct or not, am sure you will find it working.
Plz Let me know if your code works.

Last edited by Moh200jo; 09-23-2009 at 05:33 AM.
Reply With Quote
  #7  
Old 09-23-2009, 07:31 AM
krimble krimble is offline
Member
 
Join Date: Nov 2006
Location: Nijmegen
Posts: 63
Hi all,

I think I'm on the right track :-). I changed the variables to the corresponding ascii codes. I'm sending and getting stuff back now. Now I have to check if the stuff I'm getting back is the right stuff :-) if you get what I mean.

start_flag = chr(241)
stop_flag = chr(242)
cmdGetSpeed = chr(165)
cmdSetGear = chr(45)

Thanks so much for your help! If I have more questions I will get back to you guys!
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Realistic Light and Shadows Using Vizard and 3DS Max jde Vizard 4 07-13-2012 10:58 AM
.3DS importing in Vizard and 3D Studio jde Vizard 1 08-28-2009 03:14 PM
Vizard tech tip: Using the Python Imaging Library (PIL) Jeff Vizard 0 03-23-2009 11:13 AM
Vizard tech tip: Text to Speech Jeff Vizard 1 01-15-2009 09:39 PM
Fall 2007 release of Vizard R3 3 D Announcements 0 10-15-2007 04:50 PM


All times are GMT -7. The time now is 02:15 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC