i'm trying display data received on textbox. realized when data being received on br@y terminal fine (eg. 14:02:33.43 > t 11 22.32) running on software time stamp missing.
am missing out lead this?
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.data.oledb; using system.io; namespace serialcom { public partial class form1 : form { string rxstring; //variable public form1() { initializecomponent(); } private void btnstart_click(object sender, eventargs e) { serialport1.portname = "com4"; serialport1.baudrate = 9600; serialport1.open(); if (serialport1.isopen) { btnstart.enabled = false; btnstop.enabled = true; txtdata.readonly = false; } } private void btnstop_click(object sender, eventargs e) { if (serialport1.isopen) { serialport1.close(); btnstart.enabled = true; btnstop.enabled = false; txtdata.readonly = true; } } private void txtdata_keypress(object sender, keypresseventargs e) { if (!serialport1.isopen) return; // if port closed, don't try send character. char[] buff = new char[8]; // if port open, declare char[] array 1 element. buff[0] = e.keychar; // load element 0 key character. serialport1.write(buff, 0, 1); // send 1 character buffer. e.handled = true;// set keypress event handled character won't // display locally. if want display, omit next line. } private void displaytext(object sender, eventargs e) { txtdata.appendtext(rxstring); } private void serialport1_datareceived(object sender, system.io.ports.serialdatareceivedeventargs e) { rxstring = serialport1.readexisting(); this.invoke(new eventhandler(displaytext)); streamwriter mystreamwriter = new streamwriter(@"c:\testing.txt",true); //true tell sw append file instead of overwriting mystreamwriter.write(rxstring); mystreamwriter.flush(); mystreamwriter.close(); } private void form1_formclosing(object sender, formclosingeventargs e) { if (serialport1.isopen) serialport1.close(); } }
}
basically, wrong saying time stamp included in data received.. need add in time stamp on own.. act record of when did received following data.
as result, what's missing this
string time = datetime.now.tostring("dd/mm/yyyy hh:mm:ss.ff")
hope helps people struggling problem too.
Comments
Post a Comment