irlptdump.cpp

来自「红外接口串口仿真」· C++ 代码 · 共 69 行

CPP
69
字号
//////////////////////////////////////////////////////////////////////
//
//  IrLPTDump - Infrared Print Server Example
//  Copyright (c) 2003 Jan Kiszka
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "IrCOMM2kAPI.h"



COMMTIMEOUTS timeouts = {0, 0, 0, 0, 0};
DWORD        mode     = PASSIVE_CONNECTION_MODE | IRLPT_MODE;


int main(int argc, char* argv[])
{
    HANDLE  hComPort;
    CHAR    c;
    DWORD   count;


    printf("IrLPTDump (Infrared Print Server Example)\n\n");

    if (argc != 2)
    {
        printf("Usage:\n\tIrLPTDump <COMx>\n");
        return 1;
    }

    hComPort = CreateFile(argv[1], GENERIC_WRITE | GENERIC_READ, 0, NULL,
                          OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    if ((hComPort == INVALID_HANDLE_VALUE) ||
        !SetCommTimeouts(hComPort, &timeouts) ||
        !DeviceIoControl(hComPort, IOCTL_IRCOMM2K_SET_MODE, &mode, sizeof(mode),
                         NULL, NULL, &count, NULL))
    {
        printf("Invalid port specified.\n");
        return 1;
    }

    printf("Waiting for data...\n");
    while (1)
    {
        if (ReadFile(hComPort, &c, 1, &count, NULL))
            printf("%c", c);
        else
            break;
    }

    printf("Error while reading data!\n");
	return 1;
}

⌨️ 快捷键说明

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