Programming 版 (精华区)

发信人: Mice (鼠儿), 信区: Programming
标  题:   DOS下的串口通信编程---(3)
发信站: 紫丁香 (Mon Sep 15 15:59:43 1997)


//serial.cpp
#include <bios.h>
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include "serial.h"

unsigned char ComPort::read()
{
        int wait;
        unsigned st;
        errcode=0;
        for(wait=0;wait<WAITCOUNT;wait++) {
                st=state();
                if(st&RECEIVERDY) break;
        }
        if(wait==WAITCOUNT) {
               errcode=TIMEOUT;
                return 0xff;
        } else  {
                return read(RXD);
        }
}

void ComPort::write(char chr)
{
        int wait;
        unsigned st;
        errcode=0;
        for(wait=0;wait<WAITCOUNT;wait++) {
                st=state();
                if(st&EMPTYDATA) break;
        }
        if(wait==WAITCOUNT) {
                errcode=TIMEOUT;
        } else  {
                errcode=0;
                write(TXD,chr);
        }
}

void ComPort::write(char *str)
{
        char *p=str;
        errcode=0;
        while(*p&&errcode!=TIMEOUT) write(*p++);
}

--




       我是一只好老鼠

※ 来源:.紫丁香 pclinux.hit.edu.cn.[FROM: 202.118.226.74]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.652毫秒