2012 was done a scale weighing software, recently the company has also received a weighbridge weighing software project, the problems encountered to summarize for later use.
1. Wiring problems
Because the client side originally used the instrument alone, the meter does not have wiring and computer connection, this is a lot of trouble to do the wiring. Wiring method for the instrument end of the 7, 8, the computer end is 2, 5
2. Read meter weigh Count
The code basically inherits the code of the weighing software that was developed for another customer for 2012 years.
Note: The use of the scale of the customer is Taishan weighing factory out of the XK3200, but the instructions and the Yaohua series of Weighbridge compatible, and the previous customer used the Weighbridge is Yaohua XK3190, probably so the code can be directly generic.
The following code, using the SerialPort control, named Port
Weighing the Form Designer code page FrmWeigh.designer.cs
This.port.BaudRate = 2400;this.port.parity = System.io.ports.parity.even;this.port.stopbits = System.io.ports.stopbits.onepointfive;this.port.datareceived + = new System.IO.Ports.SerialDataReceivedEventHandler (this.port_datareceived);
The weigh form FrmWeigh.cs gets the core code portion of the Weighbridge gauge:
1 /// <summary>2 ///Serial port reading data3 /// </summary>4 Private voidPort_datareceived (Objectsender, System.IO.Ports.SerialDataReceivedEventArgs e)5 {6Thread.Sleep ( -); 7 if(false== This. Port. IsOpen)return;8 byteFirstbyte =Convert.tobyte (port. ReadByte ());9 if(Firstbyte = =0x02)Ten { One intBytesread =Port. Readbuffersize; A byte[] Bytesdata =New byte[bytesread]; - bytebytedata; - the for(inti =0; I < bytesread-1; i++) - { -Bytedata =Convert.tobyte (port. ReadByte ()); - if(Bytedata = =0x03)//End + { - Break; + } ABytesdata[i] =bytedata; at } -Strreceive =Encoding.Default.GetString (bytesdata); - } -Tbweight.invoke (NewEventHandler (Delegate{Tbweight.text =Getweightofport (strreceive);}); - } - in /// <summary> - ///returns the weight of the serial read to /// </summary> + /// <param name= "?" ></param> - /// <returns></returns> the Private stringGetweightofport (stringweight) * { $ if(string. IsNullOrEmpty (weight) | | Weight. IndexOf ("+") <0|| Weight. Length <6)Panax Notoginseng { - return "0.000"; the } +Weight = weight. Replace ("+",""); AWeight =int. Parse (weight. Substring (0,3)). ToString () +"."+ weight. Substring (3,3); the returnweight; +}
C # development Weighbridge weighing software