Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e4646076
authored
Sep 10, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace line endings anf fix reading bug
parent
5e32d6a6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
9 deletions
+10
-9
w32serial.py
+10
-9
No files found.
w32serial.py
View file @
e4646076
...
@@ -28,9 +28,8 @@ class SerialPort(abstract.FileDescriptor):
...
@@ -28,9 +28,8 @@ class SerialPort(abstract.FileDescriptor):
connected
=
1
connected
=
1
def
__init__
(
self
,
protocol
,
deviceNameOrPortNumber
,
reactor
):
def
__init__
(
self
,
protocol
,
deviceNameOrPortNumber
,
reactor
):
#self._serialFactory = VirtioSerial
self
.
hComPort
=
win32file
.
CreateFile
(
#self._serial = self._serialFactory(port=deviceNameOrPortNumber)
deviceNameOrPortNumber
,
self
.
hComPort
=
win32file
.
CreateFile
(
deviceNameOrPortNumber
,
win32con
.
GENERIC_READ
|
win32con
.
GENERIC_WRITE
,
win32con
.
GENERIC_READ
|
win32con
.
GENERIC_WRITE
,
0
,
# exclusive access
0
,
# exclusive access
None
,
# no security
None
,
# no security
...
@@ -80,13 +79,16 @@ class SerialPort(abstract.FileDescriptor):
...
@@ -80,13 +79,16 @@ class SerialPort(abstract.FileDescriptor):
self
.
_overlappedRead
,
self
.
_overlappedRead
,
0
)
0
)
except
:
except
:
import
time
time
.
sleep
(
10
)
n
=
0
n
=
0
if
n
:
if
n
:
first
=
str
(
self
.
read_buf
[:
n
])
first
=
str
(
self
.
read_buf
[:
n
])
# now we should get everything that is already in the buffer
# now we should get everything that is already in the buffer (max
# 4096)
win32event
.
ResetEvent
(
self
.
_overlappedRead
.
hEvent
)
win32event
.
ResetEvent
(
self
.
_overlappedRead
.
hEvent
)
rc
,
buf
=
win32file
.
ReadFile
(
self
.
hComPort
,
rc
,
buf
=
win32file
.
ReadFile
(
self
.
hComPort
,
win32file
.
AllocateReadBuffer
(
n
),
win32file
.
AllocateReadBuffer
(
4096
),
self
.
_overlappedRead
)
self
.
_overlappedRead
)
n
=
win32file
.
GetOverlappedResult
(
n
=
win32file
.
GetOverlappedResult
(
self
.
hComPort
,
self
.
hComPort
,
...
@@ -94,12 +96,11 @@ class SerialPort(abstract.FileDescriptor):
...
@@ -94,12 +96,11 @@ class SerialPort(abstract.FileDescriptor):
1
)
1
)
# handle all the received data:
# handle all the received data:
self
.
protocol
.
dataReceived
(
first
+
str
(
buf
[:
n
]))
self
.
protocol
.
dataReceived
(
first
+
str
(
buf
[:
n
]))
# set up next one
# set up next one
win32event
.
ResetEvent
(
self
.
_overlappedRead
.
hEvent
)
win32event
.
ResetEvent
(
self
.
_overlappedRead
.
hEvent
)
# rc, self.read_buf = win32file.ReadFile(self.hComPort,
rc
,
self
.
read_buf
=
win32file
.
ReadFile
(
self
.
hComPort
,
# win32file.AllocateReadBuffer(1),
win32file
.
AllocateReadBuffer
(
1
),
# self._overlappedRead)
self
.
_overlappedRead
)
def
write
(
self
,
data
):
def
write
(
self
,
data
):
if
data
:
if
data
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment