Go Down

Topic: Talk to Arduino with Visual Studio in C++ (Read 1 time) previous topic - next topic

Dumpsome

Apr 18, 2009, 02:20 am Last Edit: Apr 18, 2009, 04:46 pm by tuzzer Reason: 1
My objective is to be able to receive variables or data from various sensors on the Arduino board and, also, to control actuator, such as motors, using the computer by programming in C++. I want to be able to program like RoboRealm and do other more power-demanding task on the computer and have it to control motors and sensors.

I would really want some ways to do that. I have tried different thing on the internet... but none of them seem to work. Is there any simple way to do this??


I read about how to set up a serial connection in the Playground: http://www.arduino.cc/playground/Interfacing/CPPWindows

I tried to build the code but that gave me some error.


Quote
1>------ Rebuild All started: Project: ComputerControl, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'ComputerControl', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>ComputerControl.cpp
1>c:\b-drive\clubs\mech warfare\arduino robot\computercontrol\computercontrol\computercontrol.cpp(17) : error C2664: 'CreateFileW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\B-Drive\Clubs\Mech Warfare\Arduino Robot\ComputerControl\ComputerControl\Debug\BuildLog.htm"
1>ComputerControl - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


Then I tried to cast 'LPCWSTR' to the parameter 1 (port). I got another error.

Quote
1>------ Rebuild All started: Project: ComputerControl, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'ComputerControl', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>ComputerControl.cpp
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\B-Drive\Clubs\Mech Warfare\Arduino Robot\ComputerControl\Debug\ComputerControl.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\B-Drive\Clubs\Mech Warfare\Arduino Robot\ComputerControl\ComputerControl\Debug\BuildLog.htm"
1>ComputerControl - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


Is this the right way to do this? Or are there other solutions?

Coding Badly

#1
Apr 19, 2009, 10:06 am Last Edit: Apr 19, 2009, 10:08 am by bcook Reason: 1
For the first problem, it looks like you're trying to build perform a UNICODE build.  I have no idea how to switch Visual Studio to from UNICODE to ANSI simply because everything I've ever built was ANSI.  If you can find an ANSI option (or UNICODE OFF option), choose it and try again.

It's unlikely that typecasting from "char*" to "LPCWSTR" is safe.

The second problem could also be that you're performing a UNICODE build.  

- Brian

Dumpsome

I am trying to find ways to do that in Visual Studio.

But in the meanwhile, I have tried to compile it in Code Block. I got this error message:
Quote

-------------- Build: Debug in CodeBlockSerial ---------------

Compiling: SerialClass.cpp
Linking console executable: bin\Debug\CodeBlockSerial.exe
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(main.o):main.c:(.text+0x104): undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
1 errors, 0 warnings


This time, I simply created a header file (SerialClass.h), and a source file (SerialClass.cpp). And copy the code from the tutorial directly. Then, I added both file as Build Target in Project/Properties. Is there any project setting I should make?

Dumpsome

Back to Visual Studio. I think I have found a way to turn off Unicode.
I did that by going to Project/Properties/Configuration Properties/General/Character Set and change it to "not set"


But now i simply get the second error when I cast LSCWTR to the parameter.
Quote
1>------ Rebuild All started: Project: ComputerControl, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'ComputerControl', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>SerialClass.cpp
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\B-Drive\Clubs\Mech Warfare\Arduino Robot\ComputerControl\Debug\ComputerControl.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\B-Drive\Clubs\Mech Warfare\Arduino Robot\ComputerControl\ComputerControl\Debug\BuildLog.htm"
1>ComputerControl - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========



Go Up