Example #1
0
 void OnImageDialog(GXImageDlg dlg, GXActionArgs arg)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new ImageDialogEventHandler(OnImageDialog), dlg, arg).AsyncWaitHandle.WaitOne();
     }
     else
     {
         DescriptionList.Items.Clear();
         if (dlg.ShowDialog(this) != DialogResult.OK)
         {
             imageIdentifier = null;
             arg.Action      = ActionType.None;
             return;
         }
         if (dlg.IsAscii)
         {
             imageIdentifier = ASCIIEncoding.ASCII.GetBytes(dlg.TextTb.Text);
         }
         else
         {
             imageIdentifier = GXDLMSTranslator.HexToBytes(dlg.TextTb.Text);
         }
         arg.Text = "Updating image " + Path.GetFileNameWithoutExtension(dlg.FileNameTb.Text) + "...";
         OnDescription("Updating image " + dlg.FileNameTb.Text);
         image = dlg.Image;
     }
 }
        public void PreAction(GXActionArgs arg)
        {
            GXDLMSImageTransfer it = Target as GXDLMSImageTransfer;

            if (arg.Action == ActionType.Action)
            {
                if (arg.Index == 1)
                {
                    if (arg.Tag is GXImageUpdateStatus status)
                    {
                        //Initiate the Image transfer process.
                        arg.Value = it.ImageTransferInitiate(arg.Client, status.ImageIdentifier, status.Image.Length);
                    }
                    else
                    {
                        //Check that delay is correct and save it.
                        GetDelay(arg);
                        if (arg.Exception != null)
                        {
                            return;
                        }
                        GXManufacturerCollection manufacturers = new GXManufacturerCollection();
                        GXManufacturerCollection.ReadManufacturerSettings(manufacturers);
                        GXManufacturer man = manufacturers.FindByIdentification(arg.Client.ManufacturerId);
                        Properties.Settings.Default.ImageDelay = (int)arg.Value / 1000;
                        GXImageDlg dlg = new GXImageDlg(man.ManucatureSettings, arg.Client);
                        OnImageDialog(dlg, arg);
                        if (arg.Action == ActionType.None)
                        {
                            return;
                        }
                        arg.Index  = 5;
                        arg.Action = ActionType.Read;
                        return;
                    }
                }
                else if (arg.Index == 2)
                {
                    //Start image block transfer.
                    GXImageUpdateStatus status = (GXImageUpdateStatus)arg.Tag;
                    int imageBlockCount;
                    arg.Value = it.ImageBlockTransfer(arg.Client, status.Image, status.ImageStartIndex, out imageBlockCount);
                    OnDescription("Sending " + imageBlockCount + " blocks.");
                }
                else if (arg.Index == 3)
                {
                    arg.Value = it.ImageVerify(arg.Client);
                    OnDescription("Verifying image.");
                }
                else if (arg.Index == 4)
                {
                    arg.Value = it.ImageActivate(arg.Client);
                    OnDescription("Activating image.");
                }
            }
        }
Example #3
0
        public void PreAction(GXActionArgs arg)
        {
            GXDLMSImageTransfer it = Target as GXDLMSImageTransfer;

            if (arg.Action == ActionType.Action)
            {
                if (arg.Index == 1)
                {
                    if (!updatingImage)
                    {
                        //Check that delay is correct and save it.
                        GetDelay(arg);
                        if (arg.Exception != null)
                        {
                            return;
                        }
                        Properties.Settings.Default.ImageDelay = (int)arg.Value / 1000;
                        GXImageDlg dlg = new GXImageDlg();
                        OnImageDialog(dlg, arg);
                        if (arg.Action == ActionType.None)
                        {
                            return;
                        }
                        arg.Index         = 5;
                        arg.Action        = ActionType.Read;
                        transformingImage = false;
                        updatingImage     = true;
                        return;
                    }
                    //Initiate the Image transfer process.
                    arg.Value       = it.ImageTransferInitiate(arg.Client, imageIdentifier, image.Length);
                    imageIdentifier = null;
                    updatingImage   = false;
                    statusReadCount = 0;
                }
                else if (arg.Index == 2)
                {
                    //Start image block transfer.
                    int imageBlockCount;
                    arg.Value = it.ImageBlockTransfer(arg.Client, image, out imageBlockCount);
                    OnDescription("Sending " + imageBlockCount + " blocks.");
                }
                else if (arg.Index == 3)
                {
                    arg.Value = it.ImageVerify(arg.Client);
                    OnDescription("Verifying image.");
                }
                else if (arg.Index == 4)
                {
                    arg.Value = it.ImageActivate(arg.Client);
                    OnDescription("Activating image.");
                }
            }
        }
 void OnImageDialog(GXImageDlg dlg, GXActionArgs arg)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new ImageDialogEventHandler(OnImageDialog), dlg, arg).AsyncWaitHandle.WaitOne();
     }
     else
     {
         DescriptionList.Items.Clear();
         if (dlg.ShowDialog(this) != DialogResult.OK)
         {
             arg.Action = ActionType.None;
             return;
         }
         GXImageUpdateStatus status = new GXImageUpdateStatus();
         arg.Tag = status;
         status.ImageIdentifier = dlg.GetImageIdentifier();
         arg.Text = "Updating image " + Path.GetFileNameWithoutExtension(dlg.FileNameTb.Text) + "...";
         OnDescription("Updating image " + dlg.FileNameTb.Text);
         status.Image = dlg.Image;
     }
 }