PDA

View Full Version : Talk to Arduino with Visual Studio in C++



tuzzer
04-18-2009, 09:48 AM
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.



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\computercont rol.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\BuildL og.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.



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\BuildL og.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?

metaform3d
04-18-2009, 02:00 PM
Not finding "_main" sounds like a problem with project settings. Have you been able to build a "Hello World" test app?

Adrenalynn
04-18-2009, 11:13 PM
You can also try one of my console tutorial applications in the Tutorials section. You'd need to modify them for your application, but they do show you how to talk to the serial port in VC#. Talking to the serial port in other forms of .Net is practically identical except for syntax.

integral
04-16-2012, 12:48 PM
I came across this post while looking for a solution to the same problem.
I solved it in Visual C++ 2008 Express by doing the following:

Project -> Project Properties -> Configuration Properties -> General -> Character Set -> Use Multi-Byte Character Set