testterm.cpp

来自「DOS下采用中断接收数据的串口通讯的例子,很难找到的好东西!」· C++ 代码 · 共 46 行

CPP
46
字号
// ***************** START OF TESTTERM.CPP ****************
//
// This test program implements a simple IBM ANSI terminal 
// emulator. With a properly designed class, a terminal emulator
// amounts to just a few lines of code, since all of the work 
// here is being done by the AnsiTerminal object.  Note that 
// the Terminal and RS232 objects are both pointers to the 
// base class, not the derived class.  This shows how terminal 
// emulation can be performed without knowing anything about 
// the emulation code, or the display class.
//

#include "rs232.h"
#include "pc8250.h"
#include "ascii.h"
#include "ansiterm.h"
#include "textwind.h"

main()
{
    TextWindow window( 0, 0, 80, 25 );
    RS232 *port = new PC8250( COM1, 19200, 'N', 8, 1 );
    Terminal *terminal = new AnsiTerminal( *port, window );
    int c;

    window << "Press F10 to exit...\n";
    port->RtsCtsHandshaking( 1 );
    for ( ; ; ) {
        c = terminal->ReadPort();
        if ( c < 0 && c != RS232_TIMEOUT )
            break;
        if ( c >= 0 )
            terminal->Display( c );
        c = window.ReadKey();
        if ( c == F10 )
            break;
        if ( c != 0 )
            terminal->WriteKey( c );
    }
    delete terminal;
    delete port;
    return 0;
}

// ******************** END OF TESTTERM.CPP ********************

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?