Beginner Pyserial Question
Hi Guys, I have a project where I'd like to save GPS data that is streamed to a Sony Vaio over bluetooth. I can monitor the data stream over Hyper Terminal, but I'd like to use python to capture it as well. I've installed Python 2.5, pyserial 2.2 and the appropriate pywin program (pywin32-210.win32-py2.5.exe). My problem comes when I try to open a serial port. After importing "serial", I issue the following statement: >>> GPS = serial.Serial(0) Traceback (most recent call last): File "", line 1, in GPS = serial.Serial(0) File "C:\Python25\lib\site-packages\serial\serialutil.py", line 156, in __init__ self.open() File "C:\Python25\lib\site-packages\serial\serialwin32.py", line 55, in open raise SerialException("could not open port: %s" % msg) SerialException: could not open port: (2, 'CreateFile', 'The system cannot find the file specified.') I'm not sure where the source of the problem is. I was wondering if someone could recognize what might be be. the Vaio is running XP SP2. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Pyserial Question
> My guess is that for whatever reason the 'first' serial port > (which is what you're asking for by specifying a 0 when > instantiating the Serial class) doesn't actually exist. Serial > device names under Windows are broken. I realize this. I tried connecting to different port "numbers", but I have not tried the serial.Serial(COM1). I wasn't sure if that worked, but I know a quick way to find out. > Try using the actual name of the com port (e.g. 'COM3' or > 'COM5') instead of 0. The com port used in Hyper Terminal is COM40. I have tried connecting to 39/40/41 to no avail. > Oh, if you end up having to use a com port higher than COM9, > that's broken in Windows as well, and you've got to sprinkle a > bunch of backslashes into the device name (I don't remember the > exact syntax). That might become an issue when I try to read COM40 for the GPS bluetooth transmission. This issue does not relate to why I cannot open smaller com ports, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Pyserial Question
I've solved the problem- Thanks for steering me in the right direction. The problem is that your traditional "COM1" does not exist on this computer (Thanks Grant). A trip to the Device manager listed all the COM ports on the computer. After successfully connecting to COM7 (port = serial.Serial(6)), I realized the reason I couldn't connect to COM40 was because it was tied up with hyper terminal. after closing everything, I was able to issue a readline and collect data. Thanks for the help! jimmy -- http://mail.python.org/mailman/listinfo/python-list
Beginner String formatting question
Hi all, I am trying to write a simple program that will accept an integral "time" input in the HHMMSS format and output a "HH:MM:SS" form. My code is as follows: import string def FormatTime(time): '''Converts an HHMMSS string to HH:MM:SS format.''' timeString = str(time) #converts the num to string hours= [timeString[0], timeString[1]] minutes = [timeString[2], timeString[3]] seconds = [timeString[4], timeString[5]] Ftime = "%s:%s:%s",(hours,minutes,seconds) clock = Ftime.join() return clock === when I run it from IDLE, I get this: >>> Format.FormatTime(time) ['1', '1', ':', '2', '2', ':', '3', '3'] ['1', '1', ':', '2', '2', ':', '3', '3'] My questions- 1) Why is this function printing out twice? 2)It may be a formatting issue, but I want to have the output as "HH:MM:SS", rather than having it broken out into each cell. I thought the 'join' command would do this, but I must not be using it properly/understanding something. 3)as a side note, I've noticed that the parameter "time" passed in must be passed in as a string, otherwise I receive an error that "time" is unsubscriptable. Am I unable to pass in an int and then convert it to a string within the function with str()? I've been at this for a while, so I may not be able to see the forest through the trees at this point. I'd greatly appreciate any suggestions or instruction on these mistakes. Best, Jimmy -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner String formatting question
I apologize for the lack of details in my last post. This time formatting program is a piece of a larger program I am trying to write to de-clutter GPS transmission. I have a GPS receiver that transmits its readings via bluetooth. I've been able to use pySerial and store X number of bytes, then write that to a file (the next step will be finding a way to write the stream to a file directly). The raw GPS data is tranmitted in the NMEA format (http://vancouver-webpages.com/ peter/nmeafaq.txt): $GPRMC,024830,V,,N,,E,,,260108,,,N*58 $GPVTG,,T,,M,,N,,K,N*2C $GPGGA,024831,LAT_GOES_HERE,N,LONG_GOES_HERE,E,0,00,,,M,,M,,*61 $GPGSA,A,1,,,*1E $GPGSV,3,1,09,09,,,37,13,,,00,18,,,00,23,,,00*75 $GPGSV,3,2,09,01,,,00,29,,,00,14,,,00,26,,,00*7A $GPGSV,3,3,09,12,,,00*73 $GPRMC,024831,V,LAT_GOES_HERE,N,LONG_GOES_HERE,E,,,260108,,,N*59 $GPVTG,,T,,M,,N,,K,N*2C the "$GPGGA" and "$GPRMC" lines are the ones that will give you your Latitude and Longitude data --or the would if I had a signal. All the entries are comma delimited, so I used the split(',') function to parse the appropriate statements. Here's the code for that: = input = open('c:\sample_readout.txt','r') #location of the Raw GPS data output = open('c:\GPSout.txt', 'w') output.write("Timestamp \t Latitude \t Longitude \t Velocity") s = input.readlines() for line in s: if line.startswith('$GPGGA'): InputTuple = line.split(',') time = InputTuple[1] lat = InputTuple[2]+' '+InputTuple[3] long = InputTuple[4]+' '+InputTuple[5] out = '\n '+ time + '\t\t' + lat + '\t\t\t' + long output.writelines(out) elif line.startswith('$GPRMC'): InputTuple = line.split(',') time = InputTuple[1] lat = InputTuple[3]+' '+InputTuple[4] long = InputTuple[5]+' '+InputTuple[6] out = '\n '+ time + '\t\t' + lat + '\t\t\t' + long output.writelines(out) elif line.startswith('$GPVTG'): #this will give grounp speed in knts and [7] gives kmph InputTuple = line.split(',') out = '\n ' + '\t\t' + InputTuple[5] output.writelines(out) input.close() output.close() The time stamp for both the GPRMC and GPGGA lines will be stored in InputTuple[1]. Right now, this program will read the GPS data file and pull out the necessary information. I wanted the Format.py program to function as a module so that I could call Format.FormatTime(time) to change the HHMMSS GPS data to HH:MM:SS, for readability. The next step was to write a FormatCoord function (within the Format module) to do the same for lat/long data. Now that I've explained the structure, the argument of Format.FormatTime() will be InputTuple[1] (the timestamp). I want to be able to call that function in the GPS program to read the contents of InputTuple[1] and write the HH:MM:SS data to the file. I've incorporated some of your recommendations into my program already and it looks much better. Thanks to everyone for your suggestions. Jimmy -- http://mail.python.org/mailman/listinfo/python-list