1 Replies - 4236 Views - Last Post: 15 April 2009 - 08:03 PM Rate Topic: -----

#1 manurevi047  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-April 09

writing decimal values to serial port using pyserial

Post icon  Posted 15 April 2009 - 12:58 AM

can any one please tell me how to write a decimal value to the serial port using pyserial..

i can have been able to detect inputs from the joystick using pygame..but i need to write the inputs got from there to the serial port...

the inputs from the joystick are in the form of integers..like 00 for button 1, 01 for button 2 etc...i need to write these decimal values to the serial port...but the code..

import serial
ser = serial.Serial('COM1')
ser.open()
ser.write('s')



ther ser.write() command can only output the string.. how can i write a decimal value in this case..plz help...

Is This A Good Question/Topic? 0
  • +

Replies To: writing decimal values to serial port using pyserial

#2 numerical_jerome  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 167
  • Joined: 16-September 07

Re: writing decimal values to serial port using pyserial

Posted 15 April 2009 - 08:03 PM

 
str(object)



will return a string coercion of said object... true story.

please note that 01 will probably output as the string "1", you might consider just using some flow control [if, elif, else], and operating only on strings.

Hope this helps,

-Jerome
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1