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

📄 sertest.cpp

📁 串口通讯例程
💻 CPP
字号:






/* ------------------------------------------------------------------------ --

--                                                                          --

--                  Application example for using Tserial_event             --

--                                                                          --

--                                                                          --

--                                                                          --

--  Copyright @ 2001          Thierry Schneider                             --

--                            thierry@tetraedre.com                         --

--                                                                          --

--                                                                          --

--                                                                          --

-- ------------------------------------------------------------------------ --

--                                                                          --

--  Filename : sertest.cpp                                                  --

--  Author   : Thierry Schneider                                            --

--  Created  : April 8th 2001                                               --

--  Modified : April 24th 2001                                              --

--  Plateform: Windows 95, 98, NT, 2000 (Win32)                             --

-- ------------------------------------------------------------------------ --

--                                                                          --

--  This software is given without any warranty. It can be distributed      --

--  free of charge as long as this header remains, unchanged.               --

--                                                                          --

-- ------------------------------------------------------------------------ --

--                                                                          --

--  01.04.24    # ifdef __BORLANDC__ added in the header                    --               

--                                                                          --

--                                                                          --

-- ------------------------------------------------------------------------ */









/* ---------------------------------------------------------------------- */

#ifdef __BORLANDC__

#pragma hdrstop             // borland specific

#include <condefs.h>

#pragma argsused

USEUNIT("Tserial_event.cpp");

#endif



//---------------------------------------------------------------------------

#include "conio.h"

#include "Tserial_event.h"





/* ======================================================== */

/* ===============  OnCharArrival     ===================== */

/* ======================================================== */

void OnCharArrival(char c)

{

    printf("OnCharArrival: %c ",c);

}



/* ======================================================== */

/* ==================  OnConnected    ===================== */

/* ======================================================== */

void OnConnected(void)

{

    printf("Connected !");

}

/* ======================================================== */

/* ===================  OnDisconnected ==================== */

/* ======================================================== */

void OnDisconnected(void)

{

    printf("Disconnected !");

}



/* ======================================================== */

/* ===================   OnCharSent       ================= */

/* ======================================================== */

void OnCharSent(void)

{

    printf(" Char Sent !");

}



/* ======================================================== */

/* ========================   main  ======================= */

/* ======================================================== */

int main(int argc, char* argv[])

{

    int c;

    Tserial_event *com;





    com = new Tserial_event();

    if (com!=0)

    {

        // indicating to the serial object which function to

        // call in case of events

        com->setManagerOnCharArrival  (OnCharArrival);

        com->setManagerOnConnected    (OnConnected);

        com->setManagerOnDisconnected (OnDisconnected);

        com->setManagerOnCharSent     (OnCharSent);



        com->connect("COM1", 19200, spNONE, 8);



        // ------------------

        do

        {

            c = getch();

            printf("_%c",c);

            com->sendChar((char) c);

        }

        while (c!=32);



        // ------------------

        com->disconnect();



        // ------------------

        delete com;

        com = 0;

    }

    return 0;

}

⌨️ 快捷键说明

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