Gurux.DLMS.Objects.GXDLMSImageTransfer.ImageTransferInitiate C# (CSharp) Méthode

ImageTransferInitiate() public méthode

public ImageTransferInitiate ( Gurux.DLMS.GXDLMSClient client, string imageIdentifier, long imageSize ) : byte[][]
client Gurux.DLMS.GXDLMSClient
imageIdentifier string
imageSize long
Résultat byte[][]
        public byte[][] ImageTransferInitiate(GXDLMSClient client, string imageIdentifier, long imageSize)
        {
            if (ImageBlockSize == 0)
            {
                throw new Exception("Invalid image block size");
            }
            GXByteBuffer data = new GXByteBuffer();
            data.SetUInt8((byte)DataType.Structure);
            data.SetUInt8((byte)2);
            GXCommon.SetData(client.Settings, data, DataType.OctetString, ASCIIEncoding.ASCII.GetBytes(imageIdentifier));
            GXCommon.SetData(client.Settings, data, DataType.UInt32, imageSize);
            return client.Method(this, 1, data.Array(), DataType.Array);
        }

Usage Example

        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));
        }