// auto detect insertion and de-insertion of the USB based 2255 frame grabbers // // polling loop checks the OS for a list of connected 2255 devices. // // if the detected device count is greater than the connected device count, try to open a new device // if the detected device count is less than the connected device count, close the missing device. // problem: the OS cannot tell me which device is connected/disconnected. // so if we think we lost a device, then check each open device for time stamp at last received frame, and if // its been a while since a frame was received, assume that is the missing frame grabber and close it. // each frame grabber is associated with a device index which is used by the 2255 USB driver to identify a device. // but we have no way of knowing which device index is assigned to a device by the driver except to // attempt to open the device at each index until we get success on OpenDevice(index). So a test open // function is in the S2255Device class which opens and then closes if the open was sucessful. // the S2255Device class is a class which is designed to control a single instance of a 2255 physical device. So if // there are two frame grabbers attached there should be two instances of the S2255Device class. public unsafe S2255Controller(PAL_NTSC_MODE mode, APPLICATION_DATA appData, bool [] enableChannels) { m_PAL_NSTC_mode = mode; m_AppData = appData; m_EabledSysChannels = enableChannels; m_Log = (ErrorLog)m_AppData.Logger; m_AppData.AddOnClosing(StopThreads, APPLICATION_DATA.CLOSE_ORDER.FIRST); // how to stop this object and its subthreads m_VideoStandard = (mode == PAL_NTSC_MODE.NTSC) ? 0 : 1; // allocate 2255Device instances m_S2255Devices = new ThreadSafeList<S2255Device>(MAX_S2255DEVICE_COUNT); // max allowed number of connected frame grabbers m_DeviceHandlePool = new DeviceValuePoolManager(MAX_2255DEVICE_HANDLE_VALUE); // maximum value of device index that could be assigned by the USB driver m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_frameGrabber_1].StatString.SetValue = "No Device"; m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_frameGrabber_2].StatString.SetValue = "No Device"; m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_videoChannel1].StatString.SetValue = "No Video Connected"; m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_videoChannel2].StatString.SetValue = "No Video Connected"; m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_videoChannel3].StatString.SetValue = "No Video Connected"; m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_videoChannel4].StatString.SetValue = "No Video Connected"; m_UsedDeviceIndexes = new DeviceValuePoolManager(MAX_S2255DEVICE_COUNT); // current channel mapping: // each S2255 device has four ports. a camera will be connected in parrallel to two ports. // one port of the port pair will be setup as jpeg ecoded and the other is raw bitmap // on device 0 // port 0 and 1 will be camera channel 0 // port 2 and 3 will be camera channel 1 // on device 1 // port 0 and 1 will be camera channel 2 // port 2 and 3 will be camera channel 3 m_S2255DevicePortChannelMappsings = new S2255DevicePortChannelMappings[MAX_S2255DEVICE_COUNT];// set to 2 int deviceCounter = 0; for (deviceCounter = 0; deviceCounter < m_S2255DevicePortChannelMappsings.Length; deviceCounter++) { m_S2255DevicePortChannelMappsings[deviceCounter] = new S2255DevicePortChannelMappings(); } //////////////// assumes MAX_S2255DEVICE_COUNT == 2 , doing port mappins by hand here deviceCounter = 0; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[0] = 0; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[0] = COMPRESSION_MODE.BITMAP; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[0] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[0]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[1] = 0; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[1] = COMPRESSION_MODE.JPEG; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[1] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[1]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[2] = 1; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[2] = COMPRESSION_MODE.BITMAP; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[2] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[2]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[3] = 1; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[3] = COMPRESSION_MODE.JPEG; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[3] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[3]]; deviceCounter = 1; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[0] = 2; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[0] = COMPRESSION_MODE.BITMAP; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[0] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[0]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[1] = 2; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[1] = COMPRESSION_MODE.JPEG; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[1] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[1]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[2] = 3; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[2] = COMPRESSION_MODE.BITMAP; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[2] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[2]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[3] = 3; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[3] = COMPRESSION_MODE.JPEG; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[3] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[3]]; }
// auto detect insertion and de-insertion of the USB based 2255 frame grabbers // // polling loop checks the OS for a list of connected 2255 devices. // // if the detected device count is greater than the connected device count, try to open a new device // if the detected device count is less than the connected device count, close the missing device. // problem: the OS cannot tell me which device is connected/disconnected. // so if we think we lost a device, then check each open device for time stamp at last received frame, and if // its been a while since a frame was received, assume that is the missing frame grabber and close it. // each frame grabber is associated with a device index which is used by the 2255 USB driver to identify a device. // but we have no way of knowing which device index is assigned to a device by the driver except to // attempt to open the device at each index until we get success on OpenDevice(index). So a test open // function is in the S2255Device class which opens and then closes if the open was sucessful. // the S2255Device class is a class which is designed to control a single instance of a 2255 physical device. So if // there are two frame grabbers attached there should be two instances of the S2255Device class. unsafe public S2255Controller(PAL_NTSC_MODE mode, APPLICATION_DATA appData, bool [] enableChannels) { m_PAL_NSTC_mode = mode; m_AppData = appData; m_EabledSysChannels = enableChannels; m_Log = (ErrorLog)m_AppData.Logger; m_AppData.AddOnClosing(StopThreads, APPLICATION_DATA.CLOSE_ORDER.FIRST); // how to stop this object and its subthreads m_VideoStandard = (mode == PAL_NTSC_MODE.NTSC) ? 0 : 1; // allocate 2255Device instances m_S2255Devices = new ThreadSafeList <S2255Device>(MAX_S2255DEVICE_COUNT); // max allowed number of connected frame grabbers m_DeviceHandlePool = new DeviceValuePoolManager(MAX_2255DEVICE_HANDLE_VALUE); // maximum value of device index that could be assigned by the USB driver m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_frameGrabber_1].StatString.SetValue = "No Device"; m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_frameGrabber_2].StatString.SetValue = "No Device"; m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_videoChannel1].StatString.SetValue = "No Video Connected"; m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_videoChannel2].StatString.SetValue = "No Video Connected"; m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_videoChannel3].StatString.SetValue = "No Video Connected"; m_AppData.HealthStatistics[(int)APPLICATION_DATA.HEALTH_STATISTICS.System.System_videoChannel4].StatString.SetValue = "No Video Connected"; m_UsedDeviceIndexes = new DeviceValuePoolManager(MAX_S2255DEVICE_COUNT); // current channel mapping: // each S2255 device has four ports. a camera will be connected in parrallel to two ports. // one port of the port pair will be setup as jpeg ecoded and the other is raw bitmap // on device 0 // port 0 and 1 will be camera channel 0 // port 2 and 3 will be camera channel 1 // on device 1 // port 0 and 1 will be camera channel 2 // port 2 and 3 will be camera channel 3 m_S2255DevicePortChannelMappsings = new S2255DevicePortChannelMappings[MAX_S2255DEVICE_COUNT];// set to 2 int deviceCounter = 0; for (deviceCounter = 0; deviceCounter < m_S2255DevicePortChannelMappsings.Length; deviceCounter++) { m_S2255DevicePortChannelMappsings[deviceCounter] = new S2255DevicePortChannelMappings(); } //////////////// assumes MAX_S2255DEVICE_COUNT == 2 , doing port mappins by hand here deviceCounter = 0; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[0] = 0; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[0] = COMPRESSION_MODE.BITMAP; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[0] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[0]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[1] = 0; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[1] = COMPRESSION_MODE.JPEG; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[1] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[1]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[2] = 1; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[2] = COMPRESSION_MODE.BITMAP; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[2] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[2]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[3] = 1; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[3] = COMPRESSION_MODE.JPEG; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[3] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[3]]; deviceCounter = 1; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[0] = 2; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[0] = COMPRESSION_MODE.BITMAP; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[0] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[0]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[1] = 2; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[1] = COMPRESSION_MODE.JPEG; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[1] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[1]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[2] = 3; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[2] = COMPRESSION_MODE.BITMAP; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[2] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[2]]; m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[3] = 3; m_S2255DevicePortChannelMappsings[deviceCounter].compressionMode[3] = COMPRESSION_MODE.JPEG; m_S2255DevicePortChannelMappsings[deviceCounter].enabled[3] = m_EabledSysChannels[m_S2255DevicePortChannelMappsings[deviceCounter].globalChannIndex[3]]; }