各位大虾,我现在急需一个vc6.0写的串口通讯的程序,实现方法随便只要实现功能!
(本人用 turbo c2.0写了成功版本,不过其中getvect setvect,和中断函数声明(void interrupt(*asyncoldvect)();)都不知道怎么转成vc的,现在项目要在ms-dos下运行,开发工具vc6.0,其他的都写好了,不过串口通讯没有解决)

解决方案 »

  1.   

    建议楼主去看看这个网站
    http://www.gjwtech.com/serialcomm.htm
      

  2.   

    http://www.fxstudio.nease.net/article/form/25.txt
    楼主看看这个!
      

  3.   

    下面是我的代码,有数据的事件响应正常,不过读到的数据都是wwwwwww(正确数据:champtek),能帮我看下代码哪里不对吗?
      

  4.   


    #include <windows.h>
    #include <assert.h>
    #include <stdio.h>
    #include <iostream.h>void main( )
    {
        HANDLE hCom;
        OVERLAPPED o;
        BOOL fSuccess;
        DWORD dwEvtMask;

        hCom = CreateFile( "COM1",
            GENERIC_READ | GENERIC_WRITE,
            0,    // exclusive access 
            NULL, // default security attributes 
            OPEN_EXISTING,
            NULL,
            NULL 
            );

        if (hCom == INVALID_HANDLE_VALUE) 
        {
            // Handle the error. 
            return;
        }

        // Set the event mask. 

        fSuccess = SetCommMask(hCom, EV_RXCHAR);

        if (!fSuccess) 
        {
            // Handle the error. 
            return;
        }

        // Create an event object for use by WaitCommEvent. 

        o.hEvent = CreateEvent(
            NULL,   // default security attributes 
            FALSE,  // auto reset event 
            FALSE,  // not signaled 
            NULL    // no name
    );
        

        // Intialize the rest of the OVERLAPPED structure to zero.
        o.Internal = 0;
        o.InternalHigh = 0;
        o.Offset = 0;
        o.OffsetHigh = 0;

        assert(o.hEvent); BYTE inbuff[100];
    DWORD nBytesRead,dwEvent,dwError;
    COMSTAT cs;
    while(true)
    {
    if(WaitCommEvent(hCom,&dwEvent,NULL))
    {
    ClearCommError(hCom,&dwError,&cs);
    if((dwEvent&EV_RXCHAR)&&cs.cbInQue)
    {
    if(!ReadFile(hCom,inbuff,cs.cbInQue,&nBytesRead,NULL))
    printf("ERROR");
    else
    {
    int len=cs.cbInQue;
    for(int i=0;i<len;i++)
    printf("%c",inbuff[i]);
    }
    }
    }
    PurgeComm(hCom,PURGE_RXCLEAR);
    }
    }