Question
The IsConnected camera status tag stays on True even after I disconnect the camera. How can I check in Cognex Designer if the camera is connected or disconnected?
Answer
The IsConnected tag refers to the camera connection status on Designer startup, so it cannot be used for dynamically checking the connection status during runtime. The camera connection status can be checked by running the script below. If returnValue[0] and returnValue[1] strings contain "0.0.0.0", then it means that the camera is disconnected or an exception occurred while running the script, otherwise, the camera is connected.
string[] returnValue = new System.String[2];
try
{
// replace <CameraName> with the name of the camera in the project
var acqFifoOperator = $System.GetInternalObject("Devices.<CameraName>") as Cognex.VisionPro.ICogAcqFifo;
var framegrabber = acqFifoOperator.FrameGrabber as Cognex.VisionPro.ICogFrameGrabber;
returnValue[0] = framegrabber.OwnedGigEAccess.PersistentIPAddress;
returnValue[1] = framegrabber.OwnedGigEAccess.PersistentSubnetMask;
}
catch(Exception ex)
{
$System.Log.WriteException("Error occured in GetCameraIPAndSubnet", ex);
returnValue[0] = returnValue[1] = "0.0.0.0";
}