2012-12-08 41 views
5

का आह्वान करेगा, मैं एक प्रोग्राम लिख रहा हूं जो धारावाहिक (एक Arduino से) से भेजे गए आदेशों पर नज़र रखता है और विभिन्न अन्य कार्यक्रमों में कीस्ट्रोक भेजता है।घटना में प्रेषक केवल एक बार सी #

मैंने अपने ईवेंट में एक प्रेषक रखा है, लेकिन यह केवल एक बार चलाएगा ... मैंने कोड के माध्यम से कदम रखा है और यह पहली बार सभी तरह से चलता है लेकिन दूसरी बार नहीं चलता है।

private void portReadEvent(object sender, SerialDataReceivedEventArgs args) 
     { //break here 
      Action dump = delegate() 
      { 
       dumpInfoText(serialPort.ReadExisting()); 
      }; //create my deligate 

      txt_portInfo.Dispatcher.Invoke(dump); //run dispatcher 

     } 

     private void dumpInfoText(string text) 
     { 
      string completeCommand = ""; 
      foreach (char C in text) 
      { 
       if (serDump.Length <=8 && (C != (char)0x0A || C != (char)0x0D)) //check 
       { 
        serDump = serDump + C; //add char 
       } 
       if (serDump.Length == 8) //check to see if my info has a complete command (serDump is global) 
       { 
        completeCommand = serDump; //move to complete 
        serDump = ""; // reset dump 
        if (C == (char)0x0A || C == (char)0x0D) //dont add crlf 
        { 
         serDump = serDump + C; //add char 
        } 
       } 
       if (completeCommand.Length == 8) 
       { 
        txt_portInfo.Text = txt_portInfo.Text + completeCommand; //do something with it. 
       } 
      } 
+3

कृपया प्रेषक धागे पर एक नज़र डालें। – lontivero

उत्तर

0

आह, निश्चित ... सुनिश्चित नहीं क्यों।

private void portReadEvent(object sender, SerialDataReceivedEventArgs args) 
    { 
     txt_portInfo.Dispatcher.Invoke(new Action(() => {dumpInfoText(serialPort.ReadExisting());})); //run dispatcher 

    }