![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
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$ |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Professional Programmer
|
Windows XP will not be happy about that program, it will most likeley crash.
__________________
JG-Webdesign |
|
|
|
|
|
#4 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
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. |
|
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#7 |
|
Expert Programmer
|
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). |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |