c# - IOexception was unhandled through Arduino -
so i'm doing project 1 system transmits data via arduino , xbee , receiving system receives data via arduino , xbee. @ receiving end, i'm sending information visual studios. so, when press stop button stop receiving data ioexception unhandled. how solve this?
the error point line added comment below
my c# codes @ receiving end:
public form1() { initializecomponent(); } private void start_btn_click(object sender, eventargs e) { myport = new serialport(); myport.baudrate = 9600; myport.portname = port_name_tb.text; myport.parity = parity.none; myport.databits = 8; myport.stopbits = stopbits.one; myport.datareceived+=serialdatareceivedeventhandler (myport_datareceived); try { myport.open(); data_tb.text = ""; } catch (exception ex) { messagebox.show(ex.message, "error"); } } void myport_datareceived(object sender, serialdatareceivedeventargs e) { this.invoke(new eventhandler(displaydata_event)); in_data = myport.readline(); //------> error pointed line } private void displaydata_event(object sender, eventargs e) { datetime = datetime.now; string date = datetime.day + "/" + datetime.month; string time = datetime.hour + ":" + datetime.minute + ":" + datetime.second; data_tb.appendtext(date +" " + time + "\t\t" + in_data + "\n"); } private void stop_btn_click(object sender, eventargs e) { try { myport.close(); } catch (exception ex2) { messagebox.show(ex2.message, "error"); } } private void save_btn_click(object sender, eventargs e) { datetime = datetime.now; string date = datetime.day + "/" + datetime.month; string time = datetime.hour + ":" + datetime.minute + ":" + datetime.second; try { string pathfile = @"c:\users\user\desktop\cdata\"; string filename = "prototype.txt"; system.io.file.writealltext(pathfile + filename, data_tb.text); messagebox.show("data has been saved " + pathfile); } catch (exception ex3) { messagebox.show(ex3.message, "error"); } } }
you're not catching exception in switch correctly, hence unhandled ioexception.
you can solve changing catch exception ioexception exx& doing that.
Comments
Post a Comment