hello everyone, lately I've been learning about Arduino and Ethernet Shield...
and I'm new to this...
I currently have an Arduino that can receive and send data to a computer via an interface I created with Delphi
Delphi as a client
Arduino as server
but when I send a few characters of text to the Arduino via the Delphi client socket...
Arduino only accepts 1 character...
ex: I sent "QWERTY"
Arduino receives: "Q"
How can the Arduino receive a message in full, for example 8 characters...
Please help
Here's the code to capture messages on Arduino:
if (client.available() > 0)
{
str = client.read();
if(str=='1')
{ digitalWrite(relay1, relayON);
}
}
on delphi
ClientSocket1.Socket.SendText('qwerty');
reads only one byte..
should use a buffer to accumulate all bytes..
better to terminate the string you send..
maybe like..
ClientSocket1.Socket.SendText('qwerty'+#10);
would make it easier to read it in..
something like this maybe..
//global receive buffer..
char buff[40];
//global int to keep track
int recvCount = 0;
//above setup..
//inside the loop..
if (client.available() > 0)
{
//read a byte..
char c = client.read();
if (c != 10) {
if (recvCount < sizeof(buff) - 1) {
buff[recvCount] = c;
recvCount++;
} else {
//too many chars
buff[0] = c;
recvCount = 1;
}
} else
{
//all done, terminate buff
buff[recvCount] = 0;
//do something with buffer..
Serial.println(buff);
//reset things..
recvCount = 0;
memset(buff, 0, sizeof(buff));
}
}
untested, sorry..
good luck.. ~q
thanks for responding... i will try now...
You're welcome..
fellow delphi user, got some ics and indy projects in my github..
have fun.. ~q
system
Closed
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.