Hi all,
I do not arrive to read the characters sent from Arduino to the PC. The software that I develop on PC is written in Delphi. In fact, nothing in the PC whereas with serial monitor, all is OK.
You will find enclosed the part of code which are concerned.
Somebody can help me to solve this pb ?
Thank you in advance for your answer.
DELPHI (with RSCOM.DLL library) :
Ack : string;
...........
clearbuffer();
sendstring('O');
while (Ack ='') do begin
Ack :=readstring();
if (Ack <> '') then begin
showmessage ('message51 recu :.'+Ack+'.');
clearbuffer();
end;
end;
In Arduino :
#define bell_1 13 //Digital 2
int duration = 1040; //Length
void setup(){
pinMode(bell_1,OUTPUT);
Serial.begin(9600);
}
void loop(){
while(1){ serial_server();
}
}
void serial_server(){
byte serial_in;
if (Serial.available()>0){
serial_in = Serial.read();
char temp_char = char(serial_in);
play_sequence( &temp_char );
}
}
void play_sequence(char *notes_string){
int len = strlen(notes_string);
for (int n = 0; n < len; n++){
switch (notes_string[n]) {
case 'c': play(1); break;
.......
case 'O': play(9); break;
default: ; break;
}
}
}
void play(int note_num){
switch (note_num) {
case 1: digitalWrite(bell_1,HIGH); delay(duration); digitalWrite(bell_1,LOW); break;
...............
case 9: Serial.print("R"); break;
}
}