Hello everyone,I just stared my first project with arduino. It's a simple "car model" controlled form PC via USB cable. I decided to create my own app to do it.After long nights of searching some libraries(i forgot to look at arduino page..) and info about serial communication i created this simple test app.But i have some problem with it.How i can send a specific signal/value to arduino. I mean in my app i want send int value 1, but arduino don't recognise it as 1.Here is my app code,it's Visual Studio 2010 MFC dialog based

syg=Serial.read(); switch(syg) { case '1': digitalWrite(ledG,HIGH); break; case '0': digitalWrite(ledG,LOW); break; } }}in MFC i posted only buttons code, if i miss something important please write it and i'll post it. I forgot to add i use lib form arduino pages but i modify it a little.

Why? Visual Studio 2010 supports C# which is so much easier to use to design Windows forms based applications AND to send and receive serial data. MFC deserves to be buried deep in a toxic landfill.

Nothing in the C++ code tells us exactly what the port instance is an instance of. So, it is impossible to know what the port.WriteData() method is doing. The fact that the method takes two arguments, a pointer to the data to write, and the number of bytes that the data occupies, implies that the value is written as a stream of bytes. Since an int on the PC is 4 bytes, there will be 4 bytes written to the serial port.

Quote

I mean in my app i want send int value 1, but arduino don't recognise it as 1.

You mean that the Arduino does not recognize it as a '1', which is a lot different than a 1.

The code on the Arduino is expecting the data to be written as a string of characters. I would guess that this is NOT happening in the PC code.

Quote

I forgot to add i use lib form arduino pages but i modify it a little.

I used MFC because my teacher requires it(i will hand over this app to mark).Indeed i didn't used string in code i will fix this and try to run again.link to header file and source:http://www.arduino.cc/playground/Interfacing/CPPWindows

You can use sprintf to convert a variable containing any type of value to a string, and then send that string (using the original library). You'll need to modify the Arduino code to handle more than 1 digit numbers, though.

The string that is sent should contain start-of packet and end-of-packet markers, to make parsing easier/more robust. (Send something like "<1>", instead of 1. Search the forum for "started && ended" for code to collect and parse marker-delimited strings.)

I fixed this problem. As you said arduino was excepting a string, and i send data as int,i changed it and all is OK.i changed only type of buffer i read and write method, and also constructor. if you want i can post it