473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

win32file.AllocateReadBuffer

Still hacking pygarmin (eTrex GPS wrapper). Can anyone help explain the following snippet:

def read(self, n):
buffer = win32file.AllocateReadBuffer(n)
rc, data = win32file.ReadFile(self.f, buffer)
## if len(data) != n:
## raise LinkException, "time out";
return data

I had some problems reading from a GPS device until I commented out those two lines. Can anyone explain 1) why they're there at all and/or 2) potential side-effects I'm going to run into by commenting them out? Everything I've read seems to indicate that the AllocateReadBuffer/ReadFile pair blocks--so under what circumstances will n != len(data)?

OR, should I instead check the value of rc for errors like this:
try:
hr, data = win32file.ReadFile(srcHandle, buffer)
if hr == winerror.ERROR_HANDLE_EOF:
break
except pywintypes.error, e:
if e.args[0] == winerror.ERROR_BROKEN_PIPE:
break
else:
raise e

OR, should I go with my "other rewrite", which doesn't pre-alloc:

data = ""
while 1:
rc, chars = win32file.ReadFile(self.f, n, None)
data += chars
if len(data) >= n:
break
if len(chars) == 0:
raise LinkException, "timeout"
return data
Not a windows guru by any means,

Robert Brewer
MIS
Amor Ministries
fu******@amor.org

Jul 18 '05 #1
0 1832

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jim | last post by:
Hi, All I am using python (activestate 2.2.2-224) on XP home and have suddenly got the following error from a file which worked fine under millenium. File...
2
by: Nir of the Waves | last post by:
In windows platforms how can I make two processes hold two ends of the same pipe? os.pipe() returns reader and writer descriptors but how do I export one of the ends to another process? ...
0
by: Robert Brewer | last post by:
Hello, I realize I'm a bit over my head, here, but I'm trying to pull waypoint data from a Garmin eTrex Legend, and having mixed success. On a Win98 box last night, I was able to connect and...
0
by: yamadora1999 | last post by:
'''######################################################################### GetQueuedCompletionStatus is return new OVERLAPPED instaed requested OVERLAPPED. And OVERLAPPED.object member is lost....
1
by: me | last post by:
Hello python world. Since yesterday I'm using Python 2.4/PythonWin (build 203) on my Win98 system. My problem - that did not occured in the previous version Python 2.3.4/PythonWin (build 163) -...
16
by: dario | last post by:
Hi, Im new on phyton programming. On my GPRS modem with embedded Phyton 1.5.2+ version, I have to receive a string from serial port and after send this one enclosed in an e-mail. All OK if the...
2
by: Jim | last post by:
I'm not sure how to perform this operation in Python. The difficulty is in knowing the size of the output buffer: if it is too small, I get an "insufficient buffer" exception; too large, and I get...
4
by: jim-on-linux | last post by:
Where can I download win32file / win32ui? The links below are broken. Mark Hammond should be made aware of this. URL below has two links that send you no place...
3
by: Ron Jackson | last post by:
I am using Python 2.5 on Windows XP. I have installed Pyserial and win32all extensions. When I try to run the example program scan.py (included below), or any other program using pyserial, as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.