Receive data from serial port in one line c# -


i have code takes data serial com port weighing machine. works okay, receives data in several lines. i'm trying make receive data in 1 line.

in code below need take weight weigh bridge machine automatically timer using visual studio 2005. works, receive weight values on several lines.

i need receive weight in 1 line , automatically update , convert integer.

using system; using system.io.ports; using system.windows.forms;  namespace commsample {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }          void application_idle(object sender, eventargs e)         {             label3.text = serialport1.isopen ? "[open]" : "[closed]";         }          private void button1_click(object sender, eventargs e)         {             if (pollingcheckbox.checked)             {                 timer1.enabled = true;             }                else             {                 timer1.enabled = false;                 transmitcommand();             }         }          private void transmitcommand()         {             if (textbox1.text.length > 0)             {                 if (serialport1.isopen)                 {                     serialport1.write(textbox1.text + "\r");                 }             }         }          private void closeport()         {             if (serialport1.isopen)             {                 serialport1.datareceived -= new serialdatareceivedeventhandler(serialport1_datareceived);                 serialport1.close();             }         }          private void closeporttoolstripmenuitem_click(object sender, eventargs e)         {             closeport();         }          private void exittoolstripmenuitem_click(object sender, eventargs e)         {             close();         }          private void form1_load(object sender, eventargs e)         {             serialport1.portname = properties.settings.default.port;             serialport1.baudrate = properties.settings.default.baud;             serialport1.databits = properties.settings.default.databits;             serialport1.parity = (parity)enum.parse(typeof(parity), properties.settings.default.parity);             serialport1.stopbits = (stopbits)enum.parse(typeof(stopbits), properties.settings.default.stopbits);             application.idle += new eventhandler(application_idle);         }          private void openport()         {             serialport1.open();             serialport1.datareceived += new serialdatareceivedeventhandler(serialport1_datareceived);         }          private void openporttoolstripmenuitem_click(object sender, eventargs e)         {             openport();         }          private void optionstoolstripmenuitem_click(object sender, eventargs e)         {             closeport();             using (form2 form = new form2())             {                 if (form.showdialog(this) == dialogresult.ok)                 {                     serialport1.portname = properties.settings.default.port;                     serialport1.baudrate = properties.settings.default.baud;                     serialport1.databits = properties.settings.default.databits;                     serialport1.parity = (parity)enum.parse(typeof(parity), properties.settings.default.parity);                     serialport1.stopbits = (stopbits)enum.parse(typeof(stopbits), properties.settings.default.stopbits);                 }             }         }          void serialport1_datareceived(object sender, serialdatareceivedeventargs e)         {             if (!invokerequired)             {                 if (e.eventtype == serialdata.chars)                 {                     string portdata = serialport1.readexisting();                     textbox2.appendtext(portdata);                 }             }             else             {                 serialdatareceivedeventhandler invoker = new serialdatareceivedeventhandler(serialport1_datareceived);                 begininvoke(invoker, new object[] { sender, e });             }         }          private void pollingcheckbox_checkedchanged(object sender, eventargs e)         {             if (timer1.enabled && !pollingcheckbox.checked)             {                 timer1.enabled = false;             }         }          private void timer1_tick(object sender, eventargs e)         {             if (pollingcheckbox.checked)             {                 transmitcommand();             }         }     } } 


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -