c# - How to print Serial port incomming data to lable -


    private void clibutton_click(object sender, eventargs e)     {         sp = new serialport();         sp.portname = "com14";         sp.baudrate = 19200;         sp.parity = parity.none;         sp.databits = 8;         sp.stopbits = stopbits.one;         sp.handshake = handshake.requesttosend;         sp.dtrenable = true;         sp.rtsenable = true;          sp.open();          if (!sp.isopen)         {             messagebox.show("serial port not opened");             return;         }         sp.writeline("at" + environment.newline);         sp.writeline("at+clip=1" + environment.newline);         byte [] data= new byte [sp.bytestoread];         sp.read(data, 0, data.length);       } 

here code. use communicate mobile phone through serial port. here im sending @ command (at+clip=1 command use take cli of incomming call) serialport. read data of serial port. problem how can print readed data in label.

bytestoread going 0 when run code without debugger. takes time serial port device send response. ought solve problem:

label1.text = sp.readline(); 

readline() keeps reading until detects serialport.newline in response.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -