Quantcast
Channel: Visio General Questions and Answers for IT Professionals forum
Viewing all articles
Browse latest Browse all 2333

Sending command to device over internet and getting the response back

$
0
0

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 "";
            }
        }  


Viewing all articles
Browse latest Browse all 2333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>