-
November 16th, 2007, 06:15 AM
#1
vc++ 6 serial communication problem
hello everyone. i'm new to this forum and it's my first time to post on an english language /i'm from poland/ forum about a problem i have.
my problem is that i have to write a console based program to communicate with an electronic device via rs232 com port. the communication has to be realized by sending bytes of information to a micro controller. and the problem is that i'm not really a great programmer and really new to vc++, so if anyone could try to explain how to do such a thing i would be most grateful: which libraries to use? weather those are standard c++ libraries or vc++ ones. which fuctions to use.
as for the structure of the program i think that it should look something like this:
run prog->close port->open port->send data->close port->exit prog.
thank you for any help you can spare.
-
November 16th, 2007, 06:45 AM
#2
Re: vc++ 6 serial communication problem
1. Serial Port I/O
2. MSDN: search for thre "Serial Communications in Win32" article and MTTTY sample.
Victor Nijegorodov
-
November 16th, 2007, 06:49 AM
#3
Re: vc++ 6 serial communication problem
thanks for the link and here's my first question. which library should i include in my cpp file?
-this isn't a standard vc++ library. i get a :
fatal error C1083: Cannot open include file: 'serial.h':
which variables should i declare first? before writing down the code about opening the port?
[quote]
hCom = ::CreateFile(_T("\\\\.\\COMn"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED,NULL);
[\quote]
Last edited by rafaltypiak; November 16th, 2007 at 06:58 AM.
-
November 16th, 2007, 06:57 AM
#4
Re: vc++ 6 serial communication problem
You should create the new project using AppWizard, the project type could be Win32 Console Application that supports MFC.
Victor Nijegorodov
-
November 16th, 2007, 07:01 AM
#5
Re: vc++ 6 serial communication problem
should i mark 'header file sonly' when creating the project or 'none when asked for what database support i'm to include'? i marked header files....
what compund document support would you like to include?: none
hmmm strange..... i wanted to create a console project and it's asking me to choose if i want status bars and so on..... i don't think that's good.
i've chosen file->new->project->win32console->an aplication that supports mfc. and got a rebuild project with:
#include "stdafx.h"
#include "dgfdfg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
Last edited by rafaltypiak; November 16th, 2007 at 07:07 AM.
-
November 16th, 2007, 07:05 AM
#6
Re: vc++ 6 serial communication problem
I guess you don't need any database in this project: neither "database support", nor "header files only", nor any other DB option.
Victor Nijegorodov
-
November 16th, 2007, 07:13 AM
#7
Re: vc++ 6 serial communication problem
ok. i created new->project->consoleapp->support mfs and got something like that:
rs.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "rs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CString strHello;
strHello.LoadString(IDS_HELLO);
cout << (LPCTSTR)strHello << endl;
}
return nRetCode;
}
i included the "#include "serial.h" "
and i still get the same error: fatal error C1083: Cannot open include file
-
November 16th, 2007, 07:22 AM
#8
Re: vc++ 6 serial communication problem
Have you created and included to your project "serial.h" and "serial.cpp" files?
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|