Pages: [1]   Go Down
Author Topic: Talk to Arduino with Visual Studio in C++  (Read 1031 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: April 18, 2009, 09:46:14 am by tuzzer » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12741
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: April 19, 2009, 03:08:18 am by bcook » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ==========

Logged

Pages: [1]   Go Up
Jump to: