Exemplo n.º 1
0
        private void Load_Config_Click(object sender, RoutedEventArgs e)
        {
            int kmfRsi = 0;
            int mnp    = 0;

            try
            {
                kmfRsi = Convert.ToInt32(txtKmfRsiHex.Text, 16);
            }
            catch (Exception)
            {
                MessageBox.Show("Error Parsing KMF RSI", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                mnp = Convert.ToInt32(txtMnpHex.Text, 16);
            }
            catch (Exception)
            {
                MessageBox.Show("Error Parsing MNP", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Ensure valid KMF RSI value
            if ((kmfRsi > 9999999) || (kmfRsi < 1))
            {
                MessageBox.Show("Invalid KMF RSI - must be between 1 and 9,999,999", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Ensure valid MNP value
            if ((mnp > 65535) || (mnp < 0))
            {
                MessageBox.Show("Invalid MNP - must be between 0 and 65,535", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                RspRsiInfo temp = new RspRsiInfo();
                temp = Interact.LoadConfig(Settings.Port, kmfRsi, mnp);
                MessageBox.Show("Config Loaded Successfully - RSI: " + temp.RSI + ", Message Number: " + temp.MN + ", Status: " + temp.Status, "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Error -- {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            //MessageBox.Show("Config Loaded Successfully", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Exemplo n.º 2
0
        public RspRsiInfo ChangeRsi(int rsiOld, int rsiNew, int mnp)
        {
            RspRsiInfo result = new RspRsiInfo();

            Begin();

            try
            {
                ChangeRsiCommand cmdKmmBody = new ChangeRsiCommand();
                cmdKmmBody.RsiOld        = rsiOld;
                cmdKmmBody.RsiNew        = rsiNew;
                cmdKmmBody.MessageNumber = mnp;

                KmmBody rspKmmBody = TxRxKmm(cmdKmmBody);

                if (rspKmmBody is ChangeRsiResponse)
                {
                    ChangeRsiResponse kmm = rspKmmBody as ChangeRsiResponse;
                    result.RSI    = rsiNew;
                    result.MN     = mnp;
                    result.Status = kmm.Status;
                }
                else if (rspKmmBody is NegativeAcknowledgment)
                {
                    NegativeAcknowledgment kmm = rspKmmBody as NegativeAcknowledgment;

                    string statusDescr  = OperationStatusExtensions.ToStatusString(kmm.Status);
                    string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
                    throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
                }
                else
                {
                    throw new Exception("unexpected kmm");
                }
            }
            catch
            {
                End();

                throw;
            }

            End();

            return(result);
        }
Exemplo n.º 3
0
        /* TIA 102.AACD-A 3.7.2.22 */
        public RspRsiInfo LoadConfig(int kmfRsi, int mnp)
        {
            //cg
            RspRsiInfo result = new RspRsiInfo();

            Begin();

            try
            {
                LoadConfigCommand cmdKmmBody = new LoadConfigCommand();
                cmdKmmBody.KmfRsi = kmfRsi;
                cmdKmmBody.MessageNumberPeriod = mnp;
                KmmBody rspKmmBody = TxRxKmm(cmdKmmBody);
                if (rspKmmBody is LoadConfigResponse)
                {
                    LoadConfigResponse kmm = rspKmmBody as LoadConfigResponse;
                    result.RSI    = kmm.RSI;
                    result.MN     = kmm.MN;
                    result.Status = kmm.Status;
                    //Console.WriteLine("response status: {0}", kmm.Status);
                }
                else if (rspKmmBody is NegativeAcknowledgment)
                {
                    NegativeAcknowledgment kmm = rspKmmBody as NegativeAcknowledgment;

                    string statusDescr  = OperationStatusExtensions.ToStatusString(kmm.Status);
                    string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
                    throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
                }
                else
                {
                    throw new Exception("unexpected kmm");
                }
            }
            catch
            {
                End();

                throw;
            }

            End();

            return(result);
        }
Exemplo n.º 4
0
 private void dgRsiItems_RowClicked(object sender, MouseButtonEventArgs e)
 {
     if (sender != null)
     {
         DataGrid grid = sender as DataGrid;
         if (grid != null && grid.SelectedItems != null && grid.SelectedItems.Count == 1)
         {
             if (cbRsiAction.SelectedIndex == 1)
             {
                 return;
             }
             DataGridRow dgr     = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow;
             RspRsiInfo  rsiItem = (RspRsiInfo)dgRsiItems.SelectedItem;
             txtRsiOldDec.Text = rsiItem.RSI.ToString();
             txtRsiOldHex.Text = rsiItem.RSI.ToString("X");
             txtMnpDec.Text    = rsiItem.MN.ToString();
             txtMnpHex.Text    = rsiItem.MN.ToString("X");
         }
     }
 }
Exemplo n.º 5
0
        private void Update_RSI_Click(object sender, RoutedEventArgs e)
        {
            int        rsiOld = 0;
            int        rsiNew = 0;
            int        mn     = 0;
            RspRsiInfo result = new RspRsiInfo();

            try
            {
                rsiOld = Convert.ToInt32(txtRsiOldHex.Text, 16);
            }
            catch (Exception)
            {
                MessageBox.Show("Error Parsing old RSI", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                rsiNew = Convert.ToInt32(txtRsiNewHex.Text, 16);
            }
            catch (Exception)
            {
                MessageBox.Show("Error Parsing new RSI", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                mn = Convert.ToInt32(txtMnpHex.Text, 16);
            }
            catch (Exception)
            {
                MessageBox.Show("Error Parsing Message Number", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Ensure valid RSI value
            if ((rsiOld < 0) || (rsiOld > 16777214) || (rsiOld == 9999999))
            {
                MessageBox.Show("Invalid old RSI - must be between 1 and 9,999,998 or 10,000,000 to 16,777,214", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else if ((rsiNew < 0) || (rsiNew > 16777214) || (rsiNew == 9999999))
            {
                MessageBox.Show("Invalid new RSI - must be between 1 and 9,999,998 or 10,000,000 to 16,777,214", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Ensure valid MN value
            if ((mn > 65535) || (mn < 0))
            {
                MessageBox.Show("Invalid Message Number - must be between 0 and 65,535", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Ensure individual-individual and group-group
            if ((rsiOld < 9999999) && (rsiNew > 9999999))
            {
                MessageBox.Show("Individual RSI cannot be changed to a Group RSI", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            else if ((rsiOld > 9999999) && (rsiNew < 9999999))
            {
                MessageBox.Show("Group RSI cannot be changed to an Individual RSI", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                result = Interact.ChangeRsi(Settings.SelectedDevice, rsiOld, rsiNew, mn);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Error -- {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (result.Status == 0)
            {
                ViewRsiItems();
                MessageBox.Show("RSI changed successfully", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("Error, status: " + result.Status, "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Exemplo n.º 6
0
        public List <RspRsiInfo> ViewRsiItems()
        {
            List <RspRsiInfo> result = new List <RspRsiInfo>();

            Begin();

            try
            {
                bool more   = true;
                int  marker = 0;

                while (more)
                {
                    InventoryCommandListRsiItems commandKmmBody = new InventoryCommandListRsiItems();

                    KmmBody responseKmmBody = TxRxKmm(commandKmmBody);

                    if (responseKmmBody is InventoryResponseListRsiItems)
                    {
                        InventoryResponseListRsiItems kmm = responseKmmBody as InventoryResponseListRsiItems;

                        Logger.Debug("inventory marker: {0}", marker);

                        if (marker == 0)
                        {
                            more = false;
                        }

                        Logger.Debug("number of RSIs returned: {0}", kmm.RsiItems.Count);

                        for (int i = 0; i < kmm.RsiItems.Count; i++)
                        {
                            RsiItem item = kmm.RsiItems[i];

                            Logger.Debug("* rsi index {0} *", i);
                            Logger.Debug("rsi id: {0} (dec), {0:X} (hex)", item.RSI);
                            Logger.Debug("mn: {0} (dec), {0:X} (hex)", item.MessageNumber);

                            RspRsiInfo res = new RspRsiInfo();

                            res.RSI = (int)item.RSI;
                            res.MN  = item.MessageNumber;

                            result.Add(res);
                        }
                    }
                    else if (responseKmmBody is NegativeAcknowledgment)
                    {
                        NegativeAcknowledgment kmm = responseKmmBody as NegativeAcknowledgment;

                        string statusDescr  = OperationStatusExtensions.ToStatusString(kmm.Status);
                        string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
                        throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
                    }
                    else
                    {
                        throw new Exception("unexpected kmm");
                    }
                }
            }
            catch
            {
                End();

                throw;
            }

            End();

            return(result);
        }