コード例 #1
0
ファイル: Frm_Main.cs プロジェクト: s9703830/SmartVillage
        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();
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: s9703830/SmartVillage
        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;
            }
        }
コード例 #3
0
ファイル: Scheduling.cs プロジェクト: s9703830/SmartVillage
        private void LoadShedUnit(List<lfa.pmgmt.data.DTO.Schedule.Device> unitDevices, int defaultPort, 
                                 lfa.pmgmt.data.DTO.Schedule.Unit unit, int status)
        {
            if (unit.IsActive)
            {
                string deviceAddress = string.Empty;

                SwitchbankUpdate mySwitchbankUpdate = null;

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

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

                foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
                {
                    lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                    deviceDAO.ConnectionString = _connectionString;

                    string deviceName = unitDevice.Name;
                    int deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                    deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                    string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                    if (status == 0)
                    {
                        bool switchOn = unitDevice.DeviceOn;

                        if (switchOn)
                        {
                            status = 1;
                        }
                        else
                        {
                            status = 2;
                        }
                    }

                    SetSwitchState(deviceSwitch, status, mySwitchStates,unitDevice.Id.ToString());
                }

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

                    //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 3", System.Diagnostics.EventLogEntryType.Warning);

                    SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                    lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                    currentStatusDAO.ConnectionString = _connectionString;
                    currentStatusDAO.Insert(unit.Name, "OK");
                }
                catch(System.Net.Sockets.SocketException)
                {
                    System.Threading.Thread.Sleep(200);

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

                       //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 3", System.Diagnostics.EventLogEntryType.Warning);

                       SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    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: " + unit.Name, "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(unit.Name, "ERR");
                    }
                }
            }
            else
            {
                try
                {

                    //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 4", System.Diagnostics.EventLogEntryType.Warning);

                    SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                    lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                    currentStatusDAO.ConnectionString = _connectionString;
                    currentStatusDAO.Insert(unit.Name, "OK");
                }
                catch(System.Net.Sockets.SocketException)
                {
                    System.Threading.Thread.Sleep(200);

                    try
                    {
                        //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 4", System.Diagnostics.EventLogEntryType.Warning);

                        SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    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: " + unit.Name, "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(unit.Name, "ERR");
                    }
                }
            }
        }
コード例 #4
0
ファイル: Scheduling.cs プロジェクト: s9703830/SmartVillage
        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();
            }
        }
コード例 #5
0
ファイル: Scheduling.cs プロジェクト: s9703830/SmartVillage
        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();
            }
        }
コード例 #6
0
ファイル: Scheduling.cs プロジェクト: s9703830/SmartVillage
        private void AsyncLoadShedUnit(object parameters)
        {
            try
            {
                ArrayList parms = parameters as ArrayList;

                List<lfa.pmgmt.data.DTO.Schedule.Device> unitDevices = parms[0] as List<lfa.pmgmt.data.DTO.Schedule.Device>;

                int defaultPort = (int)parms[1];

                lfa.pmgmt.data.DTO.Schedule.Unit unit = parms[2] as lfa.pmgmt.data.DTO.Schedule.Unit;

                int status = (int)parms[3];

                if (unit.IsActive)
                {
                    string deviceAddress = string.Empty;

                    SwitchbankUpdate mySwitchbankUpdate = null;

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

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

                    foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
                    {
                        lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                        deviceDAO.ConnectionString = _connectionString;

                        string deviceName = unitDevice.Name;
                        int deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                        deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                        string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                        //if (status == 0)
                        //{
                        bool switchOn = unitDevice.DeviceOn;

                        if (switchOn)
                        {
                            status = 1;
                        }
                        else
                        {
                            status = 2;
                        }
                        //}

                        SetSwitchState(deviceSwitch, status, mySwitchStates, unitDevice.Id.ToString());
                    }

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

                    try
                    {
                        //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 1", System.Diagnostics.EventLogEntryType.Warning);

                        SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        System.Threading.Thread.Sleep(200);

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

                            //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 1", System.Diagnostics.EventLogEntryType.Warning);

                            SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "OK");
                        }
                        catch (System.Net.Sockets.SocketException soex)
                        {
                            lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                            logDAO.ConnectionString = _connectionString;
                            logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + soex.ToString(), DateTime.Now);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "ERR");
                        }
                    }
                }
                else
                {
                    try
                    {
                        //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 2", System.Diagnostics.EventLogEntryType.Warning);

                        SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        System.Threading.Thread.Sleep(200);

                        try
                        {
                            //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 2", System.Diagnostics.EventLogEntryType.Warning);

                            SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "OK");
                        }
                        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: " + unit.Name, "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(unit.Name, "ERR");
                        }
                    }
                }
            }
            catch (Exception)
            {
                //File.AppendAllText(@"c:\smartpower\logerr.txt", er.ToString());
            }
        }
コード例 #7
0
ファイル: Scheduling.cs プロジェクト: s9703830/SmartVillage
        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();
            }
        }
コード例 #8
0
ファイル: Scheduling.cs プロジェクト: s9703830/SmartVillage
        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;
            }
        }
コード例 #9
0
ファイル: Scheduling.cs プロジェクト: s9703830/SmartVillage
        private void AsyncLoadShedUnit(object parameters)
        {
            ArrayList parms = parameters as ArrayList;

            List<lfa.pmgmt.data.DTO.Schedule.Device> unitDevices = parms[0] as List<lfa.pmgmt.data.DTO.Schedule.Device>;

            int defaultPort = (int)parms[1];

            lfa.pmgmt.data.DTO.Schedule.Unit unit = parms[2] as lfa.pmgmt.data.DTO.Schedule.Unit;

            int status = (int)parms[3];

            if (unit.IsActive)
            {
                string deviceAddress = string.Empty;

                SwitchbankUpdate mySwitchbankUpdate = null;

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

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

                foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
                {
                    lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                    deviceDAO.ConnectionString = _connectionString;

                    string deviceName = unitDevice.Name;
                    int deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                    deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                    string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                    bool switchOn = unitDevice.DeviceOn;

                    if (switchOn)
                    {
                       status = 1;
                    }
                    else
                    {
                       status = 2;
                    }

                    SetSwitchState(deviceSwitch, status, mySwitchStates, unitDevice.Id.ToString());
                }

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

                try
                {
                    SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                    lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                    currentStatusDAO.ConnectionString = _connectionString;
                    currentStatusDAO.Insert(unit.Name, "OK");
                }
                catch(System.Net.Sockets.SocketException)
                {
                    System.Threading.Thread.Sleep(500);

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

                        SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException soex)
                    {
                        lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                        logDAO.ConnectionString = _connectionString;
                        logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + soex.ToString(), DateTime.Now);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "ERR");
                    }
                }
            }
        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: s9703830/SmartVillage
        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;
            }
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: s9703830/SmartVillage
        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;
            }
        }