c# - Connecting to Weight Scale through RS232 -
i have been cracking head trying figure how read weight scale, i'm kind of new c# , have never dealt com ports before, put code examples found online , other articles have been researching. i'm kind of stock, appreciate if there give me light of why code not displaying anything. scale i'm using nv-1.5r cci companies. i'm connecting trough rs232 port using db9 female female null modem cable. code have far:
using system; using system.io.ports; using system.collections.generic; namespace serialcombuffering { class program { serialport com = new serialport(serialport.getportnames()[0], 9600, parity.none, 8, stopbits.one); list<byte> bbuffer = new list<byte>(); string sbuffer = string.empty; static void main(string[] args) { new program(); } program() { com.datareceived += new serialdatareceivedeventhandler(com_datareceived); com.open(); console.writeline("waiting incoming data…"); console.readkey(); } void com_datareceived(object sender, serialdatareceivedeventargs e) { // use either binary or string technique (but not both) // buffer , process binary data while (com.bytestoread > 0) bbuffer.add((byte)com.readbyte()); processbuffer(bbuffer); // buffer string data sbuffer += com.readexisting(); processbuffer(sbuffer); } private void processbuffer(string sbuffer) { console.writeline(bbuffer); console.writeline(sbuffer); console.readkey(); } private void processbuffer(list<byte> bbuffer) { // in byte array useful information // remove useful data buffer } } }
i'm not sure else after this, hoping display , figure out there, whenever run literally nothing. nice if kind of guide me trough next. , appreciate collaboration before hand!
Comments
Post a Comment