02-11-18, 10:49 PM
(16-10-15, 11:05 PM)الشاكي لله كتب : الطريقة هي باستعمال الSERIAL PORTالسلام عليكم أخي و بارك الله فيك. يعني أقدر بهذه الطريقة استحب الداتا فيي داخل جدول في الداتا بيز؟
الدالة موجودة عندي :-
دالة ارسال نص للاردوينو
PHP كود :
Private vcp As New System.IO.Ports.SerialPort()
Private Sub WriteToSerial(stringToWrite As String, portName As String)
vcp.BaudRate = 9600
vcp.DataBits = 8
vcp.StopBits = StopBits.One
vcp.Parity = Parity.None
vcp.PortName = portName
vcp.Open()
vcp.Write(stringToWrite)
vcp.Close()
End Sub
الدالة المقابلة التي تقرأ النص المرسل من الكمبيوتر الى الاردوينو هي :
PHP كود :
char inData[20]; // Allocate some space for the string
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character
void setup()
{
pinMode(4,OUTPUT);
Serial.begin(9600);
}
void loop()
{
//high
if (Comp("4_High")==0)
{
//اذا تم ارسال النص "4_High" من الكمبيوتر قم بتنفيذ شيئ معين هنا كتشغيل pin مثلا :
digitalWrite(4,HIGH);
}
}
char Comp(char* This) {
while (Serial.available() > 0) // Don't read unless
// there you know there is data
{
if(index < 19) // One less than the size of the array
{
inChar = Serial.read(); // Read a character
inData[index] = inChar; // Store it
index++; // Increment where to write next
inData[index] = '\0'; // Null terminate the string
}
}
if (strcmp(inData,This) == 0)
{
for (int i=0;i<19;i++)
{
inData[i]=0;
}
index=0;
return(0);
}
else
{
return(1);
}
}
طبعا هذا الكود تضعينه في الsketch وترفعينه للاردوينو
في الدالة loop تضعين جملة الشرط لتحقق من النص الذي تم استقباله ..
اذا استقبلت كذا . نفذ كذا