新手小白的问题,急急急
Y_I_Y 2013-02-28 09:02:19 想写一个简简单单的基于MODBUS的串口通信,从一个485的电表上读取数据而已,不知道哪里出错一直就不能用CREATFILE这个函数
#include <iostream>
#include <Windows.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
//#include <afx.h>
#include <time.h>
int main()
{
HANDLE hCom;
DWORD dwError;
char acBuffa[20] = {0};
char acBuffb[20] = {0};
DWORD dwWriteSize = 0;
bool Y = true;
hCom = CreateFile("COM3",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL);
if (hCom == INVALID_HANDLE_VALUE)
{
printf("!!!!");
}
else
{
printf("~~~~\n");
}
strcpy(acBuffa,"01039C5600020A4B");
Y = WriteFile(hCom,acBuffa,16,&dwWriteSize,NULL);
dwError = GetLastError();
Sleep(50);
ReadFile(hCom,acBuffb,4,&dwWriteSize,NULL);
printf("%s",acBuffb);
system("pause");
}
1>------ 已启动生成: 项目: Com, 配置: Debug Win32 ------
1>正在编译...
1>main.cpp
1>f:\modbus\projects\com\com\main.cpp(22) : error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char [5]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>f:\modbus\projects\com\com\main.cpp(35) : warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)
1>生成日志保存在“file://f:\Modbus\Projects\Com\Com\Debug\BuildLog.htm”
1>Com - 1 个错误,1 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========