cemss80 發表於 2016-7-24 17:01:55

請問怎麼用writefile輸出字串給Arduino

我現在在使用opencv去傳訊息給arduino,想請問怎麼用writefile輸出字串給Arduino,我照下面的程式碼是能夠傳送一個字元像是 opencv輸入'r' arduino接收到'r' 然後執行動作 ,但是沒辦法變成 opencv輸入"rr"arduino接收到"rr"這樣


opencv 程式碼

http://aleksandarkrstikj.com/downloads/code/tracker/tracker.cpp

arduino程式碼

http://aleksandarkrstikj.com/downloads/code/tracker/tracker.ino


----以上是能夠達成傳送一個字元來執行動作
我修改arduino的部分變成


#define RED_PIN 3



void setup()
{


Serial.begin(9600);
pinMode(RED_PIN, OUTPUT);


}



String s="";



void loop()
{

if(Serial.available() > 0)
    {

   char c = Serial.read();
   if(c != '\n')
      {
            s += c;
      }
      else
      {
            Serial.println(s);



if(s=="xx\r")
{

    digitalWrite(RED_PIN,HIGH);
}


}

可以透過直接在Arduino上面的方大鏡圖片輸入裏頭輸入xx讓燈泡亮
但是連接opencv後不知道要怎麼修改讓他從原本的輸出字元變成輸出字串
-----------------------------------------------------下面是我擷取opencv傳送部分的程式碼
HANDLE hSerial = CreateFile(L"COM3", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);char outputChars[] = "c";---->在想是不是要改這項??但是不知道要怎麼改{:3_91:}       DWORD btsIO;

if (servoOrientation == 1)                     
{               
               outputChars = 'l';----->想變成輸出 "xx"這樣                        
       WriteFile(hSerial, outputChars, strlen(outputChars), &btsIO, NULL);

}

--------------------------------------------

超新手 發表於 2016-7-25 08:29:10

本帖最後由 超新手 於 2016-7-25 08:48 編輯

char outputChars[] = "xx\r\n";
當然...以下這行要拿掉
outputChars = 'l';
頁: [1]
查看完整版本: 請問怎麼用writefile輸出字串給Arduino