Beispiel #1
0
        private void btnGetStateBlock_Click(object sender, EventArgs e)
        {
            BravaConnection myConnection = new BravaConnection();

            myConnection.BravaIP = System.Net.IPAddress.Parse(txtIPAddr.Text);

            myConnection.BravaPort = Int16.Parse(txtIPPort.Text);


            RequestElectricityMeter myRequest = new RequestElectricityMeter();

            BravaSocket mySocket = new BravaSocket(myRequest, myConnection);

            try
            {
                mySocket.OpenConnection();

                mySocket.DoTransaction();

                myConnection.rqStream.Close();

                myRequest.ParseResultStream();

                MessageBox.Show(myRequest.ResultXML.OuterXml);
            }
            catch (Exception)
            {
                mySocket.SocketClient.Close();
                throw;
            }
        }
Beispiel #2
0
        private System.Xml.XmlDocument readMeter(System.Net.IPAddress destIPAdr, Int16 destPortNum)
        {
            BravaConnection myConnection = new BravaConnection();

            myConnection.BravaIP = destIPAdr;

            myConnection.BravaPort = destPortNum;

            RequestElectricityMeter myRequest = new RequestElectricityMeter();

            BravaSocket mySocket = new BravaSocket(myRequest, myConnection);

            try
            {
                mySocket.OpenConnection();

                mySocket.DoTransaction();


                myConnection.rqStream.Close();



                myRequest.ParseResultStream();


                MessageBox.Show(myRequest.ResultXML.OuterXml);

                return(myRequest.ResultXML);
            }
            catch (System.Net.Sockets.SocketException ex)
            {
                if ((ex.ErrorCode == 10061) || (ex.ErrorCode == 10060))
                {
                    return(null);
                }
                else
                {
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                mySocket.SocketClient.Close();
            }

            return(null);
        }