Jump to content

  • Log In with Google      Sign In   
  • Create Account

Serial C++ help!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 JonBMN   Members   -  Reputation: 702

Like
0Likes
Like

Posted 28 August 2012 - 08:49 AM

I am having trouble with my program to simply open the serial port COM4. any help would be appreciated.

#define STRICT
#define _AFXDLL
#include "stdafx.h"
#include <tchar.h>
#include <AFXWIN.H>
#include <windows.h>
#include "Serial\Serial\Serial.h"
#include "Serial\Serial\SerialEx.h"
#include "Serial\Serial\SerialMFC.h"
#include "Serial\Serial\SerialWnd.h"
int WINAPI_tWinMain
	 (
	 HINSTANCE //hInst
	 HINSTANCE //hInstPrev
	 int
	 )
{
	 CSerial serial;

	 serial.Open(_T("COM4"));

	 serial.Setup (CSerial::EBaud9600, CSerial::EData8, CSerial::EParNone, CSerial::EStop1);
	 CSerial::SetupHandshaking;
	 serial.Write("Hello World");

	 serial.Close();
	 return 0;
}

along with the error code..

1>------ Build started: Project: SerialComm, Configuration: Debug Win32 ------
1> stdafx.cpp
1> SerialWnd.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialwnd.cpp(23): warning C4603: 'STRICT' : macro is not defined or definition is different after precompiled header use
1> Add macro to precompiled header instead of defining here
1> c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialwnd.cpp(24) : use of precompiled header
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialwnd.h(25): fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
1> SerialEx.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialex.cpp(23): warning C4603: 'STRICT' : macro is not defined or definition is different after precompiled header use
1> Add macro to precompiled header instead of defining here
1> c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialex.cpp(24) : use of precompiled header
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serialex.h(26): fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
1> Serial.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serial\serial\serial.h(22): fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
1> SerialComm.cpp
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serialcomm.cpp(2): warning C4603: 'STRICT' : macro is not defined or definition is different after precompiled header use
1> Add macro to precompiled header instead of defining here
1> c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serialcomm.cpp(5) : use of precompiled header
1>c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serialcomm.cpp(3): warning C4603: '_AFXDLL' : macro is not defined or definition is different after precompiled header use
1> Add macro to precompiled header instead of defining here
1> c:\users\jonbecher\documents\visual studio 2012\projects\serialcomm\serialcomm\serialcomm.cpp(5) : use of precompiled header
1>c:\program files\microsoft visual studio 11.0\vc\atlmfc\include\afx.h(24): fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
1> Serial.cpp
1>c1xx : fatal error C1083: Cannot open source file: '..\Serial\Serial\Serial.cpp': No such file or directory
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Sponsor:

#2 BitMaster   Crossbones+   -  Reputation: 4088

Like
1Likes
Like

Posted 28 August 2012 - 09:03 AM

None of these errors seem to be related to working with the serial port. Your precompiled headers seem to be messed up. Either fix stdafx.h or remove the include and switch them off in the compile settings. You also seem to be trying to link MFC statically while using the dynamic runtime. Do you actually need MFC at all in the first place?

#3 turch   Members   -  Reputation: 590

Like
1Likes
Like

Posted 29 August 2012 - 07:50 AM

#include "stdafx.h"
needs to be the first line in any source file if you are using a precompiled header. Anything before that is ignored. Move the two defines down below #include "stdafx.h" or put them in the stdafx.h file instead.

Edited by turch, 29 August 2012 - 07:51 AM.


#4 NinjAndroid   Members   -  Reputation: 106

Like
0Likes
Like

Posted 02 September 2012 - 02:05 AM

when using pre-compiled headers, #include "stdafx.h" should always be the first line.
anythig before that is ignored
MoMinis R&D team




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS