注册 登录
编程论坛 单片机编程

求c语言打开串口的完整程序或修改一下下面的程序

ren1375342 发布于 2013-04-12 19:43, 4494 次点击
// kkk.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <windows.h>
#include <afxwin.h>
#include <afx.h>


int _tmain(int argc, _TCHAR* argv[])
{
     HANDLE hcom=CreateFile("COM7",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL);
    if(hcom==INVALID_HANDLE_VALUE)
    {
        AfxMessageBox("打开com失败");
        int err=GetLastError();
        CString st;
        st.Foormat("Error in open COM port:%d\n",err);
    }
    MessageBox(st);
    return ;
}

1 回复
#2
小xiong2013-04-14 23:01
..,
1