c# - Reading any string coming from Arduino -


i developing application read data through serial port. trying read string empty or in it.

my first attempt creating array inside of able insert come serial port.

string[] pass = new string[4]; pass[0] = ""; pass[1] = "something"; pass[2] = "to"; pass[3] = "read";  (int = 0; < pass.length; i++) {     string element = pass[i]; } 

but isn't work me because wanna read thing serial port. in next option, in data.tostring() == "any string want".

string data = serport.readexisting(); if (data.tostring() == "any string want") {     environment.exit(0); } 

basically, instead of "any string want" every time send through arduino recognized application.

do guys have suggestions this? in other words, if incoming data equal string written arduino something.

you need decide on termination char , add arduino code sending serial string , char in incoming data. i'm using carriage return line feed.

    private string receiveddate = string.empty;     private system.io.ports.serialport mport;     private void form1_load(object sender, eventargs e)     {         mport = new serialport("com1", 9600, parity.none,8, stopbits.one);         mport.datareceived += new serialdatareceivedeventhandler(mport_datareceived);     }      private void mport_datareceived(object sender, serialdatareceivedeventargs e)     {         receiveddate += mport.readexisting();         if (receiveddate.contains("\r\n"))         {             //show data             //clear receiveddate          }      } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -