RS-232 経由でマシン通信用の PC 用のネットからコードを取得することができました。VS2010 で Win32 コンソール アプリケーションを使用しています。私はそれを実行して結果を見たいと思っていました。しかし、修正できないエラーがいくつかあります。
コードは次のとおりです。
// HTHH.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
HANDLE hSerial;
int _tmain(int argc, _TCHAR* argv[])
{
hSerial = CreateFile("COM4",
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (hSerial == INVALID_HANDLE_VALUE)
{
if(GetLastError()==ERROR_FILE_NOT_FOUND)
{
}
}
DCB dcbSerialParams = {0};
dcbSerial.DCBlength=sizeof(dcbSerialParams);
if (!GetCommState(hSerial, &dcbSerialParams))
{
}
dcbSerialParams.BaudRate=CBR_9600;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;
if(!SetCommState(hSerial, &dcbSerialParam))
{
}
COMMTIMEOUTS timeouts={0};
timeouts.ReadIntervalTimeout=50;
timeouts.ReadTotalTimeoutConstant=50;
timeouts.ReadTotalTimeoutMultiplier=10;
timeouts.WriteTotalTimeoutConstant=50;
timeouts.WriteTotalTimeoutMultiplier=10;
if(!SetCommTimeouts(hSerial, &timeouts))
{
}
char szbuff[n+1] = {0};
DWORD dwBytesRead = 0;
if(!ReadFile(hSerial, szbuff, n, &dwBytesRead, NULL))
{
CloseHandle(hSerial);
return 0;
}
エラーは次のとおりです:--
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(17): エラー C2664: 'CreateFileW': パラメーター 1 を 'const char [5]' から 'LPCWSTR に変換できません'
1> 指されている型は無関係です。変換には reinterpret_cast、C スタイルのキャスト、または関数スタイルのキャストが必要です
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(28): エラー C2065: 'dcbSerial': 宣言されていない識別子
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(28): エラー C2228: '.DCBlength' の左側には class/struct/union が必要です
1> タイプは「未知のタイプ」です
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(38): エラー C2065: 'dcbSerialParam': 宣言されていない識別子
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(53): エラー C2065: 'n': 宣言されていない識別子
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(56): エラー C2065: 'n': 宣言されていない識別子
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(64): 致命的なエラー C1075: 'c:\users\ の左中かっこ '{' の前にファイルの終わりが見つかりましたsinganathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(10)' が一致しました ========== ビルド: 0 成功、1 失敗、0 最新、0 スキップ==========
申し訳ありませんが、非常に長いです。あなたのアドバイスに感謝します。
ありがとう