facebook pixel מדריך: ספריה - Ethernet - בדיקת (EthernetClient)if - www.4project.co.il
Main logo www.4project.co.il
כל הרכיבים לפרוייקט שלכם
עגלת קניות

העגלה ריקה

לקוחות נכבדים, אלה שעות הפעילות של המחסן במהלך פסח 2024:
ערב חג וחג ראשון (22-23/04) - המחסן סגור
חול המועד (24-25/04) - המחסן יפעל בין 8:00 עד 15:00
ערב חג וחג שני (28-29/04) - המחסן סגור
נחזור לפעילות רגילה ביום שלישי 30/04
חג שמח!

ספריה - Ethernet - בדיקת (EthernetClient)if


2022-06-14 13:17:37
בדיקה (EthernetClient)if מאפשרת לבדוק האם אובייקט של צד הלקוח זמין לעבודה.


תחביר

קוד: בחר הכל
if (client)

פרמטרים:
אין.

הפונקציה מחזירה true כשהאובייקט זמין לעבודה.


דוגמה

קוד: בחר הכל
#include <Ethernet.h>
#include <SPI.h>


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
byte server[] = { 64, 233, 187, 99 }; // Google

EthernetClient client;

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println("connecting...");
  while(!client){
    ; // wait until there is a client connected to proceed
  }
  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}



ראו גם:

Ethernet

פירוט שפת תכנות לסביבת Arduino


עמוד זה הוא תרגום של if (EthernetClient) לפי רישיון Creative Commons Attribution-ShareAlike 3.0.