⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tstmodem.cpp

📁 DOS下采用中断接收数据的串口通讯的例子,很难找到的好东西!
💻 CPP
字号:
// ********************** START OF TSTMODEM.CPP **********************
//
//
// This short program is used to test the Modem class.  It is a
// very simple terminal emulator that can accept just a few commands.

#include <ctype.h>
#include <iostream.h>
#include "rs232.h"
#include "pc8250.h"
#include "modem.h"

int handle_command( Modem &modem );

// The main routine just acts as a terminal emulator.  It invokes
// a command handler if the escape key is pressed.

int main()
{
    int c;
    PC8250 port( COM1, 19200 );
    Modem modem( port, "Practical Peripherals V.34" );
    ModemError init;

    init = modem.Initialize();
    cout << "\nInitialization returned:  "
         << modem.ErrorName( init )
         << '\n';
    for ( ; ; ) {
        if ( kbhit() ) {
            c = getch();
            if ( c == 27 ) {
                if ( handle_command( modem ) )
                    break;
            } else
                port.Write( c );
        }
        if ( ( c = port.Read() ) > 0 )
            cout << (char) c;
        cout.flush(); // Needed by Zortech and Microsoft
    }
    return 0;
}

// The command handler is used to send various commands to the modem
// via the normal modem class.  It prints a help prompt so you will
// know exactly what your choice of commands is.

int handle_command( Modem &modem )
{
    int c;
    int i;
    ModemError status;
    char *command;
    int registers[ 11 ];

    cout << "\nAnswer Exit Dial Hangup Initialize "
            "Product-ID Read-regs Status\n\nEnter command: ";
    cout.flush(); // Needed by Zortech and Microsoft
    c = getch();
    cout << (char) c << '\n';
    switch ( toupper( c ) ) {
        case 'A' :
            command = "Answer";
            status = modem.Answer();
            break;
        case 'D' :
            command = "Dial";
            status = modem.Dial( "972-403-9406" );
            break;
        case 'E' :
            return 1;
        case 'H' :
            command = "Hangup";
            status = modem.Disconnect();
            break;
        case 'I' :
            command = "Initialize";
            status = modem.Initialize();
            break;
        case 'P' :
            command = "Product ID code";
            status = modem.SendCommand( "ATI0" );
            break;
        case 'R' :
            for ( i = 1 ; i < 11 ; i++ )
                registers[ i ] = modem.ReadRegister( i );
            for ( i = 1 ; i < 11 ; i++ ) {
                cout << "Register " << i << " = ";
                cout << registers[ i ] << '\n';
            }
            return 0;
        case 'S' :
            modem.DumpState();
            return 0;
        default  :
            cout << (char) 7; return 0;
    }
    cout << command << " returned: " << modem.ErrorName( status ) << '\n';
    return 0;
}

// ********************** END OF TSTMODEM.CPP **********************

⌨️ 快捷键说明

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