Ardiono Serial.print and Visual C++

userHead antonioDP 2018-03-04 23:44:37 2447 Views2 Replies
i'm having a couple of trouble using Arduino Leonardo on Lattepanda (LP) board. On LP runs a .exe that is the result of the compiling of VS2015 C++ project. I develop it on my PC with Windows7. The .exe runs at the startup of LP.

I can't read what i write on Arduino using Serial.print. I also tried println, write, several end-line but nothing. The C++ code keeps forever (or the serial port read timeout time) on read statement (i tried ReadLine(), ReadChar(), ReadByte(). Same result).
I have no problems using both arduino's serial monitor and putty instead of my C++ program.
where i'm wrong?

please find below arduino code:

Code: Select all

int led = 13; void setup() { Serial.begin(115200); while(!Serial); pinMode(led, OUTPUT); digitalWrite(led, LOW); } void loop() { if(Serial.available()) { String s = Serial.readString(); digitalWrite(led, HIGH); delay(2000); Serial.println(s); digitalWrite(led, LOW); } }
and my C++ code:

Code: Select all

#include "stdafx.h" #include <stdio.h> using namespace System; using namespace System::IO::Ports; using namespace System::Threading; int main(array<System::String ^> ^args) { String^ strSerialRead = ""; char ch; SerialPort port("COM10", 115200); port.ReadTimeout = 5000; port.Open(); Console::WriteLine("sending GetID"); port.WriteLine("GetID\n"); int r = 0; do { Console::WriteLine("waiting for char"); try { ch = port.ReadChar(); printf("%c", ch); strSerialRead += ch; } catch (TimeoutException ^) { Console::WriteLine("timeout"); Thread::Sleep(5000); } printf("%s\n", strSerialRead); Console::WriteLine("esco"); strSerialRead = ""; Thread::Sleep(15000); return 0; }

arduino virtual serial port is set on COM10 of LP. Whwn i switch LP on COM10 is not available. I have to push arduino's reset button on LP board in order to make it works. It is a problem to me because, as i told before, my .exe program starts at the startup of LO windows 10. How can i fix it?

many thanks