【发布时间】:2019-09-15 06:14:04
【问题描述】:
我必须将信息从 uController 传输到我的笔记本电脑。当我创建文件时,我收到以下错误。如果您看到脚本,我认为更容易进行故障排除。
因为它说 'LPCWSTR' 中的 'char [20]' 不适合,所以我将其更改为:
CreateFile((LPCWSTR)name, GENERIC..
现在我可以编译程序了,但我仍然得到 INVALID_HANDLE_VALUE,并且我无法打开端口。
我的串行例程:
#include <stdlib.h>
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "com_bg.hpp"
char name[20]=""; //between the "" inserting COM"X"
...
do
{
port = CreateFile(name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (port==INVALID_HANDLE_VALUE)
{
k++;
}
}
while ((k<MAXCREAT) && (port==INVALID_HANDLE_VALUE));
if (k==MAXCREAT)
return(ERR_COM);
...
我的主要看起来是这样的:
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <conio.h>
#include "com_bg.hpp"
#include "com._bg.cpp"
#include "tchar.h"
using namespace std;
int _tmain(int argc, _TCHAR *argv[])
{
printf("Hello\n");
getch();
err = openCom(8, 9600, NONE,1,RTSDTRLOW);
if (err != OK)
{
closeCom();
printf("Failed to OpenPort\n");
return 0;
}
…
【问题讨论】: