CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2007
    Posts
    4

    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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  3. #3
    Join Date
    Nov 2007
    Posts
    4

    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?

    #include "serial.h"
    -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.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  5. #5
    Join Date
    Nov 2007
    Posts
    4

    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.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  7. #7
    Join Date
    Nov 2007
    Posts
    4

    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

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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
  •  





Click Here to Expand Forum to Full Width

Featured