Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 20th, 2006, 3:44 PM   #1
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Serial Communication: BASIC to Python

This thread is essentially a continuation of this one; however, my problem now is translating BASIC code to Python.

I got ahold of a small piece of BASIC code someone was using to communicate with the device I described which connected to the serial port:

INPUT ; "Enter filename to save data- ", outfile$
OPEN outfile$ FOR OUTPUT AS #1

OPEN "COM1:9600,O,7,1" FOR RANDOM AS #2
PRINT #2, "01,TEMP?"
INPUT #2, A$, B$
INPUT #2, C$, D$, E$, F$

PRINT #1, TIME$, C$, D$, E$, F$
If it's possible to do this in just a few lines of BASIC code, it doesn't make sense to me that it should require an entire module (eg, PySerial) to do the same thing in Python. Is there a simpler way to translate this? Thanks for any input.
titaniumdecoy is offline   Reply With Quote
Old Jul 20th, 2006, 4:07 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Have you tried that BASIC program on your XP machine??
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 20th, 2006, 4:12 PM   #3
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 417
Rep Power: 4 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Windows XP will not be happy about that program, it will most likeley crash.
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Old Jul 20th, 2006, 4:15 PM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by titaniumdecoy
If it's possible to do this in just a few lines of BASIC code, it doesn't make sense to me that it should require an entire module (eg, PySerial) to do the same thing in Python.
The functionality is obviously built into that version of BASIC, both because BASIC was a language that had a lot of built in functionality, and because serial ports were a commonly used interface when the language was developed.

Python came along much later, when it became fashionable to have libraries and modules, rather than inbuilt functionality, and when serial ports had become more or less obsolete.

Just because functionality is inbuilt into a language, doesn't mean it doesn't have overhead. At least when something is an external module you have a choice whether to use it or not.
Arevos is offline   Reply With Quote
Old Jul 20th, 2006, 4:16 PM   #5
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
What platform does that code run under? This is closets I could find to explaining that function call, it is for m the help manual for liberty basic. Which is windows only. Both python modules are portable on windows,linux and mac.

Using USPP I think the code translates (roughly) to:
from uspp import *
from time import strftime

tty=SerialPort("COM1", 1000, 9600) 
tty.write("01,TEMP?")  
a = tty.read()
b = tty.read()
c = tty.read()
d = tty.read()
e = tty.read()
f = tty.read()

print '%s %d %d %d %d' % (strftime(''%H:%M:%S')c,d,e,f)

Because I can't get the refernce material online, I am not sure I am using the read method properly.

Last edited by Game_Ender; Jul 20th, 2006 at 4:27 PM.
Game_Ender is offline   Reply With Quote
Old Jul 20th, 2006, 4:40 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
The reason I asked if that BASIC runs is that the code appears to date back to real-mode days, when one could access ports directly. That is no longer the case. For that to run, the interpreter would have to drop out of protected mode, just as driver or kernel code has to.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 20th, 2006, 4:46 PM   #7
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
This is all very interesting. It sounds like PySerial/USPP is the way to go.

And Dawei, I don't know if it runs because I haven't had a chance to connect the device to my computer yet (It's very large).
titaniumdecoy is offline   Reply With Quote
Old Jul 20th, 2006, 5:09 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You would have to have a BASIC interpreter (with or without a BASCOM) to use it, anyway. That code indicates that the equipment is rather straightforward, anyway. I have a link here somewhere to serial access via C/C++, but I'm not finding it. I'd probably use Python, though, if it were me.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
[tutorial] Python for programming beginners coldDeath Python 30 Dec 14th, 2005 11:35 AM
Advanced Python Tricks Arevos Python 19 Sep 24th, 2005 7:39 AM
[ANN] New script engine (Basic sintax) MKTMK C++ 3 Sep 1st, 2005 5:51 PM
Python - A Programmers Introduction coldDeath Python 17 Aug 19th, 2005 12:41 PM
Serial Communication Automatik C++ 2 May 19th, 2005 9:30 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:49 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC