Define a delegate:
Delegate void Electronicscales (string str); Electronicscales strc;
In the initialization of the electronic weigh:
#regionElectronic weighing settings Public voidElectronic () {//Initialization Window program accepts electronic scale information Try{serialport1.portname="COM3"; Switch(Share.getcompanyid ()) { Case 1: Serialport1.baudrate= -; Break; default: Serialport1.baudrate=2400; Break; } strc=Newelectronicscales (Updatetextbox); Serialport1.datareceived+=NewSystem.IO.Ports.SerialDataReceivedEventHandler (serialport1_datareceived); Serialport1.close (); Serialport1.open (); } Catch { } } Private voidUpdatetextbox (stringweight) {Trueweight=int. Parse (weight); Trueweight interface text Box}Private voidSerialport1_datareceived (Objectsender, System.IO.Ports.SerialDataReceivedEventArgs e) { Try { varStrweight =""; Thread.Sleep ( $); stringcom =serialport1.readexisting (); Char[] ch = com. Substring (COM. IndexOf ("=") +1,6). ToCharArray (); Array.reverse (CH); Strweight= Convert.ToInt32 (New string(CH)). ToString (); This. Invoke (STRC,New string[] {strweight}); } Catch { } } #endregion
COM3 is the port number, you need to set the port number to COM3
Add an electronic weigh program