Once the device has been selected, the update process will be started. Depending on the selected device and parameters the console output might and the duration might differ.
If desired, this sample can also be used as a command-line tool to update Balluff/MATRIX VISION devices. The following command-line parameters might be useful in this case.
The update process itself is very straight forward. It is just necessary to create an instance of mv.impact.acquire.FirmwareUpdater. To configure the update process itself it is necessary to pass the correct parameters to the constructor. Afterwards it is sufficient to call mvIMPACT.acquire.FirmwareUpdater.update.
The callbacks can be customized to get the required behavior. In this example the update status callbacks just return some message to the shell and look like this:
public class MyFirmwareUpdater :
mv.impact.acquire.FirmwareUpdater
{
public MyFirmwareUpdater(Device pDev, bool boOverride=true, bool boForceDowngrade=true, bool boKeepUserSets=true, bool boForceBreakingChange=true) : base(pDev, boOverride, boForceDowngrade, boKeepUserSets, boForceBreakingChange) { }
public override int onErrorMessage(double progressTimer)
{
Console.WriteLine("Info: {0} @ {1} s", statusMessage, progressTimer);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onErasingFlash(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Erasing - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onUnzippingFirmwareArchive(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Unzipping firmware archive - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onUpdatingBootProgrammer(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Updating boot programmer - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onUploadingImage(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Uploading - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onRebooting(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Rebooting - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onHardResetRequired(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Rebooting - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
Console.WriteLine("Manual hard reset required.");
return (int)TFirmwareUpdateAction.fuaCancel;
}
public override int onSavingUserSets(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Saving sets - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onLoadingUserSets(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Loading sets - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
}
Definition Enumerations.cs:2
For mvBlueFOX3 or mvBlueCOUGAR-X/XD/XT devices it is necessary to provide the path to a firmware archive (*.mvu file). Some cases might require some specific parameters to be changed e.g. in case of downgrading a device or if there might be a breaking change within the device's software interface.
As BVS CA-BN (mvBlueNAOS) devices are very much integrated within the host system, there is no separate firmware file which can be downloaded. The devices firmware is embedded into the Impact Acquire framework and has to be updated once the Impact Acquire framework on the host system contains breaking changes. This applies for upgrades as well as for downgrades.
As mvBlueFOX devices are not capable of the complex functionalities provided by GenICam™ compliant devices the set of configurable parameters is much more limited. There is no specific firmware file available, instead different firmware versions are shipped within the mvBlueFOX package and can be selected for the update via the mv.impact.acquire.FirmwareUpdater.firmwareVersionToUpload property.
using System;
using mv.impact.acquire.examples.helper;
namespace mv.impact.acquire.examples
{
class MyFirmwareUpdater :
mv.impact.acquire.FirmwareUpdater
{
public MyFirmwareUpdater(Device pDev, bool boOverride = true, bool boForceDowngrade = true, bool boKeepUserSets = true, bool boForceBreakingChange = true) : base(pDev, boOverride, boForceDowngrade, boKeepUserSets, boForceBreakingChange) { }
public override int onErrorMessage(double progressTimer)
{
Console.WriteLine("Info: {0} @ {1} s", statusMessage, progressTimer);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onErasingFlash(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Erasing - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onUnzippingFirmwareArchive(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Unzipping firmware archive - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onUpdatingBootProgrammer(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Updating boot programmer - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onUploadingImage(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Uploading - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onRebooting(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Rebooting - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onHardResetRequired(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Rebooting - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
Console.WriteLine("Manual hard reset required.");
return (int)TFirmwareUpdateAction.fuaCancel;
}
public override int onSavingUserSets(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Saving sets - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
public override int onLoadingUserSets(int currentProgress_pc, double timeElapsed)
{
Console.WriteLine("Loading sets - Update progress: {0}, time: {1:N2} s", currentProgress_pc, timeElapsed);
return (int)TFirmwareUpdateAction.fuaContinue;
}
}
class FirmwareUpdate
{
enum TDeviceFamily
{
dfBVS_CA_BN,
dfMvBlueCOUGAR,
dfMvBlueFOX3,
dfMvBlueFOX,
dfUnknown
};
static bool IsGigEVisionDevice(Device pDev)
{
PropertyI64 deviceIPAddress = new PropertyI64();
DeviceComponentLocator locator = new DeviceComponentLocator(pDev.hDev);
return (locator.bindComponent(deviceIPAddress, "DeviceIPAddress") && (deviceIPAddress.readS() != "Unavailable"));
}
static TDeviceFamily GetDeviceFamily(Device pDev)
{
if ((pDev.family.readS() == "mvBlueCOUGAR" || pDev.family.readS() == "BVS CA") && IsGigEVisionDevice(pDev))
{
return TDeviceFamily.dfMvBlueCOUGAR;
}
if (pDev.family.readS() == "mvBlueFOX3" || pDev.family.readS() == "BVS CA")
{
return TDeviceFamily.dfMvBlueFOX3;
}
if (pDev.product.read().StartsWith("BVS CA-BN") || (pDev.family.read() == "mvBlueNAOS"))
{
return TDeviceFamily.dfBVS_CA_BN;
}
if (pDev.family.readS() == "mvBlueFOX")
{
return TDeviceFamily.dfMvBlueFOX;
}
return TDeviceFamily.dfUnknown;
}
static bool GetLatestLocalFirmwareVersion(Device pDev, out string latestFirmwareVersion)
{
latestFirmwareVersion = "0.0.0.0";
string currentFirmwareVersion = pDev.firmwareVersion.readS();
PropertyI64 firmwareVersionLatest = new PropertyI64();
DeviceComponentLocator locator = new DeviceComponentLocator(pDev.hDev);
if (!locator.bindComponent(firmwareVersionLatest, "FirmwareVersionLatest"))
{
return false;
}
latestFirmwareVersion = firmwareVersionLatest.readS();
return (currentFirmwareVersion == latestFirmwareVersion);
}
static TDMR_ERROR updateBlueCOUGAROrBlueFOX3(Device pDev, string pathToFirmwareArchive, bool boForceOverideSameVersion, bool boForceDowngrade, bool boForceSameVersion, bool boForceBreakingChange, out string status)
{
status = "";
TDMR_ERROR result = TDMR_ERROR.DMR_NO_ERROR;
MyFirmwareUpdater fwu = new MyFirmwareUpdater(pDev, boForceOverideSameVersion, boForceDowngrade, boForceSameVersion, boForceBreakingChange);
result = fwu.update(pathToFirmwareArchive);
if (result == TDMR_ERROR.DMR_NO_ERROR)
{
result = MyFirmwareUpdater.verifyFirmwareChecksum(pDev, pathToFirmwareArchive);
if (result != TDMR_ERROR.DMR_NO_ERROR)
{
Console.WriteLine("Firmware checksum verification: {0}", fwu.statusMessage);
}
else
{
Console.WriteLine("Firmware checksum verified successful!");
}
}
if (result != TDMR_ERROR.DMR_NO_ERROR)
{
status = fwu.statusMessage;
}
return result;
}
static TDMR_ERROR updateBlueFOX(Device pDev, string version, out string status)
{
status = null;
TDMR_ERROR result = TDMR_ERROR.DMR_NO_ERROR;
MyFirmwareUpdater fwu = new MyFirmwareUpdater(pDev);
if (version != null && fwu.firmwareVersionToUpload.isValid)
{
fwu.firmwareVersionToUpload.writeS(version);
}
Console.WriteLine("Updating device {0} from FW version {1} to {2}.", pDev.serial.read(), pDev.firmwareVersion.readS(), fwu.firmwareVersionToUpload.readS());
result = fwu.update();
if (result != TDMR_ERROR.DMR_NO_ERROR)
{
status = fwu.statusMessage;
}
return result;
}
static TDMR_ERROR updateBVS_CA_BN(Device pDev, bool boForce, out string status)
{
status = null;
string latestFirmwareVersion;
if (GetLatestLocalFirmwareVersion(pDev, out latestFirmwareVersion))
{
if (!boForce)
{
Console.WriteLine("Skipping device {0} because it already uses the current FW version ({1}).", pDev.serial.read(), pDev.firmwareVersion.readS());
return TDMR_ERROR.DMR_NO_ERROR;
}
Console.WriteLine("Device {0} already uses the current FW version ({1}).", pDev.serial.read(), pDev.firmwareVersion.readS());
Console.WriteLine("Not skipping because 'force' specified'.");
}
Console.WriteLine("Updating device {0} from FW version {1} to {2}.", pDev.serial.read(), pDev.firmwareVersion.readS(), latestFirmwareVersion);
TDMR_ERROR result = TDMR_ERROR.DMR_NO_ERROR;
MyFirmwareUpdater fwu = new MyFirmwareUpdater(pDev);
result = fwu.update();
if (result != TDMR_ERROR.DMR_NO_ERROR)
{
status = fwu.statusMessage;
}
return result;
}
static bool isDeviceSupportedBySample(Device pDev)
{
return GetDeviceFamily(pDev) != TDeviceFamily.dfUnknown;
}
static void displayCommandLineOptions()
{
Console.WriteLine("Available command-line parameters:");
Console.WriteLine(" General:");
Console.WriteLine(" 'serial' or 's' to specify the serial number of the device to use (if not specified the user will be asked to select a device)");
Console.WriteLine(" 'unattended' or 'u' to specify no questions asked, if possible");
Console.WriteLine(" 'force' or 'f' to specify force update even if FW is already up-to-date");
Console.WriteLine(" 'help' or 'h' displays this help text");
Console.WriteLine(" mvBlueCOUGAR-(X/XD/XT) and mvBlueFOX3:");
Console.WriteLine(" 'forceDowngrade' or 'd' to force an update even if the specified FW is older than the version already installed");
Console.WriteLine(" 'keepUserSets' or 'k' if UserSets stored on the device should still be present after the update");
Console.WriteLine(" 'forceBreakingChange' or 'b' if the device should be updated even if the interface might be different afterwards");
Console.WriteLine(" 'pathToFWArchive' or 'p' to specify the firmware archive which should be used to update the device");
Console.WriteLine(" mvBlueFOX:");
Console.WriteLine(" 'version' or 'v' to specify the version that should be used to update the device");
Console.WriteLine();
Console.WriteLine("USAGE EXAMPLES:");
Console.WriteLine(" FirmwareUpdate s=BN* f=1");
Console.WriteLine(" FirmwareUpdate s=GX* p=\"path to firmware archive\" k=0");
Console.WriteLine(" FirmwareUpdate s=BF* v=49");
}
static int Main(string[] args)
{
bool boUnattended = false;
bool boForceSameVersion = false;
bool boForceDowngrade = false;
bool boKeepUserSets = true;
bool boForceBreakingChange = false;
string version = null;
string pathToFirmwareArchive = null;
Device pDev = null;
if (args.Length > 0)
{
bool boInvalidCommandLineParameterDetected = false;
foreach (var arg in args)
{
string[] argumentParts = arg.Split('=');
switch (argumentParts[0])
{
case "s":
case "serial":
pDev = DeviceManager.getDeviceBySerial(argumentParts[1]);
break;
case "u":
case "unattended":
boUnattended = Convert.ToBoolean(Convert.ToInt32(argumentParts[1]));
break;
case "f":
case "force":
boForceSameVersion = Convert.ToBoolean(Convert.ToInt32(argumentParts[1]));
break;
case "h":
case "help":
displayCommandLineOptions();
break;
case "d":
case "forceDowngrade":
boForceDowngrade = Convert.ToBoolean(Convert.ToInt32(argumentParts[1]));
break;
case "k":
case "keepUserSets":
boKeepUserSets = Convert.ToBoolean(Convert.ToInt32(argumentParts[1]));
break;
case "b":
case "forceBreakingChange":
boForceBreakingChange = Convert.ToBoolean(Convert.ToInt32(argumentParts[1]));
break;
case "p":
case "pathToFWArchive":
pathToFirmwareArchive = argumentParts[1];
break;
case "v":
case "version":
version = argumentParts[1];
break;
default:
boInvalidCommandLineParameterDetected = true;
break;
}
}
if (boInvalidCommandLineParameterDetected)
{
displayCommandLineOptions();
}
}
else
{
Console.WriteLine("No command-line parameters specified.");
displayCommandLineOptions();
Console.Read();
}
if (pDev == null)
{
pDev = DeviceAccess.getDeviceFromUserInput();
if (isDeviceSupportedBySample(pDev))
{
Console.WriteLine("Error! Device not supported by this sample. Unable to continue!");
if (!boUnattended)
{
Console.WriteLine("Press [ENTER] to end the application");
Console.Read();
}
Environment.Exit(1);
}
}
if (pDev == null)
{
Console.WriteLine("Unable to continue!");
return 1;
}
TDeviceFamily deviceFamily = GetDeviceFamily(pDev);
if (deviceFamily == TDeviceFamily.dfUnknown)
{
Console.WriteLine("The selected device is not supported by this sample. Unable to continue!");
if (!boUnattended)
{
Console.WriteLine("Press [ENTER] to end the application");
Console.Read();
}
return 1;
}
if (!boUnattended)
{
Console.WriteLine("Press [ENTER] to update the device.");
Console.Read();
}
Console.WriteLine("Updating {0} ...", pDev.serial.read());
string status = "";
TDMR_ERROR updateResult = TDMR_ERROR.DMR_NO_ERROR;
try
{
switch (deviceFamily)
{
case TDeviceFamily.dfMvBlueCOUGAR:
case TDeviceFamily.dfMvBlueFOX3:
updateResult = updateBlueCOUGAROrBlueFOX3(pDev, pathToFirmwareArchive, boForceSameVersion, boForceDowngrade, boKeepUserSets, boForceBreakingChange, out status);
break;
case TDeviceFamily.dfMvBlueFOX:
updateResult = updateBlueFOX(pDev, version, out status);
break;
case TDeviceFamily.dfBVS_CA_BN:
updateResult = updateBVS_CA_BN(pDev, boForceSameVersion, out status);
break;
}
}
catch (ImpactAcquireException e)
{
Console.WriteLine("An error occurred while updating the firmware of the device {0} (error code: {1}).", pDev.serial.read(), e.errorCodeAsString);
Console.WriteLine("Status: {0}", status);
}
Console.WriteLine("Result code after updating: {0}({1})", updateResult, ImpactAcquireException.getErrorCodeAsString(updateResult));
DeviceManager.updateDeviceList();
if (!boUnattended)
{
Console.WriteLine("Press [ENTER] to end the application");
Console.Read();
}
return updateResult == TDMR_ERROR.DMR_NO_ERROR ? 0 : 1;
}
}
}
A small helper class to administer various library search path related variables and paths.
Definition LibraryPath.cs:14
static void init()
Calling this method will add the folders containing unmanaged libraries to the systems library search...
Definition LibraryPath.cs:251
This namespace contains classes and functions belonging to the image acquisition module of this SDK.
Definition Enumerations.cs:2
Definition Enumerations.cs:2