Commit 639bea37c5c015f961f77d2683a83882a8ad6f6d

Authored by xiemeng
1 parent 725f6c31

更新代码注释

... ... @@ -23,7 +23,9 @@
23 23 SetupCommPort - 第一次打开港口
24 24 WaitForThreads - 设置线程退出事件并等待工作线程退出
25 25 BreakDownCommPort - 关闭与comm端口的连接
26   - DisconnectOK - 询问用户是否可以断开连接
  26 + DisconnectOK - 询问用户是否可以断开连接
  27 + QuerySingleSerialPortEx(int nPort) - 查询指定端口状态
  28 + QuerySerialPortStatusEx - 查询指定范围端口状态
27 29
28 30 -----------------------------------------------------------------------------*/
29 31
... ... @@ -182,6 +184,7 @@ void InitNewFont(LOGFONT LogFont, COLORREF rgbColor)
182 184 TTYInfo.lfTTYFont = LogFont;
183 185 TTYInfo.hTTYFont = CreateFontIndirect(&(TTYInfo.lfTTYFont));
184 186 TTYInfo.rgbFGColor = rgbColor;
  187 + TTYInfo.rgbBGColor = RGB(255,255,255);
185 188
186 189 hDC = GetDC( ghwndMain ) ;
187 190 SelectObject( hDC, TTYInfo.hTTYFont ) ;
... ... @@ -213,9 +216,7 @@ HISTORY: Date: Author: Comment:
213 216 -----------------------------------------------------------------------------*/
214 217 BOOL InitTTYInfo()
215 218 {
216   - //
217   - // initialize generial TTY info
218   - //
  219 +
219 220 TTYInfo.hCommPort = NULL ;
220 221 TTYInfo.fConnected = FALSE ;
221 222 TTYInfo.fLocalEcho = FALSE ;
... ... @@ -236,7 +237,7 @@ BOOL InitTTYInfo()
236 237 TTYInfo.fDisplayErrors = TRUE ;
237 238
238 239 //
239   - // timeouts
  240 + // 超时
240 241 //
241 242 TTYInfo.timeoutsnew = gTimeoutsDefault;
242 243
... ... @@ -380,29 +381,27 @@ HANDLE SetupCommPort()
380 381 ErrorReporter("GetCommTimeouts");
381 382
382 383 //
383   - // Set port state
  384 + // 重连COM口连接
384 385 //
385 386 UpdateConnection();
386 387
387 388 //
388   - // set comm buffer sizes
  389 + // 设置通信缓冲区大小
389 390 //
390 391 SetupComm(TTYInfo.hCommPort, MAX_READ_BUFFER, MAX_WRITE_BUFFER);
391 392
392 393 //
393   - // raise DTR
394   - //
  394 + // 将DT&线路升成高电位。
  395 + // 参考后面注释
395 396 if (!EscapeCommFunction(TTYInfo.hCommPort, SETDTR))
396 397 ErrorReporter("EscapeCommFunction (SETDTR)");
397 398
398 399 //
399   - // start threads and set initial thread state to not done
  400 + // 启动线程并将初始线程状态设置为not done
400 401 //
401 402 StartThreads();
402 403
403   - //
404   - // set overall connect flag
405   - //
  404 + //设置连接标志
406 405 TTYInfo.fConnected = TRUE ;
407 406
408 407 return TTYInfo.hCommPort;
... ... @@ -412,15 +411,15 @@ HANDLE SetupCommPort()
412 411
413 412 FUNCTION: WaitForThreads(DWORD)
414 413
415   -PURPOSE: Waits a specified time for the worker threads to exit
  414 +PURPOSE: 等待指定时间让工作线程退出
416 415
417 416 PARAMETERS:
418   - dwTimeout - milliseconds to wait until timeout
  417 + dwTimeout - 等待超时的毫秒数
419 418
420 419 RETURN:
421   - WAIT_OBJECT_0 - successful wait, threads are not running
422   - WAIT_TIMEOUT - at least one thread is still running
423   - WAIT_FAILED - failure in WaitForMultipleObjects
  420 + WAIT_OBJECT_0 - 成功等待,线程没有运行
  421 + WAIT_TIMEOUT - 至少有一个线程仍在运行
  422 + WAIT_FAILED - failure in WaitForMultipleObjects 参考文档末尾注释
424 423
425 424 HISTORY: Date: Author: Comment:
426 425 10/27/95 AllenD Wrote it
... ... @@ -435,10 +434,9 @@ DWORD WaitForThreads(DWORD dwTimeout)
435 434 hThreads[1] = TTYInfo.hWriter;
436 435
437 436 //
438   - // set thread exit event here
439   - //
  437 + // 设置线程终止句柄
  438 + // 两个线程 读线程和写线程
440 439 SetEvent(ghThreadExitEvent);
441   -
442 440 dwRes = WaitForMultipleObjects(2, hThreads, TRUE, dwTimeout);
443 441 switch(dwRes)
444 442 {
... ... @@ -448,13 +446,12 @@ DWORD WaitForThreads(DWORD dwTimeout)
448 446 break;
449 447
450 448 case WAIT_TIMEOUT:
451   -
  449 + //读线程
452 450 if (WaitForSingleObject(TTYInfo.hReaderStatus, 0) == WAIT_TIMEOUT)
453 451 OutputDebugString("Reader/Status Thread didn't exit.\n\r");
454   -
  452 + //写线程
455 453 if (WaitForSingleObject(TTYInfo.hWriter, 0) == WAIT_TIMEOUT)
456 454 OutputDebugString("Writer Thread didn't exit.\n\r");
457   -
458 455 break;
459 456
460 457 default:
... ... @@ -474,15 +471,13 @@ DWORD WaitForThreads(DWORD dwTimeout)
474 471
475 472 FUNCTION: BreakDownCommPort
476 473
477   -PURPOSE: Closes a connection to a comm port
  474 +PURPOSE: 关闭对comm端口的连接
478 475
479 476 RETURN:
480   - TRUE - successful breakdown of port
  477 + TRUE - 成功关闭港口
481 478 FALSE - port isn't connected
482 479
483   -COMMENTS: Waits for threads to exit,
484   - clears DTR, restores comm port timeouts, purges any i/o
485   - and closes all pertinent handles
  480 +COMMENTS: 等待线程退出,清除DTR,恢复通信端口超时,清除任何i/o并关闭所有相关句柄
486 481
487 482 HISTORY: Date: Author: Comment:
488 483 10/27/95 AllenD Wrote it
... ... @@ -496,34 +491,20 @@ BOOL BreakDownCommPort()
496 491 TTYInfo.fConnected = FALSE;
497 492
498 493 //
499   - // wait for the threads for a small period
  494 + // 等待线程一小段时间
500 495 //
501 496 if (WaitForThreads(20000) != WAIT_OBJECT_0)
502   - /*
503   - if threads haven't exited, then they will
504   - interfere with a new connection. I must abort
505   - the entire program.
506   - */
  497 + //如果线程还没有退出,那么它们将退出 干扰一个新的连接。 必须中止 整个程序。
507 498 ErrorHandler("Error closing port.");
508   -
509   - //
510   - // lower DTR
511   - //
  499 + // 将DTR线路降成低电位。
512 500 if (!EscapeCommFunction(TTYInfo.hCommPort, CLRDTR))
513 501 ErrorReporter("EscapeCommFunction(CLRDTR)");
514   -
515   - //
516 502 // restore original comm timeouts
517   - //
518 503 if (!SetCommTimeouts(TTYInfo.hCommPort, &(TTYInfo.timeoutsorig)))
519 504 ErrorReporter("SetCommTimeouts (Restoration to original)");
520   -
521   - //
522   - // Purge reads/writes, input buffer and output buffer
523   - //
  505 + // 清除读取/写入,输入缓冲区和输出缓冲区
524 506 if (!PurgeComm(TTYInfo.hCommPort, PURGE_FLAGS))
525 507 ErrorReporter("PurgeComm");
526   -
527 508 CloseHandle(TTYInfo.hCommPort);
528 509 CloseHandle(TTYInfo.hReaderStatus);
529 510 CloseHandle(TTYInfo.hWriter);
... ... @@ -535,7 +516,7 @@ BOOL BreakDownCommPort()
535 516
536 517 FUNCTION: DisconnectOK
537 518
538   -PURPOSE: Asks user if it is OK to disconnect
  519 +PURPOSE: 询问用户是否可以断开连接
539 520
540 521 RETURN:
541 522 TRUE - OK to disconnect
... ... @@ -547,12 +528,15 @@ HISTORY: Date: Author: Comment:
547 528 -----------------------------------------------------------------------------*/
548 529 BOOL DisconnectOK()
549 530 {
550   - if (!TTYInfo.fConnected)
551   - return TRUE;
552   -
  531 + if (!TTYInfo.fConnected) return TRUE;
553 532 return ((MessageBox(ghwndMain, "OK to Disconnect?", gszPort, MB_YESNO)) == IDYES);
554 533 }
555 534
  535 +/*-----------------------------------------------------------------------------
  536 +FUNCTION: QuerySingleSerialPortEx
  537 +
  538 +PURPOSE: 查询指定端口状态
  539 +-----------------------------------------------------------------------------*/
556 540
557 541
558 542 BOOL QuerySingleSerialPortEx(int nPort)
... ... @@ -586,8 +570,15 @@ BOOL QuerySingleSerialPortEx(int nPort)
586 570 return bValid;
587 571 }
588 572
589   -//利用API查询指定范围内的串口状态信息,并分别返回指定范围内系统存在的串口,
590   -//当前未被占用的可用串口,已被占用的串口和系统不存在的串口
  573 +
  574 +/*-----------------------------------------------------------------------------
  575 +FUNCTION: QuerySingleSerialPortEx
  576 +
  577 +PURPOSE: 查询指定范围端口状态
  578 +利用API查询指定范围内的串口状态信息,并分别返回指定范围内系统存在的串口,
  579 +当前未被占用的可用串口,已被占用的串口和系统不存在的串口
  580 +*/
  581 +
591 582 void QuerySerialPortStatusEx(int *AryNoneOpenedPort,int nStartPort,int nLastPort)
592 583 {
593 584 char strTmp[50],strComm[50],strFree[50];
... ... @@ -626,3 +617,196 @@ void QuerySerialPortStatusEx(int *AryNoneOpenedPort,int nStartPort,int nLastPor
626 617 }
627 618
628 619 }
  620 +
  621 +
  622 +/*
  623 +代码说明
  624 +EscapeCommFunction()函数
  625 +指示指定的通信设备执行扩展功能。
  626 +BOOL EscapeCommFunction(
  627 + HANDLE hFile, //通信设备的句柄
  628 + DWORD dwFunc //指定执行的功能
  629 +);
  630 +hFile:串行端口的Handle值,此值即为使用createFile函数后所返回的值。
  631 +dwFunc:指定串行端口必须完成的工作,由以下的常数数值组成:
  632 +CLRDTR:将DTR线路降成低电位。
  633 +CLRRTS:将RTS线路降成低电位
  634 +SETDTR:将DT&线路升成高电位。
  635 +SETRTS:RTS线路升成高电位
  636 +SETXOFF:当接收到Xoff字符时启动传输操作。
  637 +SETXON:当接收到Xon字符时启动传蝓作。
  638 +SETBREAK:没置道信状态为中断(送出Break信号)。
  639 +CLRBREAK:清除 Break信号,使传输动作继续。
  640 +请特别注意到上述的参数,包有DTR、RTS的线路控制指令,如果要个别地控制这两条线路的高低电位状态就需要硬用这个函数。
  641 +
  642 +
  643 +
  644 +GetCommState()函数功能,使用指定通信设备的当前控制设置填充设备控制块(DCB结构)
  645 +BOOL GetCommState( HANDLE hFile, LPDCB lpDCB );
  646 +参数
  647 +hFile [in]由CreateFile函数返回的通信设备句柄。
  648 +lpDCB [out]指向返回控制设置数据的DCB结构的长指针。
  649 +typedef struct _DCB { //DCB结构声明
  650 + DWORD DCBlength; DCB结构的长度
  651 + DWORD BaudRate; 当前波特率
  652 + DWORD fBinary: 1; 二进制模式,无EOF检查
  653 + DWORD fParity: 1; 激活奇偶校验检查
  654 + DWORD fOutxCtsFlow:1; CTS输出流量控制
  655 + DWORD fOutxDsrFlow:1; DSR输出流量控制
  656 + DWORD fDtrControl:2; DTR流量控制类型
  657 + DWORD fDsrSensitivity:1; DSR安全设置
  658 + DWORD fTXContinueOnXoff: 1; XOFF持续Tx
  659 + DWORD fOutX: 1; XON/XOFF输出流量控制
  660 + DWORD fInX: 1; XON/XOFF输出流量控制
  661 + DWORD fErrorChar: 1; 激活错误替换机制
  662 + DWORD fNull: 1; 允许舍空格
  663 + DWORD fRtsControl:2; Rts流量控制
  664 + DWORD fAbortOnError:1; 有错误时放弃读/写
  665 + DWORD fDummy2:17; 保留
  666 + WORD wReserved; 现在不使用
  667 + WORD XonLim; 传送XON阀值
  668 + WORD XoffLim; 传送XOFF阀值
  669 + BYTE ByteSize; 每个字节的位数 4-8
  670 + BYTE Parity; 校验 0-4=None,Odd,Even,Mark,Space
  671 + BYTE StopBits; 0,1,2 = 1, 1.5, 2
  672 + char XonChar; 设置Tx和Rx的XON的字符
  673 + char XoffChar; 设置Tx和Rx的XOFF字符
  674 + char ErrorChar; 有错误时的替换字符
  675 + char EofChar; 表示输入结束的字符
  676 + char EvtChar; 接收事件字符
  677 + WORD wReserved1; 保留未使用
  678 +} DCB, *LPDCB;
  679 +
  680 +DCB结构中重要参数说明如下:
  681 +
  682 +Baudrate:串行端口的传输速度
  683 +fBinary:是否采用二进制方式发送数据,若设为1,表示采用二进制方式,占 一个位。由于win32只支持二进制的方式,故此值必须设置为1.
  684 +fParity:是否启动奇偶校验位检查,若设为1,表示采用奇偶校验位检查。此标志占一个位。
  685 +fOutxCtsFlow:是否采用CTS硬件流量控制。当此值设为1,而CTS引脚为底电位时,数据发送将暂停,直到CTS引脚升至高电位。占一个位。
  686 +fOutDsrFlow:是否采用DSR硬件流量控制。当此值设为1,而DSR引脚为低电位时,数据发送将暂停,直到DSR引脚升至高电位,占一个位。
  687 +fDtrControl:是否采用DTR硬件流量控制。可设为DTR_CONTROL_DISABLE(串行端口打开后设为低电位)、DTR_CONTROL_ENABLE( 串行端口打开后设为高电位)DTR_CONTROL_HANDSHAKE(启动硬件流量控制)三者之一,其常数定义数值分别是0、1、2。此标志占两个位。
  688 +fDsrSensitivity:当成True时,当DSR引脚被提升至高电位之前,串行端口将忽略任何被收到的数据。此标志占一个位的位置。
  689 +ftOutX:发送过程是否启用软件握手(XON_XOFF)。当设成1时,发送过程收到XOFF字符时停上发送,而收到XON字符时恢复发送。此标志占一个位的位置。
  690 +fInX:发送过程是否后用软件握手(XON-XOFF),当设成1时,接收过程若超过设置值(XoffLim参数决定),则送出XOFF字符:而低于设置值时(Xonlim参数决定)送出XON字符。此标志占一个位的位置。
  691 +fNuil:接收过程是否舍弃空格符。若设成1则于接收过程将自动去掉空格符。此标志占一个位的位置。
  692 +fRtsControl:是否启动RTS硬件流控制。可设为RTS_CONTROL_DISABLE(串行端凵打丌后设为低电位)、RTS_CONTROL_ENABLE(串行端口打开后设为高电位)、RTS_CONTROL_HANDSHAKE(启动硬件流量控制)、
  693 +RTSCONTROLTOGGLE(指示发过程的进行状态)四者之一,其常数是0、1、2、3。此标志占两个位的位置。
  694 +XonLim:设置发送XON字符时,输入缓冲区中的最小字节数
  695 +XoffLim:设置发送XOFF字符时,输入缓冲区中的最大字节数
  696 +ByteSize:设置数据位数。有5、6、7、8可以设置。
  697 +Parity:设置校验位检查的种类。有None、Even、Odd三种
  698 +StopBits:设置停止位数。有1、1.5、2三种
  699 +XonChar:设置XON字符
  700 +XoffChar:设置XOFF字符
  701 +
  702 +
  703 +SetCommState()函数
  704 +SetCommState()函数设置串行端口状态。如设置串口设置(波特率,校验,停止位,数据位等).
  705 +SetCommState()函数原型:
  706 +BOOL SetCommState( HANDLE hFile, LPDCB lpDCB );
  707 +hFile:串行端口的Handle值,此值即为使用CreateFile函数后返回的值。
  708 +lpDCB:设备控制块(Device Control Block, DCB)结构,将指定后的DCB结构传入。
  709 +
  710 +
  711 +WriteFile()函数
  712 +WriteFile函数,可以将数据写入一个文件或者I/O设备。该函数比fwrite函数要灵活的多,也可将这个函数应用于对通信设备、管道、套接字以及邮槽的处理。
  713 +windows将串行端口当成文件来使用,因此写入串行端口数据的函数也是WriteFile。
  714 +WriteFile()函数原型:
  715 +BOOL WriteFile( HANDLE hFile,//文件句柄
  716 + LPCVOID lpBuffer,//数据缓存区指针
  717 + DWORD nNumberOfBytesToWrite,//要写的字节数
  718 + LPDWORD lpNumberOfBytesWritten,//用于保存实际写入字节数的存储区域的指针
  719 + LPOVERLAPPED lpOverlapped//OVERLAPPED结构体指针
  720 +);
  721 +hFile:串行端口的Handle值,句柄
  722 +lpBuffer:指向欲发送的数据
  723 +nNumberOfBytesToWrite:写入的字节数
  724 +lpNumberOfBytesWritten:指向被写入的字节数的变量地址
  725 +lpOverlapped:指向overlapped I/O的结构地址,通常用来作背景工作时同步检查用,在串行通信中若不使用异步传输,则可不使用,设成NULL即可。
  726 +
  727 +
  728 +ReadFile()函数
  729 +从文件中读出数据。与fread函数相比,这个函数要明显灵活的多。该函数能够操作通信设备、管道、套接字以及邮槽。
  730 +windows将串行端口的使用当成文件,因此读取串行端口数据的函数亦使用读文件函数ReadFile.
  731 +ReadFile()函数原型:
  732 +BOOL ReadFile(
  733 + HANDLE hFile, //文件的句柄
  734 + LPVOID lpBuffer, //接收数据的缓冲区
  735 + DWORD nNumberOfBytesToRead, //读取的字节数
  736 + LPDWORD lpNumberOfBytesRead, //指向实际读取字节数的指针
  737 + LPOVERLAPPED lpOverlapped
  738 + //如文件打开时指定了FILE_FLAG_OVERLAPPED,那么必须,用这个参数引用一个特殊的结构。
  739 + //该结构定义了一次异步读取操作。否则,应将这个参数设为NULL
  740 +);
  741 +ReadFile()函数参数说明:
  742 +hFile:串行端口的Handle值,
  743 +lpBuffer:指向存储被读取数据的地址
  744 +nNumberOfBytesToRead:准备读取的数据字节数
  745 +lpNumberOfBytesRead:准备读取字节数的指针
  746 +lpOverlapped:指向overlapped I/O的结构地址,在串行通信中若不同时进行后台工作,则可不使用,设成NULL即可。
  747 +
  748 +
  749 +ClearCommError()函数
  750 +清除串行端口错误或读取串行端口现在的状态时,可用函数ClearCommError。Windows系统利用此函数清除硬件的通讯错误以及获取通讯设备的当前状态
  751 +ClearCommError()函数原型
  752 +BOOL ClearCommError( HANDLE hFile, //通信设备的句柄
  753 + LPDWORD lpErrors,//接收错误代码变量的指针
  754 + LPCOMSTAT lpStat //通信状态缓冲区的指针
  755 +);
  756 +ClearCommError()函数参数说明:
  757 +hFile:串行端冂的Handle值,此值即为使用CreateFile函数后所返回的值。
  758 +lpError:返回错误数值,错误常数如下:
  759 +CE_BREAK:检测到中断信号。
  760 +CE_DNS:Windows95专用,未被选择的并行端口。
  761 +CE_FRAME:硬件检到框架错误
  762 +CE_IOE:通信设备发生输入/输出綹误,
  763 +CE_MODE:设置模式错误,或是hFile值错误。
  764 +CE_OOP:Wmdows95专用,并行端口发生缺纸错误。CE_OVERRUN:缓冲区容量不足,数据将遗失。
  765 +CE_PTO:Windows95专用,并行端口发生超时错误。
  766 +CE_RXOVER:接收区满溢或在文件结尾被接收到后仍有数据发送过来。
  767 +CE_RXPARITY:硬件检测到校验位检查错误。
  768 +CE_TXFULL:发送缓存区已满后,应用程序仍要发送数据。
  769 +lpStat:指向通信端口状态的结构变量。此结构的原始声明如下:
  770 +typedef struct _COMSTAT { //cst
  771 + DWORD fCtsHold : 1; //Tx正在等待CTS信号
  772 + DWORD fDsrHold : 1; //Tx正在等待DSR信号
  773 + DWORD fRlsdHold : 1; //Tx正在等待RLSD信号
  774 + DWORD fXoffHold : 1; //Tx由于接收XOFF字符而在等待
  775 + DWORD fXoffSent : 1; //Tx由于发送XOFF字符而在等待
  776 + DWORD fEof : 1; //发送EOF字符
  777 + DWORD fTxim : 1; //字符在等待Tx
  778 + DWORD fReserved : 25; //保留
  779 + DWORD cbInQue; //输入缓冲区中的字节数
  780 + DWORD cbOutQue; //输出缓冲区中的字节数
  781 +} COMSTAT, *LPCOMSTAT;
  782 +此结构屮有关参数说明如下:
  783 +fCtsHold:是否正在等待CTS信号。占一个位的位置。
  784 +fDsrHold:是否正在等待DSR信号。占一个位的位置。
  785 +fRlsdHoId:是否正在等待RLSD信号。占一个位的位置。
  786 +fXoftHoId:是否因收到xoff字符而在等待。占一个位的位置。
  787 +fXoffHold:是否因送出xoff字符而使得发送的动作在等待。占一个位置
  788 +cbInQue:在输入缓冲区尚未被ReadFile函数读取的数据字节数。这个参数经常被用来进行状态检查。
  789 +cbOutQue:在发送缓冲区而尚未被发送的据字节数
  790 +
  791 +
  792 +WaitForMultipleObjects 是Windows中的一个功能非常强大的函数,几乎可以等待Windows中的所有的内核对象
  793 +
  794 +PurgeComm()函数
  795 +PurgeComm()函数–清空缓冲区
  796 +BOOL PurgeComm( HANDLE hFile, DWORD dwFlags );
  797 +hFile
  798 +[in]处理通信资源。该的CreateFile函数返回该句柄。
  799 +dwFlags
  800 +[in]指定要采取的操作。下表显示了可能的值。
  801 +PURGE_TXABORT 终止所有正在进行的字符输出操作,完成一个正处于等待状态的重叠i/o操作,他将产生一个事件,指明完成了写操作
  802 +PURGE_RXCLEAR 终止所有正在进行的字符输入操作,完成一个正在进行中的重叠i/o操作,并带有已设置得适当事件
  803 +PURGE_TXABORT 这个命令指导设备驱动程序清除输出缓冲区,经常与PURGE_TXABORT 命令标志一起使用
  804 +PURGE_RXCLEAR 这个命令用于设备驱动程序清除输入缓冲区,经常与PURGE_RXABORT 命令标志一起使用
  805 +
  806 +
  807 +
  808 +
  809 +
  810 +
  811 +
  812 +*/
... ...
... ... @@ -50,13 +50,13 @@ BOOL PaintTTY( HWND );
50 50
51 51 FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
52 52
53   -PURPOSE: Start application and process all window messages
  53 +PURPOSE: 启动应用程序并处理所有窗口消息
54 54
55 55 PARAMETERS:
56 56 hInstance - this apps hinstance
57   - hPrevInstance - previous instance of this app - always NULL
  57 + hPrevInstance - 这个应用程序的前一个实例-总是NULL
58 58 lpCmdLine - command line parameters
59   - nCmdShow - code for showing window
  59 + nCmdShow - 显示窗口的代码
60 60
61 61 RETURN:
62 62 1 for success
... ... @@ -95,7 +95,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
95 95
96 96 FUNCTION: VersionCheck(void)
97 97
98   -PURPOSE: Verifies that the correct version of Windows is running
  98 +PURPOSE: 验证运行的Windows版本是否正确
99 99
100 100 RETURN:
101 101 TRUE - success version for running this app
... ... @@ -122,8 +122,7 @@ BOOL VersionCheck()
122 122
123 123 FUNCTION: InitializeApp(HINSTANCE, int)
124 124
125   -PURPOSE: GlobalInitialize, Register window classes
126   - and create main window
  125 +PURPOSE: 全局初始化,注册窗口类,创建主窗口
127 126
128 127 PARAMETERS:
129 128 hInst - HINSTANCE of this app
... ... @@ -140,12 +139,8 @@ HISTORY: Date: Author: Comment:
140 139 BOOL InitializeApp(HINSTANCE hInst, int nShowCmd)
141 140 {
142 141 WNDCLASS wc = {0};
143   -
144   - GlobalInitialize(); // get all global variables initialized to defaults
145   -
146   - //
147   - // setup program's main window class
148   - //
  142 + GlobalInitialize(); // 所有的全局变量初始化为defaultss app
  143 + // 安装程序的主窗口类
149 144 wc.lpfnWndProc = (WNDPROC) MTTTYWndProc;
150 145 wc.hInstance = hInst;
151 146 wc.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_APPICON));
... ... @@ -153,18 +148,13 @@ BOOL InitializeApp(HINSTANCE hInst, int nShowCmd)
153 148 wc.lpszMenuName = MAKEINTRESOURCE(IDR_MTTTYMENU);
154 149 wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1) ;
155 150 wc.lpszClassName = "MTTTYClass";
156   -
157   - if (!RegisterClass(&wc)) {
158   - GlobalCleanup();
159   - return FALSE;
160   - }
161   -
  151 + if (!RegisterClass(&wc))
  152 + {
  153 + GlobalCleanup();
  154 + return FALSE;
  155 + }
162 156 QuerySerialPortStatusEx(TTYInfo.unOpenedPortAry,2,255);
163   - TTYInfo.rgbBGColor = RGB(255,255,255);
164   -
165   - //
166   - // setup program's tty child window class
167   - //
  157 + //设置程序的tty子窗口类
168 158 wc.lpfnWndProc = (WNDPROC) TTYChildProc;
169 159 wc.hInstance = hInst;
170 160 wc.hCursor = LoadCursor(NULL, IDC_IBEAM);
... ... @@ -172,32 +162,27 @@ BOOL InitializeApp(HINSTANCE hInst, int nShowCmd)
172 162 wc.lpszClassName = "MTTTYChildClass";
173 163 wc.lpszMenuName = NULL;
174 164 wc.hIcon = NULL;
175   -
176   - if (!RegisterClass(&wc)) {
177   - GlobalCleanup();
178   - return FALSE;
179   - }
180   -
181   - //
  165 + if (!RegisterClass(&wc))
  166 + {
  167 + GlobalCleanup();
  168 + return FALSE;
  169 + }
182 170 // create main window
183   - //
184 171 ghwndMain = CreateWindow("MTTTYClass", "BlueFlashTool 鼎维尔科技",
185 172 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
186 173 STARTXWINDOW, STARTYWINDOW,
187 174 MAXXWINDOW, MAXYWINDOW,
188 175 NULL, NULL, hInst, NULL);
189   -
190   - if (ghwndMain == NULL) {
191   - GlobalCleanup();
192   - return FALSE;
193   - }
194   -
  176 + if (ghwndMain == NULL)
  177 + {
  178 + GlobalCleanup();
  179 + return FALSE;
  180 + }
195 181 ShowWindow( ghwndMain, nShowCmd ) ;
196 182 UpdateWindow( ghwndMain ) ;
197   -
198 183 ghInst = hInst;
  184 + //LoadAccelerators函数功能:调入加速键表。该函数调入指定的加速键表。
199 185 ghAccel = LoadAccelerators( hInst, MAKEINTRESOURCE( IDR_MTTTYACCELERATOR) ) ;
200   -
201 186 return TRUE;
202 187 }
203 188
... ... @@ -229,7 +214,7 @@ int WINAPI MTTTYWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
229 214 {
230 215 case WM_CREATE:
231 216 //
232   - // since main window is created, I can now open all other windows
  217 + // 由于创建了主窗口,我现在可以打开所有其他窗口
233 218 //
234 219 InitTTYInfo();
235 220 OpenTTYChildWindow(hwnd);
... ... @@ -240,7 +225,7 @@ int WINAPI MTTTYWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
240 225
241 226 case WM_DESTROY:
242 227 //
243   - // since main windows is being destroyed, so same to other windows
  228 + // 由于主窗口正在被销毁,所以其他窗口也一样
244 229 //
245 230 DestroyTTYInfo();
246 231 DestroyWindow(ghWndToolbarDlg);
... ... @@ -253,58 +238,37 @@ int WINAPI MTTTYWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
253 238
254 239 case WM_GETMINMAXINFO:
255 240 {
256   - //
257   - // make sure that main window doesn't get smaller than
258   - // the minimum child windows.
259   - //
  241 + // 确保主窗口不会小于最小子窗口。
260 242 LPMINMAXINFO lpTemp;
261 243 POINT ptTemp;
262   -
263 244 lpTemp = (LPMINMAXINFO) lParam;
264   -
265 245 ptTemp.x = (long) lpTemp->ptMinTrackSize.x;
266 246 ptTemp.y = (long) gcyMinimumWindowHeight;
267   -
268 247 lpTemp->ptMinTrackSize = ptTemp;
269 248 }
270   -
271 249 break;
272 250
273 251 case WM_SIZE:
274 252 {
275   - //
276   - // main window size has changed,
277   - // so I need to change the positions of child windows
278   - //
  253 + //主窗口大小已经改变,,所以我需要改变子窗口的位置
279 254 WORD wTop;
280 255 WORD wHeight;
281 256 WORD wWidth = LOWORD(lParam);
282   -
283   - //
284   - // put Settings window at top
285   - //
  257 + // 把设置窗口放在顶部
286 258 wHeight = SETTINGSFACTOR*gwBaseY;
287 259 wTop = 0;
288 260 MoveWindow(ghWndToolbarDlg, 0,wTop, wWidth, wHeight, TRUE);
289   -
290   - //
291   - // put Status window at bottom
292   - //
  261 + // 把状态窗口放在底部
293 262 wHeight = STATUSFACTOR*gwBaseY;
294 263 wTop = HIWORD(lParam) - wHeight;
295 264 MoveWindow(ghWndStatusDlg, 0, wTop, wWidth, wHeight, TRUE);
296   -
297   - //
298   - // put TTTY window right in the middle
  265 + // 把TTTY window放在中间
299 266 // height = whole window - height of two previous windows
300   - //
301 267 wHeight = HIWORD(lParam) - ((STATUSFACTOR + SETTINGSFACTOR)*gwBaseY);
302 268 wTop = SETTINGSFACTOR*gwBaseY;
303 269 MoveWindow(ghWndTTY, 0, wTop, wWidth, wHeight, TRUE);
304 270 }
305   -
306 271 break;
307   -
308 272 case WM_COMMAND:
309 273 CmdDispatch(LOWORD(wParam), hwnd, lParam);
310 274 break;
... ... @@ -315,16 +279,17 @@ int WINAPI MTTTYWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
315 279 break;
316 280
317 281 case WM_CLOSE:
318   - if (DisconnectOK()) {
319   - if (TTYInfo.fConnected) {
320   - if (TTYInfo.fTransferring)
321   - TransferFileTextEnd();
322   - BreakDownCommPort();
323   - }
324   - DestroyWindow(hwnd);
325   - }
  282 + if (DisconnectOK())
  283 + {
  284 + if (TTYInfo.fConnected)
  285 + {
  286 + if (TTYInfo.fTransferring)
  287 + TransferFileTextEnd();
  288 + BreakDownCommPort();
  289 + }
  290 + DestroyWindow(hwnd);
  291 + }
326 292 break;
327   -
328 293 default:
329 294 return DefWindowProc(hwnd, message, wParam, lParam);
330 295 }
... ... @@ -336,11 +301,11 @@ int WINAPI MTTTYWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
336 301
337 302 FUNCTION: CmdDispatch(int, HWND)
338 303
339   -PURPOSE: Responds to menu selections
  304 +PURPOSE: 响应菜单选择
340 305
341 306 PARAMETERS:
342   - iMenuChoice - ID of menu choice (from resource file)
343   - hwnd - window handle of menu owner
  307 + iMenuChoice - 菜单选择ID(来自资源文件)
  308 + hwnd - 菜单所有者的窗口句柄
344 309
345 310 HISTORY: Date: Author: Comment:
346 311 10/27/95 AllenD Wrote it
... ... @@ -349,40 +314,34 @@ HISTORY: Date: Author: Comment:
349 314 void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam)
350 315 {
351 316 static char szFileName[MAX_PATH] = {0};
352   -
353 317 switch (iMenuChoice)
354 318 {
355 319 case ID_HELP_ABOUTMTTTY:
356 320 CmdAbout(hwnd);
357 321 break;
358   -
359 322 case ID_TRANSFER_SENDFILETEXT:
360   - {
  323 + {// 发送文件
361 324 if (strlen(TTYInfo.szFileName) == 0)
362 325 {
363   - char * szFilter = "Text Files\0*.*\0";
364   - OPENFILENAME ofn = {0};
365   -
366   - ofn.lStructSize = sizeof(OPENFILENAME);
367   - ofn.hwndOwner = hwnd;
368   - ofn.lpstrFilter = szFilter;
369   - ofn.lpstrFile = szFileName;
370   - ofn.nMaxFile = MAX_PATH;
371   - ofn.lpstrTitle = "Send File";
372   - ofn.Flags = OFN_FILEMUSTEXIST;
373   -
  326 + char * szFilter = "Text Files\0*.*\0";
  327 + OPENFILENAME ofn = { 0 };
  328 + ofn.lStructSize = sizeof(OPENFILENAME);
  329 + ofn.hwndOwner = hwnd;
  330 + ofn.lpstrFilter = szFilter;
  331 + ofn.lpstrFile = szFileName;
  332 + ofn.nMaxFile = MAX_PATH;
  333 + ofn.lpstrTitle = "Send File";
  334 + ofn.Flags = OFN_FILEMUSTEXIST;
374 335 if (!GetOpenFileName(&ofn))
375 336 break;
376   - strcpy(TTYInfo.szFileName,szFileName); }
377   -
378   -
379   - if (TRUE)
380   - TransferFileTextStart(TTYInfo.szFileName);
381   - }
  337 + strcpy(TTYInfo.szFileName, szFileName);
  338 + }
  339 + if (TRUE)
  340 + TransferFileTextStart(TTYInfo.szFileName);
  341 + }
382 342 break;
383   -
384 343 case ID_TRANSFER_RECEIVEFILETEXT:
385   - {
  344 + {// 接收文件
386 345 char * szFilter = "Text Files\0*.TXT\0";
387 346 OPENFILENAME ofn = {0};
388 347
... ... @@ -402,7 +361,7 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam)
402 361 break;
403 362
404 363 case ID_TRANSFER_ABORTSENDING:
405   - // was abort sent from the abort button?
  364 + // 是否从中止按钮发出中止?
406 365 if (LOWORD(lParam) == IDC_ABORTBTN) {
407 366 // am I in a transfer repeat?
408 367 if (TTYInfo.fRepeating)
... ... @@ -415,12 +374,12 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam)
415 374 gfAbortTransfer = TRUE;
416 375 }
417 376 else
418   - // transfer abort was sent by transfer thread
  377 + //传输中止
419 378 TransferFileTextEnd();
420 379 break;
421 380
422 381 case ID_TRANSFER_SENDREPEATEDLY:
423   - {
  382 + {// 重复发送
424 383 DWORD dwFreq;
425 384 char * szFilter = "Text Files\0*.TXT\0";
426 385 OPENFILENAME ofn = {0};
... ... @@ -481,12 +440,12 @@ void CmdDispatch(int iMenuChoice, HWND hwnd, LPARAM lParam)
481 440
482 441 FUNCTION: OpenTTYChildWindow(HWND)
483 442
484   -PURPOSE: Creates the TTY Child Window
  443 +PURPOSE: 创建TTY子窗口
485 444
486 445 PARAMETERS:
487   - hWnd - parent window handle of TTY child window
  446 + hWnd -TTY子窗口的父窗口句柄
488 447
489   -COMMENTS: This window is actually the TTY Screen
  448 +COMMENTS: 这个窗口实际上是TTY屏幕
490 449
491 450 HISTORY: Date: Author: Comment:
492 451 10/27/95 AllenD Wrote it
... ... @@ -506,27 +465,21 @@ void OpenTTYChildWindow(HWND hWnd)
506 465 }
507 466
508 467
509   -//---------------------------------------------------------------------------
510   -// BOOL NEAR ScrollTTYVert( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
511   -//
512   -// Description:
513   -// Scrolls TTY window vertically.
514   -//
515   -// Parameters:
516   -// HWND hWnd
517   -// handle to TTY window
518   -//
519   -// WORD wScrollCmd
520   -// type of scrolling we're doing
521   -//
522   -// WORD wScrollPos
523   -// scroll position
524   -//
525   -// History: Date Author Comment
526   -// 5/ 8/91 BryanW Wrote it.
527   -// 10/27/95 AllenD Included it for MTTTY Sample.
528   -//
529   -//---------------------------------------------------------------------------
  468 +/*
  469 + BOOL NEAR ScrollTTYVert( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
  470 + Description:
  471 + 垂直滚动TTY窗口。
  472 + Parameters:
  473 + HWND hWnd
  474 + handle to TTY window
  475 + WORD wScrollCmd
  476 + type of scrolling we're doing
  477 + WORD wScrollPos
  478 + scroll position
  479 + History: Date Author Comment
  480 + 5/ 8/91 BryanW Wrote it.
  481 + 10/27/95 AllenD Included it for MTTTY Sample.
  482 +*/
530 483 BOOL NEAR ScrollTTYVert( HWND hWnd, WORD wScrollCmd, WORD wScrollPos )
531 484 {
532 485 int nScrollAmt ;
... ... @@ -925,10 +878,7 @@ int WINAPI TTYChildProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
925 878 break ;
926 879
927 880 case WM_MOUSEACTIVATE:
928   - /*
929   - If mouse is clicked in me (the tty child window)
930   - then I need to get the focus.
931   - */
  881 + // 如果鼠标在(tty子窗口)中被点击 然后设置焦点。
932 882 SetFocus(hWnd);
933 883 return MA_ACTIVATE;
934 884 break;
... ...
... ... @@ -23,20 +23,24 @@
23 23
24 24 //
25 25 // GLOBAL DEFINES
26   -//
  26 +//输出buff size
27 27 #define TTY_BUFFER_SIZE MAXROWS * MAXCOLS
28 28 #define MAX_STATUS_BUFFER 20000
  29 +//读写buff size
29 30 #define MAX_WRITE_BUFFER 1024
30 31 #define MAX_READ_BUFFER 2048
  32 +//超时设定
31 33 #define READ_TIMEOUT 500
32 34 #define STATUS_CHECK_TIMEOUT 500
33 35 #define WRITE_CHECK_TIMEOUT 500
  36 +//清空缓冲区
34 37 #define PURGE_FLAGS PURGE_TXABORT | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_RXCLEAR
  38 +
35 39 #define EVENTFLAGS_DEFAULT EV_BREAK | EV_CTS | EV_DSR | EV_ERR | EV_RING | EV_RLSD
36 40 #define FLAGCHAR_DEFAULT '\n'
37 41
38 42 //
39   -// Write request types
  43 +//写请求类型
40 44 //
41 45 #define WRITE_CHAR 0x01
42 46 #define WRITE_FILE 0x02
... ... @@ -54,8 +58,8 @@
54 58 //
55 59 // window coords
56 60 //
57   -#define MAXXWINDOW 750
58   -#define MAXYWINDOW 530
  61 +#define MAXXWINDOW 350
  62 +#define MAXYWINDOW 230
59 63 #define STARTXWINDOW 80
60 64 #define STARTYWINDOW 70
61 65
... ... @@ -91,7 +95,7 @@ WORD gwBaseY;
91 95 LONG gcyMinimumWindowHeight;
92 96
93 97 //
94   -// Flags controlling thread actions
  98 +// 控制线程操作的标志
95 99 //
96 100 HANDLE ghThreadExitEvent;
97 101 BOOL gfAbortTransfer;
... ... @@ -125,7 +129,7 @@ typedef struct STATUS_MESSAGE
125 129
126 130
127 131 //
128   -// Port name
  132 +// 端口名称
129 133 //
130 134 char gszPort[10];
131 135
... ... @@ -139,7 +143,7 @@ HANDLE ghWriterEvent;
139 143 HANDLE ghTransferCompleteEvent;
140 144
141 145 //
142   -// Write request data structure; look in Writer.c for more info
  146 +// 写请求数据结构;在Writer.c中查找更多信息
143 147 //
144 148 typedef struct WRITEREQUEST;
145 149
... ...
... ... @@ -13,9 +13,9 @@
13 13 PURPOSE: Read from comm port
14 14
15 15 FUNCTIONS:
16   - OutputABufferToWindow - process incoming data destined for tty window
17   - OutputABufferToFile - process incoming data destined for a file
18   - OutputABuffer - called when data is read from port
  16 + OutputABufferToWindow - 传入的数据显示到窗口
  17 + OutputABufferToFile - 传入的数据保存到文件
  18 + OutputABuffer - 从端口读取数据时调用
19 19
20 20 -----------------------------------------------------------------------------*/
21 21
... ... @@ -34,7 +34,7 @@ void OutputABufferToFile( HANDLE, char *, DWORD );
34 34
35 35 FUNCTION: OutputABufferToWindow(HWND, char *, DWORD)
36 36
37   -PURPOSE: Updates TTY Buffer with characters just received.
  37 +PURPOSE: 用刚刚收到的字符更新TTY缓冲区。
38 38
39 39 PARAMETERS:
40 40 hTTY - handle to the TTY child window
... ... @@ -47,84 +47,72 @@ HISTORY: Date Author Comment
47 47
48 48 -----------------------------------------------------------------------------*/
49 49 void OutputABufferToWindow(HWND hTTY, char * lpBuf, DWORD dwBufLen)
50   -{
51   - RECT rect;
52   -
53   - /*
54   - update screen buffer with new buffer
55   - need to do a character by character check
56   - for special characters
57   - */
58   - int i;
59   -
60   - for ( i = 0 ; i < (int) dwBufLen; i++) {
61   - switch (lpBuf[ i ]) {
62   - case ASCII_BEL: // BELL CHAR
63   - MessageBeep( 0 ) ;
64   - break ;
65   -
66   - case ASCII_BS: // Backspace CHAR
67   - if (TTYInfo.nColumn > 0)
68   - TTYInfo.nColumn -- ;
69   - break ;
70   -
71   - case ASCII_CR: // Carriage Return
72   - TTYInfo.nColumn = 0 ;
73   - if (!TTYInfo.fNewLine)
74   - break;
75   -
76   - //
77   - // FALL THROUGH
78   - //
79   -
80   - case ASCII_LF: // Line Feed
81   - if (TTYInfo.nRow++ == MAXROWS - 1)
82   - {
83   - MoveMemory( (LPSTR) (TTYInfo.Screen),
84   - (LPSTR) (TTYInfo.Screen + MAXCOLS),
85   - (MAXROWS - 1) * MAXCOLS ) ;
86   - FillMemory((LPSTR) (TTYInfo.Screen + (MAXROWS - 1) * MAXCOLS),
87   - MAXCOLS, ' ' ) ;
88   - InvalidateRect( hTTY, NULL, FALSE ) ;
89   - TTYInfo.nRow-- ;
90   - }
91   - break ;
92   -
93   - default: // standard character
94   - TTYInfo.Screen[TTYInfo.nRow * MAXCOLS + TTYInfo.nColumn]= lpBuf[ i ];
95   -
96   - rect.left = (TTYInfo.nColumn * TTYInfo.xChar) -
97   - TTYInfo.xOffset ;
98   - rect.right = rect.left + TTYInfo.xChar ;
99   - rect.top = (TTYInfo.nRow * TTYInfo.yChar) -
100   - TTYInfo.yOffset ;
101   - rect.bottom = rect.top + TTYInfo.yChar ;
102   - InvalidateRect( hTTY, &rect, FALSE ) ;
103   -
104   - //
105   - // Line wrap
106   - //
107   - if (TTYInfo.nColumn < MAXCOLS-1 )
108   - TTYInfo.nColumn++ ;
109   - else if (TTYInfo.fAutowrap)
110   - OutputABufferToWindow(hTTY, "\r\n", 2 ) ;
111   -
112   - break;
113   - }
114   - }
115 50
116   - MoveTTYCursor(hTTY);
117   - return;
  51 +{
  52 + RECT rect;
  53 +//更新屏幕缓冲区与新的缓冲区 需要一个字符一个字符地检查 为特殊字符
  54 + int i;
  55 +
  56 + for (i = 0; i < dwBufLen; i++)
  57 + {
  58 + switch (lpBuf[i])
  59 + {
  60 + case ASCII_BEL: // BELL CHAR
  61 + MessageBeep(0);
  62 + break;
  63 + case ASCII_BS: // Backspace CHAR
  64 + if (TTYInfo.nColumn > 0)
  65 + TTYInfo.nColumn--;
  66 + break;
  67 + case ASCII_CR: // Carriage Return
  68 + TTYInfo.nColumn = 0;
  69 + if (!TTYInfo.fNewLine)
  70 + break;
  71 +
  72 + //
  73 + // FALL THROUGH
  74 + //
  75 + case ASCII_LF: // Line Feed
  76 + if (TTYInfo.nRow++ == MAXROWS - 1)
  77 + {
  78 + MoveMemory((LPSTR) (TTYInfo.Screen),
  79 + (LPSTR) (TTYInfo.Screen + MAXCOLS),
  80 + (MAXROWS - 1) *MAXCOLS);
  81 + FillMemory((LPSTR) (TTYInfo.Screen + (MAXROWS - 1) *MAXCOLS),
  82 + MAXCOLS, ' ');
  83 + InvalidateRect(hTTY, NULL, FALSE);
  84 + TTYInfo.nRow--;
  85 + }
  86 + break;
  87 + default: // standard character
  88 + TTYInfo.Screen[TTYInfo.nRow * MAXCOLS + TTYInfo.nColumn] = lpBuf[i];
  89 + rect.left = (TTYInfo.nColumn * TTYInfo.xChar) -TTYInfo.xOffset;
  90 + rect.right = rect.left + TTYInfo.xChar;
  91 + rect.top = (TTYInfo.nRow * TTYInfo.yChar) -TTYInfo.yOffset;
  92 + rect.bottom = rect.top + TTYInfo.yChar;
  93 + InvalidateRect(hTTY, &rect, FALSE);
  94 + // Line wrap
  95 + if (TTYInfo.nColumn < MAXCOLS - 1)
  96 + TTYInfo.nColumn++;
  97 + else if (TTYInfo.fAutowrap)
  98 + OutputABufferToWindow(hTTY, "\r\n", 2);
  99 + break;
  100 + }
  101 + }
  102 + MoveTTYCursor(hTTY);
  103 + return;
118 104 }
119 105
  106 +
  107 +
120 108 /*-----------------------------------------------------------------------------
121 109
122 110 FUNCTION: OutputABufferToFile(HANDLE, char *, DWORD)
123 111
124   -PURPOSE: Output a rec'd buffer to a file
  112 +PURPOSE: 将已读取的缓冲区输出到文件中
125 113
126 114 PARAMETERS:
127   - hFile - handle of file save data into
  115 + hFile - 文件的句柄保存数据到
128 116 lpBuf - address of data buffer
129 117 dwBufLen - size of data buffer
130 118
... ...
... ... @@ -9,9 +9,8 @@
9 9
10 10 MODULE: ReadStat.c
11 11
12   - PURPOSE: Thread procedure responsible for reading comm port,
13   - reporting status events, report status messages,
14   - and periodically updating status controls
  12 + PURPOSE:
  13 + 线程过程负责读取通信端口,报告状态事件,报告状态消息,并定期更新状态控制
15 14
16 15 FUNCTIONS:
17 16 ReaderAndStatusProc - Thread procedure does the work here
... ... @@ -28,8 +27,7 @@
28 27
29 28 FUNCTION: ReaderAndStatusProc(LPVOID)
30 29
31   -PURPOSE: Thread function controls comm port reading, comm port status
32   - checking, and status messages.
  30 +PURPOSE: 线程功能控制通信端口读取、通信端口状态检查和状态消息。
33 31
34 32 PARMATERS:
35 33 lpV - 4 byte value contains the tty child window handle
... ...
... ... @@ -16,8 +16,8 @@
16 16 SetCommState and SetCommTimeouts.
17 17
18 18 FUNCTIONS:
19   - OpenSettingsToolbar - Creates the Settings Dialog
20   - ChangeConnection - Modifies menus & controls based on connection state
  19 + OpenSettingsToolbar - 创建设置对话框
  20 + ChangeConnection - 根据连接状态修改菜单和控件
21 21 UpdateTTYInfo - Modifies TTY data from Settings Dialog and
22 22 if connected, updates open comm port settings
23 23 FillComboBox - Fills a combo box with strings
... ... @@ -299,10 +299,9 @@ void UpdateTTYInfo()
299 299
300 300 FUNCTION: UpdateConnection( void )
301 301
302   -PURPOSE: Sets port state based on settings from the user
  302 +PURPOSE: 根据用户的设置设置端口状态
303 303
304   -COMMENTS: Sets up DCB structure and calls SetCommState.
305   - Sets up new timeouts by calling SetCommTimeouts.
  304 +COMMENTS: 设置DCB结构并调用SetCommState。通过调用SetCommTimeouts设置新的超时。
306 305
307 306 HISTORY: Date: Author: Comment:
308 307 1/ 9/96 AllenD Wrote it
... ...
... ... @@ -59,20 +59,15 @@ BOOL GetTransferSizes( HANDLE, DWORD *, DWORD *, DWORD *);
59 59
60 60 FUNCTION: TransferRepeatCreate(LPCTSTR, DWORD)
61 61
62   -PURPOSE: Prepares program for a repeated text file transfer (send)
  62 +PURPOSE: 重复的文件传输(发送)准备
63 63
64 64 PARAMETERS:
65 65 lpstrFileName - name of file selected to send
66 66 dwFrequency - frequency of timer
67 67
68   -COMMENTS: This function sets up a window timer to fire off
69   - every so often. When it fires, TransferRepeatDo is
70   - called with the same name as above. This causes the file transfer
71   - to actuall take place.
72   - TransferRepeatDestroy is called to kill the timer.
73   - This function disables certain menu items that should not be
74   - available for the duration of a repeated send even if the actual
75   - Tx is not taking place.
  68 +COMMENTS:
  69 +This function sets up a window timer to fire off every so often. When it fires, TransferRepeatDo is called with the same name as above. This causes the file transfer to actuall take place.
  70 +TransferRepeatDestroy is called to kill the timer. This function disables certain menu items that should not be available for the duration of a repeated send even if the actual Tx is not taking place.
76 71
77 72 HISTORY: Date: Author: Comment:
78 73 1/29/96 AllenD Wrote it
... ...
Please register or login to post a comment