📄 wpw_w32_comm_95.html
字号:
<HTML>
<HR><A NAME=WIN32_COMM_PROB>
Return to <a href="wpw_w32_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: Problem with COMM API in w32s</H4><PRE>
WIN32S does not yet support comm ports directly. The easiest way to do
this currently is to use universal thunks to get to the WIN16 comms API.
Not very nice :-(
Paul Stewart (ultracch@ix.netcom.com) wrote:
: I having problems opening a COM port in Win32s. I'm using the example
: in the (Borland) Win32 API help that uses the CreateFile function. It
: returns a handle ok, but when I try to do a GetCommState, that function
: fails. GetLastError returns 120, but I don't know what that means (I
: guess that means I need a list of possible error codes returned from
: GetLastError, too).
: Is the problem the fact that I'm using Win32s and not running my app in
: Windows95?
: Thanks for your help
: Paul Stewart
: UltraCoach Software Development
</PRE>
<HR><A NAME=WIN32_COMM_READ>
Return to <a href="wpw_w32_index.html#TOC">Table of Contents for this chapter</a><br>
<H4>Subject: How to read Comm port under Win32?</H4><PRE>
Mark Long (long) wrote:
> I know this should be trivial, but I'm new
> to windows and I'm having trouble find the proper
> way to open and read a comm port under Visual C
> and Windows NT, on a 486.
It is trivial. Just not well documented in the help files.
Opening the file is a matter of just opening a special
com device file:
hPort=CreateFile("COM1",GENERIC_READ|GENERIC_WRITE,0,NULL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
Other keywords you'll need to look up
SetupComm()
GetCommState()
SetCommState()
GetLastError()
WriteFile()
ReadFile
GetCommMask()
SetCommMask()
PurgeComm()
ClearCommError () //lets you find out the size of the input queue...
SetCommTimeouts()
Basically, once you've opened the port and set it up, you can then use
blocking reads to wait for data on the port, or play with
SetCommTimeouts so that the read block briefly or not at all.
You can then either poll the port (old win30 style) or just have a
separate thread which reads the data and processes it or forwards it
(somehow) to the main thread to deal with.
BTW: I found that using WaitEvent() to get the port to signal when data was
ready didn't work -even when the port was opened for reading only.
Apart from that win32 API comms port handling is a lot nicer than in
win31 as your thread doesn't ever block during window drag or resize.
-Steve
<HR>
Mark Long <long> wrote:
>I know this should be trivial, but I'm new
>to windows and I'm having trouble find the proper
>way to open and read a comm port under Visual C
>and Windows NT, on a 486. Searching on all the
>usual Unix and Dos keywords gives me nothing.
>I've looked through the archives, seems like
>this should be out there. I just need to suck
>in the data, (prefer buffered) and feed a OpenGL
>animation.
Search your win32 help for a chapter called "communications" (I
think). Win32 has no serial port API; you use the CreateFile()/
ReadFile()/WriteFile() API. Buffering is configurable and builtin.
The win16 way was OpenComm(), but that's history.
</PRE>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -