The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Pyserial help
Discuss Pyserial help in the Python Programming forum on Dev Shed. Pyserial help Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 13th, 2012, 01:14 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 11
Time spent in forums: 1 h 39 m 35 sec
Reputation Power: 0
|
|
|
Pyserial help
Ok so I have code that will print out the value of the slider to idle every 100 ms but how can i send this value to the serial port.
My current code looks like this:
Quote: import serial
import time
import Tkinter
ser = serial.Serial('/dev/tty.usbmodem1411', 9600)
time.sleep(2)
root = Tkinter.Tk()
w = Tkinter.Scale(root, from_=0, to=100)
w.pack()
def show_slider(root,w):
millisecond = 1
print(w.get())
root.after(100*millisecond,show_slider,root,w)
show_slider(root,w)
root.mainloop() |
|

December 13th, 2012, 11:17 AM
|
 |
Contributing User
|
|
|
|
|
For python code please use [code] tags instead of [quote] tags.
I expect you'd open a file and write to it. On DOS the file might be called COM1, SER1, or even LPT1:
In unix I expect the file would be accessible somewhere in /dev . Haven't done it. (In 1983 I wrote a BASICA program that communicated with a serial device. Come to think of it, I also worked on a FORTRAN program that communicated with an external device with that microcomputer operating system that preceded DOS.)
__________________
[code] Code tags[/code] are essential for python code!
|

December 13th, 2012, 08:09 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 11
Time spent in forums: 1 h 39 m 35 sec
Reputation Power: 0
|
|
[QUOTE=b49P23TIvg]For python code please use [code] tags instead of Quote: tags.
I expect you'd open a file and write to it. On DOS the file might be called COM1, SER1, or even LPT1:
In unix I expect the file would be accessible somewhere in /dev . Haven't done it. (In 1983 I wrote a BASICA program that communicated with a serial device. Come to think of it, I also worked on a FORTRAN program that communicated with an external device with that microcomputer operating system that preceded DOS.) |
Haha sorry. I have the path to the microcontroller setup in the code and i can write to the serial port (ser.write("hello")) but i need the value of the scale to go to the serial port. Not the IDLE.
and i cant just put ser.write(w.get()) like i thought i would be able to, i get an error.
I'm so confused haha. Thanks
|

December 13th, 2012, 08:59 PM
|
 |
Contributing User
|
|
|
|
|
Oh! Sorry, you do have
ser = serial.Serial('/dev/tty.usbmodem1411', 9600)
OK, so the problem may be data type. w.get() returns an integer.
ser.write(str(w.get()))
and of course that still might not work because Serial may need bytes.
Anyway, the problem may be data type. When debugging python the data type is often more useful to know than a human representation.
|

December 15th, 2012, 01:15 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 11
Time spent in forums: 1 h 39 m 35 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by b49P23TIvg Oh! Sorry, you do have
ser = serial.Serial('/dev/tty.usbmodem1411', 9600)
OK, so the problem may be data type. w.get() returns an integer.
ser.write(str(w.get()))
and of course that still might not work because Serial may need bytes.
Anyway, the problem may be data type. When debugging python the data type is often more useful to know than a human representation. |
Yes! it worked thankyou 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|