LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-31-2008, 11:40 AM   #1
jabfinger
Member
 
Registered: Jan 2004
Location: USA, Pa
Distribution: Gentoo, Fedora Core 3, Mepis, Vector
Posts: 83

Rep: Reputation: 15
Craeting a serial program with Python


Hello,

Its been a while since I have posted and today I am posting about
some problems I am having with a program I am attempting to Create
with Python. As you can see it will be running on a windows platform
(2000). What it is supposed to do is capture data over a serial line from
a WYSE 50 terminal when the WYSE Shift + Print keys are pressed,
put that data into a file, and finally open the file with notepad to make
edits and print the data. The WYSE terminal is set up to send data over
the AUX port at 9600 baud. If using Procom Plus to perform this function,
it (Pro Com) is set 9600,8,none,1 and works flawlessly. I have been testing my program using a garmin gps with a serial out and all seems fine using the gps device, but when connected to the WYSE the data is all Jibberishy with smiley faces. Some data does appear but not as it should. I am using pyserial, in the program so I got a copy of Chris Liechti's miniterm.py program, tried it, and it works fine for viewing the serial data from the WYSE.

Maybe you guys could look over my code and see where I have gone astray. I have been all over the web reading and have not been able to come up with a solution. I am a beginer at progrmaming so please be gentel.

Code:

Code:
#!/usr/bin/python

#_____________________import necessary modules__________________________ 

import sys, os, serial, msvcrt

print "Welcom to the GPS Weekly Program. \n\n\n\n"
print "Data collection begins upon entering your name in this terminal. \n"
print "After you have entered your name you may use the Shift + print \n"
print "keys on the WYSE terminal as normal to collect data. \n\n "
print "After you have collected the weekly data press the \"d\" key, \n"
print "pressing any other key during data collection will exit the program\n"
print "imediatly and the collection program will have to be restarted.\n\n\n" 
name = raw_input('Enter your name>>>')
os.system('cls')


gpslog = open('GPS-9_Log.txt', 'w')
gpslog.write('GPS-9 Weekly Performed by ' + name + '\n \n')
gpslog.close()

def write():
    s = serial.Serial(port=0, parity=serial.PARITY_NONE, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE, timeout=3, baudrate=9600)
#_________________________Write data to GPS-9.txt______________________
    s.flushInput()
    s.flushOutput()
    gpsdata = s.readline()
    gpslog = open('GPS-9_Log.txt', 'a')
    gpslog.write(gpsdata)
    print gpsdata	
    gpslog.close()
    s.close()
        
    
#__________________Loop write() until "d" is pressed____________________
while not msvcrt.kbhit():
    write()

#_________Stop the loop clear the screen and pop open the text editor__
if msvcrt.getch() == 'd':
    os.system('cls')
    print "Data collection is now complete.\n\n\n"
    input = raw_input('Press Enter to continue>>>')
os.system('start ' + 'GPS-9_Log.txt')

Thanks guys.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read data coming from serial connected procurve 2524 with python Tanc Programming 3 11-07-2012 06:44 AM
First Python Program dudeman41465 Programming 3 01-21-2006 02:22 PM
craeting a boot image when I don't have a floppy drive jomy Linux - Networking 15 02-02-2005 12:53 PM
Making a Python program gamehack Programming 0 04-11-2004 05:12 AM
craeting a boot floppy kaustav Linux - General 4 11-22-2002 12:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration