I have written a Visual Basic program that passes data to the serial port. I am able to read and write integers, but I'm apparently missing something when it comes to dealing with strings in C++.
The VB program is simply writing "Hello" to the port...
Dim myPort As New Ports.SerialPort("COM4")
myPort.BaudRate = 9600
myPort.Open()
myPort.Write("Hello")
The code is never validating what is passed to the serial port as "Hello". I've read most of the posts on the forum, but still seem to be missing something...
Trace what happens in your program flow when you have received the first byte ('H') in the serial buffer... then what happens when you receive the 'e'....
Part of your problem is here: myData[sizeof(myData)] = 0;
sizeof cannot be used like this - it always returns a constant.
Edit: I had another thought. Imagine you had declared "char myData [10];", so "myData" has ten elements with subscripts zero to nine.
"sizeof(myData)" is ten, so "myData[sizeof(myData)] = 0;" would write past the end of "myData".
if you've just received the 'H' in "Hello", the first "Serial.available" returns 1, so you execute "for(i = 0; i < 1; i++) myData [0] = 'H'.
The rest of the string, 'ello', still hasn't left the transmitter, so "loop" repeats until 'e' arrives.
"Serial.available" returns 1, and you overwrite the 'H' in "myData[0]" with 'e'.
See where this is going?
(and what Ty Breizh said about not using "sizeof").