ฉันกำลังพัฒนาแอพพลิเคชั่นที่สื่อสารกับวงจรอิเล็กทรอนิกส์ของฉันผ่านทางพอร์ต 4 ฉันสามารถส่งข้อมูลจากพีซีไปยังวงจรได้โดยไม่มีปัญหา จากนั้นฉันก็รับข้อมูลกลับจากวงจร อย่างไรก็ตาม เมื่อฉันพยายามรับข้อมูลจากวงจรของฉันเป็นครั้งที่สอง ฉันได้รับข้อมูลที่ไม่ถูกต้องจากวงจรนั้น ตัวชี้ใด ๆ เกี่ยวกับวิธีแก้ปัญหานี้?
นี่คือรหัส C #:
byte[] Sent_Byte = {1,2,3,4,5,6};
byte[] Received_Byte = new byte[10];
private void button_sendData_Click(object sender, EventArgs e)
{
// I send this data because the circuit is ready to get data
serialPort1.Write("G");
serialPort1.Write(Sent_Byte, 0, 6);
}
private void button_getData_Click(object sender, EventArgs e)
{
// I send this data because the circuit is ready to send data
serialPort1.Write("A");
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
serialPort1.Read(Received_Byte, 0, 10);
}
นี่คือรหัส Arduino:
char Control_OP=0;
char Received_Data[6];
byte Sent_Data[10];
void loop()
{
while(Serial.available())
{
Control_OP = Serial.read(); // determines whether receiving data or sending data
if(Control_OP=='G') // receiving data
{
Number=Serial.readBytes(Received_Data,6);
}
else if(Control_OP=='A') // sending data
{
Serial.write(Sent_Data,10);
}
}
}
A
และดูว่าตอบสนองหรือไม่ นี่คือการแก้ไขปัญหาการสื่อสารแบบอนุกรมขั้นพื้นฐาน - person Matt Burland   schedule 04.02.2014