public string GetScaleWeight(string val1, string val2)//GetWeight contains the code to fetch the weight from the scale// { try { Socket sc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//here we are using socket programming// IPAddress ip = IPAddress.Parse(val1); // to connect to the scale device// IPEndPoint dp = new IPEndPoint(ip, int.Parse(val2)); sc.Connect(dp); Byte[] myArray = new Byte[100]; int value = Convert.ToInt32("5", 16); string stringValue = Char.ConvertFromUtf32(value); sc.Send(Encoding.ASCII.GetBytes((stringValue)));//passing the hex command to the machine// int no = sc.Receive(myArray);//getting the length of the result array// string str = System.Text.Encoding.ASCII.GetString(myArray);//getting the result and storing it in a string// sc.Close(); str = str.Substring(0, no);//checking and removing any unwanted garbage value if any // return str; } catch { return ""; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)