Esempio n. 1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            BravaConnection myConnection = new BravaConnection();

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

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

            RequestType myRequest = new RequestType();

            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;
            }
        }
Esempio n. 2
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            BravaConnection myConnection = new BravaConnection();

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

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

            RequestType myRequest = new RequestType();

            BravaSocket mySocket = new BravaSocket(myRequest, myConnection);

            try
            {
                mySocket.DoTransaction();

                if (myRequest.State == BravaTransaction.TransactionState.Completed)
                {
                    myRequest.ParseResultStream();
                }

                if (myRequest.State == BravaTransaction.TransactionState.Failed)
                {
                    MessageBox.Show("Transaction Failed.");
                }
                else
                {
                    // Transaction Result is now valid.
                    MessageBox.Show(myRequest.ResultXML.OuterXml);
                }

                //mySocket.OpenConnection();

                //mySocket.DoTransaction();

                //myConnection.rqStream.Close();

                //myRequest.ParseResultStream();

                //MessageBox.Show(myRequest.ResultXML.OuterXml);
            }
            catch (Exception)
            {
                mySocket.SocketClient.Close();
                throw;
            }
        }
Esempio n. 3
0
        private void btnConnectSw_Click(object sender, EventArgs e)
        {
            BravaConnection myConnection = new BravaConnection();

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

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

            ConnectSwitch myConnectSwitch = new ConnectSwitch(0, 0, 0);

            if(radioButton1.Checked)
                myConnectSwitch = new ConnectSwitch((byte)BravaCodes.LoadSwitchCircuits.Circuit1,0,0);

            if (radioButton2.Checked)
                myConnectSwitch = new ConnectSwitch((byte)BravaCodes.LoadSwitchCircuits.Circuit2, 0, 0);

            if (radioButton3.Checked)
                myConnectSwitch = new ConnectSwitch((byte)BravaCodes.LoadSwitchCircuits.Circuit3, 0, 0);

            if (radioButton4.Checked)
                myConnectSwitch = new ConnectSwitch((byte)BravaCodes.LoadSwitchCircuits.Circuit4, 0, 0);

            BravaSocket mySocket = new BravaSocket(myConnectSwitch, myConnection);

            try
            {
                mySocket.OpenConnection();

                mySocket.DoTransaction();

                myConnection.rqStream.Close();

            }
            catch (Exception)
            {
                mySocket.SocketClient.Close();
                throw;
            }
        }
Esempio n. 4
0
        private void button4_Click(object sender, EventArgs e)
        {
            BravaConnection myConnection = new BravaConnection();

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

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

            System.Net.IPHostEntry myIPs = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());

            ConfigureAlertMessageRoute myConfigureAlertRouting = new ConfigureAlertMessageRoute((byte)numRouteRuleNum.Value, myIPs.AddressList[0], Int16.Parse(txtAlertPortNum.Text));

            BravaSocket mySocket = new BravaSocket(myConfigureAlertRouting, myConnection);

            try
            {
                mySocket.OpenConnection();

                mySocket.DoTransaction();

                myConnection.rqStream.Close();
            }
            catch (Exception)
            {
                mySocket.SocketClient.Close();
                throw;
            }
        }
Esempio n. 5
0
        private void button3_Click(object sender, EventArgs e)
        {
            BravaConnection myConnection = new BravaConnection();

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

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

            BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

            for (int x = 0; x <= 7; x++) mySwitchStates[x] = BravaCodes.SwitchState.SwitchOff;

            if (checkBox1.Checked)
                mySwitchStates[0] = BravaCodes.SwitchState.SwitchOn;
            if (checkBox2.Checked)
                mySwitchStates[1] = BravaCodes.SwitchState.SwitchOn;
            if (checkBox3.Checked)
                mySwitchStates[2] = BravaCodes.SwitchState.SwitchOn;
            if (checkBox4.Checked)
                mySwitchStates[3] = BravaCodes.SwitchState.SwitchOn;
            if (checkBox5.Checked)
                mySwitchStates[4] = BravaCodes.SwitchState.SwitchOn;
            if (checkBox6.Checked)
                mySwitchStates[5] = BravaCodes.SwitchState.SwitchOn;
            if (checkBox7.Checked)
                mySwitchStates[6] = BravaCodes.SwitchState.SwitchOn;
            if (checkBox8.Checked)
                mySwitchStates[7] = BravaCodes.SwitchState.SwitchOn;

            SwitchbankUpdate mySwitchbankUpdate = new SwitchbankUpdate(
                mySwitchStates[0],
                mySwitchStates[1],
                mySwitchStates[2],
                mySwitchStates[3],
                mySwitchStates[4],
                mySwitchStates[5],
                mySwitchStates[6],
                mySwitchStates[7]);

            BravaSocket mySocket = new BravaSocket(mySwitchbankUpdate, myConnection);

            try
            {
                mySocket.OpenConnection();

                mySocket.DoTransaction();

                myConnection.rqStream.Close();

            }
            catch (Exception)
            {
                mySocket.SocketClient.Close();
                throw;
            }
        }
Esempio n. 6
0
        private void button2_Click(object sender, EventArgs e)
        {
            BravaConnection myConnection = new BravaConnection();

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

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

            DisplayText myTextDisply = new DisplayText("\0", (byte)numericUpDown1.Value);

            BravaSocket mySocket = new BravaSocket(myTextDisply, myConnection);

            try
            {
                mySocket.OpenConnection();

                mySocket.DoTransaction();

                myConnection.rqStream.Close();

            }
            catch (Exception)
            {
                mySocket.SocketClient.Close();
                throw;
            }
        }
Esempio n. 7
0
        private void SendSwitchState(string ipAddress, string unitName, int port, BravaCodes.SwitchState[] mySwitchStates)
        {
            BravaConnection myConnection = new BravaConnection();

            myConnection.BravaIP = System.Net.IPAddress.Parse(ipAddress);

            myConnection.BravaPort = port;

            SwitchbankUpdate mySwitchbankUpdate = new SwitchbankUpdate(
                mySwitchStates[0],
                mySwitchStates[1],
                mySwitchStates[2],
                mySwitchStates[3],
                mySwitchStates[4],
                mySwitchStates[5],
                mySwitchStates[6],
                mySwitchStates[7]);

            BravaSocket mySocket = new BravaSocket(mySwitchbankUpdate, myConnection);

            try
            {
                mySocket.DoTransaction();

                if (mySwitchbankUpdate.State == BravaTransaction.TransactionState.Completed)
                {
                    mySwitchbankUpdate.State = BravaTransaction.TransactionState.Closed;

                    lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                    currentStatusDAO.ConnectionString = _connectionString;
                    currentStatusDAO.Insert(unitName, "OK");
                }

                if (mySwitchbankUpdate.State == BravaTransaction.TransactionState.Failed)
                {
                    lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                    logDAO.ConnectionString = _connectionString;
                    logDAO.Insert(1, "Unit: " + unitName, "TCP/IP Communications Error due to: BRAVA API or Connection error.", DateTime.Now);

                    lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                    currentStatusDAO.ConnectionString = _connectionString;
                    currentStatusDAO.Insert(unitName, "ERR");
                }
            }
            catch (System.Net.Sockets.SocketException ex)
            {

               lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
               logDAO.ConnectionString = _connectionString;
               logDAO.Insert(1, "Unit: " + unitName, "TCP/IP Communications Error due to: " + ex.ToString(), DateTime.Now);

               lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
               currentStatusDAO.ConnectionString = _connectionString;
               currentStatusDAO.Insert(unitName, "ERR");
            }
            catch (Exception nex)
            {
                HandleException(nex);
            }
            finally
            {
                mySocket.SocketClient.Close();
            }
        }
Esempio n. 8
0
        private void SendBatchSwitchState(string ipAddress, int port, string swState, int status)
        {
            BravaConnection myConnection = new BravaConnection();

            myConnection.BravaIP = System.Net.IPAddress.Parse(ipAddress);

            myConnection.BravaPort = port;

            BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

            SetSwitchStateBatch(swState, status, mySwitchStates);

            SwitchbankUpdate mySwitchbankUpdate = new SwitchbankUpdate(
                mySwitchStates[0],
                mySwitchStates[1],
                mySwitchStates[2],
                mySwitchStates[3],
                mySwitchStates[4],
                mySwitchStates[5],
                mySwitchStates[6],
                mySwitchStates[7]);

            BravaSocket mySocket = new BravaSocket(mySwitchbankUpdate, myConnection);

            try
            {
                mySocket.DoTransaction();

                if (mySwitchbankUpdate.State == BravaTransaction.TransactionState.Completed)
                {
                    mySwitchbankUpdate.State = BravaTransaction.TransactionState.Closed;
                }

                if (mySwitchbankUpdate.State == BravaTransaction.TransactionState.Failed)
                {
                    throw new System.Net.Sockets.SocketException(10004);
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
                mySocket.SocketClient.Close();

                throw;
            }
            finally
            {
                mySocket.SocketClient.Close();
            }
        }
Esempio n. 9
0
        private void SendSwitchState(string ipAddress, int port, SwitchbankUpdate mySwitchbankUpdate)
        {
            BravaConnection myConnection = new BravaConnection();

            myConnection.BravaIP = System.Net.IPAddress.Parse(ipAddress);

            myConnection.BravaPort = port;

            BravaSocket mySocket = new BravaSocket(mySwitchbankUpdate, myConnection);

            try
            {
                mySocket.DoTransaction();

                if (mySwitchbankUpdate.State == BravaTransaction.TransactionState.Completed)
                {
                    mySwitchbankUpdate.State = BravaTransaction.TransactionState.Closed;
                }

                if (mySwitchbankUpdate.State == BravaTransaction.TransactionState.Failed)
                {
                    throw new System.Net.Sockets.SocketException(10004);
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
                mySocket.SocketClient.Close();

                throw;
            }
            finally
            {
                mySocket.SocketClient.Close();
            }
        }
Esempio n. 10
0
        private void SendSwitchState(string ipAddress, int port, string swState, int status)
        {
            BravaConnection myConnection = new BravaConnection();

            myConnection.BravaIP = System.Net.IPAddress.Parse(ipAddress);

            myConnection.BravaPort = port;

            BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

            SetSwitchState(swState, status, mySwitchStates);

            SwitchbankUpdate mySwitchbankUpdate = new SwitchbankUpdate(
                mySwitchStates[0],
                mySwitchStates[1],
                mySwitchStates[2],
                mySwitchStates[3],
                mySwitchStates[4],
                mySwitchStates[5],
                mySwitchStates[6],
                mySwitchStates[7]);

            BravaSocket mySocket = new BravaSocket(mySwitchbankUpdate, myConnection);

            try
            {
                mySocket.OpenConnection();

                mySocket.DoTransaction();

                myConnection.rqStream.Close();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                mySocket.SocketClient.Close();
            }
        }
Esempio n. 11
0
        private void SendSwitchState(string ipAddress, int port, SwitchbankUpdate mySwitchbankUpdate)
        {
            BravaConnection myConnection = new BravaConnection();

            myConnection.BravaIP = System.Net.IPAddress.Parse(ipAddress);

            myConnection.BravaPort = port;

            BravaSocket mySocket = new BravaSocket(mySwitchbankUpdate, myConnection);

            try
            {
                mySocket.DoTransaction();

                #region Todo: We possibly dont care. Validate and remove
                //if (mySwitchbankUpdate.State == BravaTransaction.TransactionState.Completed)
                //{
                //    mySwitchbankUpdate.State = BravaTransaction.TransactionState.Closed;
                //}

                //if (mySwitchbankUpdate.State == BravaTransaction.TransactionState.Failed)
                //{
                //    throw new System.Net.Sockets.SocketException(10004);
                //}
                #endregion
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 12
0
        private void sendSwitchStateCommand(System.Net.IPAddress destIPAdr, Int16 destPortNum,
                                            bool swState1, bool swState2, bool swState3, bool swState4,
                                            bool swState5, bool swState6, bool swState7, bool swState8)
        {
            BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

            for (int x = 0; x <= 7; x++) mySwitchStates[x] = BravaCodes.SwitchState.SwitchOff;

            if (swState1)
                mySwitchStates[0] = BravaCodes.SwitchState.SwitchOn;
            if (swState2)
                mySwitchStates[1] = BravaCodes.SwitchState.SwitchOn;
            if (swState3) // cbSingleSw3.Checked)
                mySwitchStates[2] = BravaCodes.SwitchState.SwitchOn;
            if (swState4) // cbSingleSw4.Checked)
                mySwitchStates[3] = BravaCodes.SwitchState.SwitchOn;
            if (swState5) // cbSingleSw5.Checked)
                mySwitchStates[4] = BravaCodes.SwitchState.SwitchOn;
            if (swState6) // cbSingleSw6.Checked)
                mySwitchStates[5] = BravaCodes.SwitchState.SwitchOn;
            if (swState7) // cbSingleSw7.Checked)
                mySwitchStates[6] = BravaCodes.SwitchState.SwitchOn;
            if (swState8) // cbSingleSw8.Checked)
                mySwitchStates[7] = BravaCodes.SwitchState.SwitchOn;

            SwitchbankUpdate mySwitchbankUpdate = new SwitchbankUpdate(
                mySwitchStates[0],
                mySwitchStates[1],
                mySwitchStates[2],
                mySwitchStates[3],
                mySwitchStates[4],
                mySwitchStates[5],
                mySwitchStates[6],
                mySwitchStates[7]);

            // RequestStateBlock myReadBackVerify = new RequestStateBlock((byte)BravaCodes.StateBlockRecords.SwitchBankLS8);

            BravaConnection myConnection = new BravaConnection();
            myConnection.BravaIP = destIPAdr;
            myConnection.BravaPort = destPortNum;

            BravaSocket mySocket = new BravaSocket(mySwitchbankUpdate, myConnection);

            try
            {
                mySocket.DoTransaction();

                if (mySwitchbankUpdate.State == BravaTransaction.TransactionState.Completed)
                {
                    mySwitchbankUpdate.State = BravaTransaction.TransactionState.Closed;

                    //mySocket.Transaction = myReadBackVerify;

                    //mySocket.DoTransaction();

                    //if (myReadBackVerify.State == BravaTransaction.TransactionState.Completed)
                    //{
                    //    BravaCodes.SwitchState[] readbackStates = new BravaCodes.SwitchState[8];
                    //    readbackStates = myReadBackVerify.ParseSwitchStates(8);
                    //    // TODO: Utility function to extract the switch state from the StateBlock
                    //    if (myReadBackVerify.State == BravaTransaction.TransactionState.Closed)
                    //    {
                    //        if (mySwitchStates == readbackStates)
                    //        {
                    //            MessageBox.Show("ReadBack value differs from Set Value");

                    //        }
                    //    }

                    //}
                    //else
                    //{
                    //    MessageBox.Show("ReadBackVerify Failed.");
                    //}

                }
                else
                {
                    MessageBox.Show("SwitchBankUpdate Failed.");
                }

            }
            catch (Exception)
            {
                mySocket.SocketClient.Close();
                throw;
            }
        }
Esempio n. 13
0
        private System.Xml.XmlDocument readSwitchStateXML(System.Net.IPAddress destIPAdr, Int16 destPortNum)
        {
            RequestStateBlock myRequest = new RequestStateBlock((byte)BravaCodes.StateBlockRecords.SwitchBankLS8);
            BravaConnection myConnection = new BravaConnection();
            BravaSocket mySocket = new BravaSocket(myRequest, myConnection);

            try
            {
                // Prepare Connection Parameters.
                myConnection.BravaIP = destIPAdr;
                myConnection.BravaPort = destPortNum;

                // Enact / Transmit the Request.
                mySocket.DoTransaction();

                if (myRequest.State == BravaTransaction.TransactionState.Completed)
                {
                    myRequest.ParseResultStream();
                }

                if (myRequest.State == BravaTransaction.TransactionState.Failed)
                {
                    MessageBox.Show("Transaction Failed.");
                }

                //MessageBox.Show(myRequest.ResultXML.OuterXml);

                return myRequest.ResultXML;

            }
            catch (System.Net.Sockets.SocketException ex)
            {
                if ((ex.ErrorCode == 10061) || (ex.ErrorCode == 10060) || (ex.ErrorCode == 10065) )
                {
                    return null;
                }
                else
                {
                    throw ex;
                }

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                mySocket.SocketClient.Close();
            }
        }
Esempio n. 14
0
        private void btnSingleConnect_Click(object sender, EventArgs e)
        {
            if (cmbListOfIPAddress.Text != string.Empty)
            {
                BravaConnection myConnection = new BravaConnection();

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

                myConnection.BravaPort = (Int16)numDeviceProtocolPortNum.Value;

                RequestType myRequest = new RequestType();

                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;
                }
            }
        }
Esempio n. 15
0
        private void sendSwitchStateCommand(System.Net.IPAddress destIPAdr, Int16 destPortNum, 
                                            bool swState1, bool swState2, bool swState3, bool swState4,
                                            bool swState5, bool swState6, bool swState7, bool swState8)
        {
            BravaConnection myConnection = new BravaConnection();

            myConnection.BravaIP = destIPAdr;

            myConnection.BravaPort = destPortNum;

            BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

            for (int x = 0; x <= 7; x++) mySwitchStates[x] = BravaCodes.SwitchState.SwitchOff;

            if (swState1)
                mySwitchStates[0] = BravaCodes.SwitchState.SwitchOn;
            if (swState2)
                mySwitchStates[1] = BravaCodes.SwitchState.SwitchOn;
            if (swState3) // cbSingleSw3.Checked)
                mySwitchStates[2] = BravaCodes.SwitchState.SwitchOn;
            if (swState4) // cbSingleSw4.Checked)
                mySwitchStates[3] = BravaCodes.SwitchState.SwitchOn;
            if (swState5) // cbSingleSw5.Checked)
                mySwitchStates[4] = BravaCodes.SwitchState.SwitchOn;
            if (swState6) // cbSingleSw6.Checked)
                mySwitchStates[5] = BravaCodes.SwitchState.SwitchOn;
            if (swState7) // cbSingleSw7.Checked)
                mySwitchStates[6] = BravaCodes.SwitchState.SwitchOn;
            if (swState8) // cbSingleSw8.Checked)
                mySwitchStates[7] = BravaCodes.SwitchState.SwitchOn;

            SwitchbankUpdate mySwitchbankUpdate = new SwitchbankUpdate(
                mySwitchStates[0],
                mySwitchStates[1],
                mySwitchStates[2],
                mySwitchStates[3],
                mySwitchStates[4],
                mySwitchStates[5],
                mySwitchStates[6],
                mySwitchStates[7]);

            BravaSocket mySocket = new BravaSocket(mySwitchbankUpdate, myConnection);

            try
            {
                mySocket.OpenConnection();

                mySocket.DoTransaction();

                myConnection.rqStream.Close();

            }
            catch (Exception)
            {
                mySocket.SocketClient.Close();
                throw;
            }
        }
Esempio n. 16
0
        private System.Xml.XmlDocument readStateCommand(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)
                {
                    throw;
                }
                finally
                {
                    mySocket.SocketClient.Close();
                }
        }