Obtain the connection status of all channels in the remote device. Note that you need to log in to the device first. For details, please refer to the device login in the previous section.
Channel connection status description
public enum EM_CAMERA_STATE_TYPE
{
UNKNOWN, //未知
CONNECTING, //正在连接
CONNECTED, //已连接(在线)
UNCONNECT, //未连接(掉线)
EMPTY, //通道未配置,无信息
DISABLE //通道有配置,但被禁用
}
Get channel status method
public static NET_CAMERA_STATE_INFO[] GetDeviceStatus()
{
if (m_loginID == IntPtr.Zero) return null;
IntPtr intPtr = IntPtr.Zero;
IntPtr outPtr = IntPtr.Zero;
NET_IN_GET_CAMERA_STATEINFO inParam = new NET_IN_GET_CAMERA_STATEINFO();
NET_OUT_GET_CAMERA_STATEINFO outParam = new NET_OUT_GET_CAMERA_STATEINFO();
inParam.dwSize = (uint)Marshal.SizeOf(typeof(NET_IN_GET_CAMERA_STATEINFO));
inParam.bGetAllFlag = true;
outParam.dwSize = (uint)Marshal.SizeOf(typeof(NET_OUT_GET_CAMERA_STATEINFO));
outParam.nMaxNum = m_DeviceInfo.nChanNum;
outParam.pCameraStateInfo = Marshal.AllocHGlobal(outParam.nMaxNum * Marshal.SizeOf(typeof(NET_CAMERA_STATE_INFO)));
intPtr = Marshal.AllocHGlobal((int)inParam.dwSize);
Marshal.StructureToPtr(inParam, intPtr, true);
outPtr = Marshal.AllocHGlobal((int)outParam.dwSize);
Marshal.StructureToPtr(outParam, outPtr, true);
//获取设备连接状态
bool res = NETClient.QueryDevInfo(m_loginID, EM_QUERY_DEV_INFO.GET_CAMERA_STATE, intPtr, outPtr, 3000);
if (!res)
{
return null;
}
outParam = (NET_OUT_GET_CAMERA_STATEINFO)Marshal.PtrToStructure(outPtr, typeof(NET_OUT_GET_CAMERA_STATEINFO));
if (outParam.nValidNum > 0)
{
var status = new NET_CAMERA_STATE_INFO[outParam.nValidNum];
for (int i = 0; i < outParam.nValidNum; i++)
{
status[i] = (NET_CAMERA_STATE_INFO)Marshal.PtrToStructure(outParam.pCameraStateInfo + i * Marshal.SizeOf(typeof(NET_CAMERA_STATE_INFO)), typeof(NET_CAMERA_STATE_INFO));
}
return status;
}
return null;
}