Giữ nguyên cơ chế giao tiếp giữa Windows, chúng tôi đã có trải nghiệm tích cực khi sử dụng các đường ống có tên là. Sử dụng Windows chồng chéo IO và mô-đun win32pipe
từ pywin32.
Bạn có thể tìm hiểu nhiều về win32 và python trong sách Python Programming On Win32.
Phần gửi chỉ cần viết tới r'\\.\pipe\mypipe'
.
Đối tượng nghe (ovpipe
) giữ đối tượng xử lý sự kiện và đợi thông báo có các sự kiện khác có thể liên quan đến việc gọi win32event.WaitForMultipleObjects
.
rc = win32event.WaitForMultipleObjects(
eventlist, # Objects to wait for.
0, # Wait for one object
timeout) # timeout in milli-seconds.
Dưới đây là một phần của python chồng chéo lớp nghe:
import win32event
import pywintypes
import win32file
import win32pipe
class ovpipe:
"Overlapped I/O named pipe class"
def __init__(self):
self.over=pywintypes.OVERLAPPED()
evt=win32event.CreateEvent(None,1,0,None)
self.over.hEvent=evt
self.pname='mypipe'
self.hpipe = win32pipe.CreateNamedPipe(
r'\\.\pipe\mypipe', # pipe name
win32pipe.PIPE_ACCESS_DUPLEX| # read/write access
win32file.FILE_FLAG_OVERLAPPED,
win32pipe.PIPE_TYPE_MESSAGE| # message-type pipe
win32pipe.PIPE_WAIT, # blocking mode
1, # number of instances
512, # output buffer size
512, # input buffer size
2000, # client time-out
None) # no security attributes
self.buffer = win32file.AllocateReadBuffer(512)
self.state='noconnected'
self.chstate()
def execmsg(self):
"Translate the received message"
pass
def chstate(self):
"Change the state of the pipe depending on current state"
if self.state=='noconnected':
win32pipe.ConnectNamedPipe(self.hpipe,self.over)
self.state='connectwait'
return -6
elif self.state=='connectwait':
j,self.strbuf=win32file.ReadFile(self.hpipe,self.buffer,self.over)
self.state='readwait'
return -6
elif self.state=='readwait':
size=win32file.GetOverlappedResult(self.hpipe,self.over,1)
self.msg=self.strbuf[:size]
ret=self.execmsg()
self.state = 'noconnected'
win32pipe.DisconnectNamedPipe(self.hpipe)
return ret
Có số lượng dữ liệu khổng lồ không? Bạn đang sắp xếp nó? Bản chất của dữ liệu là gì? –
Trong hầu hết các trường hợp, dữ liệu về điểm vĩ độ/dữ liệu điểm. Và tại thời điểm nó được chuyển trực tiếp thông qua COM, một cái gì đó như thế nào. AddPoint (lat, lon). – monkut