i managed code net pc machine communication via rs-232. i'm using win32 console application in vs2010. wanted run , see outcome. have errors unable rectify.
heres's code:
// hthh.cpp : defines entry point 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; }
the errors follows:--
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(17): error c2664: 'createfilew' : cannot convert parameter 1 'const char [5]' 'lpcwstr'
1> types pointed unrelated; conversion requires reinterpret_cast, c-style cast or function-style cast
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(28): error c2065: 'dcbserial' : undeclared identifier
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(28): error c2228: left of '.dcblength' must have class/struct/union
1> type ''unknown-type''
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(38): error c2065: 'dcbserialparam' : undeclared identifier
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(53): error c2065: 'n' : undeclared identifier
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(56): error c2065: 'n' : undeclared identifier
1>c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(64): fatal error c1075: end of file found before left brace '{' @ 'c:\users\singanathan\documents\visual studio 2010\projects\hthh\hthh\hthh.cpp(10)' matched ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
sorry, lenghty. appreciate advise.
thanks
you compiling targeting unicode
, createfile
maps createfilew
expects wide character arrays, wchar_t*
. "com4"
char
literal. change l"com4"
.
the compiler told dcbserial
undeclared. it's right. , same dcbserialparam
. variable declared named dcbserialparams
.
and did not declare n
@ all.
Comments
Post a Comment