Sending command to device over internet and getting the response back

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

July 28th, 2015 9:01am

Sorry,

You're in the wrong forum, you might consider a Visual Studio forum not an Office one.

al edlund

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 2:59pm

Hi Sir,

This forum is talking about MS Visio that a part of MS office, not Visual Studio, please post the question to VS forum:

https://social.msdn.microsoft.com/Forums/en-US/home?category=vslanguages

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

Regards,

George Zhao
TechNet Community Support

July 29th, 2015 1:13am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics