עבור לתוכן

השוואת מחרוזות

Featured Replies

פורסם

אני חדש בארדוינו ומשחזר כישורי תכנות מלפני שנים

בכל אופן, לקחתי דוגמה של TCP SERVER והיא עובדת מעולה בין הלוח לקליינט בווב

אני שולח מחרוזות ומהן מגיעות ונשלחת הודעה בחזרה

אך כאשר אני מנסה לזהות את המחרוזת כדי להגיב בהתאם לתכנה ההשוואה לא מצליחה למרות שהדפסתי ל DEBUG גם את שתי המחרוזות שאני משווה וגם את אורכן

אשמח לעזרה

(הטקסט שלי נצמד לא נכון בהמשך אך הוא נכון בסביבת הפיתוח)

#include <SPI.h>

#include <Ethernet.h>

// Enter a MAC address, IP address and Portnumber for your Server below.

// The IP address will be dependent on your local network:

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress serverIP(10,0,0,100);

int serverPort=84;

// Initialize the Ethernet server library

// with the IP address and port you want to use

EthernetServer server(serverPort);

void setup()

{

// start the serial for debugging

Serial.begin(9600);

// start the Ethernet connection and the server:

Ethernet.begin(mac, serverIP);

server.begin();

Serial.println("Server started");//log

}

void loop()

{

// listen for incoming clients

EthernetClient client = server.available();

if (client) {

String clientMsg ="";

String workMsg = "";

String compMsg="";

while (client.connected()) {

if (client.available()) {

char c = client.read();

//Serial.print©;

clientMsg+=c;//store the recieved chracters in a string

//if the character is an "end of line" the whole message is recieved

if (c == '\n')

{

workMsg="on";

Serial.println(workMsg);

Serial.println(clientMsg);

if (workMsg==clientMsg)

{

client.println("got you");

}

Serial.println("Message from Client:"+clientMsg);//print it to the serial

client.println("You said:"+clientMsg);//modify the string and send it back

clientMsg="";

}

}

}

// give the Client time to receive the data

delay(1);

// close the connection:

client.stop();

}

}

פורסם

אני חושב שאתה מערבב כאן בין מחלקות String לבין null-terminated char arrays מהדור הישן. יכול להיות שה-\n שמגיע מהקלט ומתווסף למחרוזת גורם לבעיה - אתה יכול לבדוק את זה על ידי הדפסת המחרוזות תו אחרי תו בקוד ASCII, או להסיר את ה-\n הזה ולקוות שזה יעבוד...

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים