C # development Weighbridge weighing software

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.