Hello from a new member, just got my board!
I'm trying to make it respond to commands over the serial port (something like Firmata, but simpler).
I've written this sketch:
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available()>0) {
int inLen = Serial.available();
char inStr[inLen];
for(int i=0; i<inLen; i++){
inStr[i]=Serial.read();
}
CommandResponse(inStr);
}
delay(100);
}
boolean StringComparer(char str1[],char str2[]){
for(int i=0;i<sizeof(str1)/sizeof(char);i++){
if(str1[i]!=str2[i]){
return false;
}
}
return true;
}
void CommandResponse(char command[]){
char AT[2]={'A','T'};
if(StringComparer(command, AT)){
Serial.println("OK");
}
else{
Serial.println("ERR");}
}
It responds nicely, with 'OK' to 'AT' and 'ERR' to everything else using the built in serial monitor.
Next I tried to do the same with VB.NET, but I'm failing. I can open the port, send the string, and the RX LED on the Arduino flashes, but there is no response (either in VB.NET, or the TX LED).
This has me thinking that the board doesn't understand whatever VB is sending. Am I right? If not, what could be the problem?
Here is the method I use to send the data:
Private Sub Send(ByVal msg As String)
If msg = String.Empty OrElse MyPort Is Nothing Then Return
Try
'Write to the port.
MyPort.Write((msg & vbCrLf).ToCharArray)
'Write to the console.
WriteToConsole(msg)
Catch ex As Exception
ErrorNotifyer("Error sending data.", ex)
End Try
End Sub
By the way, have also tried this without success:
MyPort.WriteLine(msg)
MyPort.WriteLine(msg & vbCrLf)
MyPort.Write(msg & vbNewLine)
MyPort.WriteLine((msg & vbNewLine).ToCharArray)
MyPort.Write("A"c)
Dim b As Byte = 30
MyPort.Write(b)