public void UpdateImage(GXDLMSImageTransfer target, byte[] data, string Identification) { //Check that image transfer ia enabled. byte[] reply = ReadDataBlock(Client.Read(target, 5)); Client.UpdateValue(reply, target, 5); if (!target.ImageTransferEnabled) { throw new Exception("Image transfer is not enabled"); } //Step 1: The client gets the ImageBlockSize. reply = ReadDataBlock(Client.Read(target, 2)); Client.UpdateValue(reply, target, 2); // Step 2: The client initiates the Image transfer process. ReadDataBlock(target.ImageTransferInitiate(Client, Identification, data.Length)); // Step 3: The client transfers ImageBlocks. int ImageBlockCount; ReadDataBlock(target.ImageBlockTransfer(Client, data, out ImageBlockCount)); //Step 4: The client checks the completeness of the Image in //each server individually and transfers any ImageBlocks not (yet) transferred; Client.UpdateValue(reply, target, 2); // Step 5: The Image is verified; ReadDataBlock(target.ImageVerify(Client)); // Step 6: Before activation, the Image is checked; //Get list to imaages to activate. reply = ReadDataBlock(Client.Read(target, 7)); Client.UpdateValue(reply, target, 7); bool bFound = false; foreach (GXDLMSImageActivateInfo it in target.ImageActivateInfo) { if (it.Identification == Identification) { bFound = true; break; } } //Read image transfer status. reply = ReadDataBlock(Client.Read(target, 6)); Client.UpdateValue(reply, target, 6); if (target.ImageTransferStatus != ImageTransferStatus.VerificationSuccessful) { throw new Exception("Image transfer status is " + target.ImageTransferStatus.ToString()); } if (!bFound) { throw new Exception("Image not found."); } //Step 7: Activate image. ReadDataBlock(target.ImageActivate(Client)); }
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."); } } }
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."); } } }
/// <summary> /// This method is used to update meter firmware. /// </summary> /// <param name="target"></param> public void ImageUpdate(GXDLMSImageTransfer target, string identification, byte[] data) { //Check that image transfer ia enabled. GXReplyData reply = new GXReplyData(); ReadDataBlock(Client.Read(target, 5), reply); Client.UpdateValue(target, 5, reply.Value); if (!target.ImageTransferEnabled) { throw new Exception("Image transfer is not enabled"); } //Step 1: Read image block size. ReadDataBlock(Client.Read(target, 2), reply); Client.UpdateValue(target, 2, reply.Value); // Step 2: Initiate the Image transfer process. ReadDataBlock(target.ImageTransferInitiate(Client, identification, data.Length), reply); // Step 3: Transfers ImageBlocks. int imageBlockCount; ReadDataBlock(target.ImageBlockTransfer(Client, data, out imageBlockCount), reply); //Step 4: Check the completeness of the Image. ReadDataBlock(Client.Read(target, 3), reply); Client.UpdateValue(target, 3, reply.Value); // Step 5: The Image is verified; ReadDataBlock(target.ImageVerify(Client), reply); // Step 6: Before activation, the Image is checked; //Get list to images to activate. ReadDataBlock(Client.Read(target, 7), reply); Client.UpdateValue(target, 7, reply.Value); bool bFound = false; foreach (GXDLMSImageActivateInfo it in target.ImageActivateInfo) { if (it.Identification == identification) { bFound = true; break; } } //Read image transfer status. ReadDataBlock(Client.Read(target, 6), reply); Client.UpdateValue(target, 6, reply.Value); if (target.ImageTransferStatus != Gurux.DLMS.Objects.Enums.ImageTransferStatus.VerificationSuccessful) { throw new Exception("Image transfer status is " + target.ImageTransferStatus.ToString()); } if (!bFound) { throw new Exception("Image not found."); } //Step 7: Activate image. ReadDataBlock(target.ImageActivate(Client), reply); }