public static ProtocolDriver CreateInstance(Device device) { ProtocolDriver driver = null; switch (device.key) { case DEVICE_KEY.FBG: driver = new ProtocolFbg(device); break; case DEVICE_KEY.DVS: case DEVICE_KEY.DTS: driver = new ProtocolDVS(device); break; case DEVICE_KEY.INANTER: driver = new ProtocolInanter(device); break; case DEVICE_KEY.ES: driver = new ProtocolEs(device); break; case DEVICE_KEY.HK: driver = new ProtocolHK(device); break; case DEVICE_KEY.MOXA_2K: driver = new ProtocolMoxa(device); break; case DEVICE_KEY.JDEX: driver = new ProtocolJDExpand(device); break; case DEVICE_KEY.VIDEO: driver = new ProtocolVideo(device); break; case DEVICE_KEY.HKAI: driver = new ProtocolHKAI(device); break; case DEVICE_KEY.DHAlarm: driver = new ProtocolDHAlarm(device); break; default: break; } return(driver); }
private static void cbNetMsgProc(int handle, int nType, IntPtr pointer) { if (GlobalMain.from == null) { return; } ProtocolDVS driver = GlobalMain.from._listDriver.Find(x => x.instance == handle) as ProtocolDVS; if (driver == null) { return; } switch ((CMD_CODE)nType) { case CMD_CODE.R_CONNECT: driver.OnConnectEH(driver.device, 0); break; case CMD_CODE.R_DISCONNECT: driver.OnConnectEH(driver.device, 1); break; case CMD_CODE.R_EVENT: { EVENT_PACK pack = (EVENT_PACK)Marshal.PtrToStructure(pointer, typeof(EVENT_PACK)); if (pack.alarmneed == 0) { break; } Sensor sensor = driver.FindSensorBySID(pack.channel, pack.id); if (sensor != null) { STATUS_INFO info = new STATUS_INFO(); info.no = pack.no; info.id = sensor.id; info.type = (MONITOR_TYPE)sensor.type; info.name = sensor.name; info.range1 = pack.range1.ToString(); info.range2 = pack.range2.ToString(); info.confidence = pack.confidence / 100; info.classification = (CLASSIFICATION)pack.classification; info.status = STATUS_TYPE.ALARM; DateTime vDateTime = new DateTime( pack.time.vYear, pack.time.vMonth, pack.time.vDay, // 月日年 pack.time.vHour, pack.time.vMinute, pack.time.vSecond, // 时分秒 pack.time.vMiliseconds); // 毫秒 info.time = vDateTime.ToString("yyyy-MM-dd HH:mm:ss"); driver.OnObjectStatusEH(info); } } break; case CMD_CODE.R_ERROR: { ERROR_PACK pack = (ERROR_PACK)Marshal.PtrToStructure(pointer, typeof(ERROR_PACK)); Sensor sensor = driver.FindSensorBySID(pack.channel, pack.id); if (sensor != null) { DateTime vDateTime = new DateTime( pack.time.vYear, pack.time.vMonth, pack.time.vDay, // 月日年 pack.time.vHour, pack.time.vMinute, pack.time.vSecond, // 时分秒 pack.time.vMiliseconds); // 毫秒 Channel channel = driver.device.listChannel.Find(x => x.number == pack.channel); if (channel != null) { List <Sensor> listSensorFront = channel.listSensor.FindAll(x => (x.number != sensor.number && x.status == STATUS_TYPE.ERROR)); foreach (var front in listSensorFront) { ERROR_INFO infoFront = new ERROR_INFO(); infoFront.id = front.id; infoFront.name = front.name; infoFront.status = STATUS_TYPE.NORMAL; infoFront.starttime = vDateTime.ToString("yyyy-MM-dd HH:mm:ss"); infoFront.type = OBJECT_TYPE.sensor; driver.OnObjectErrorEH(infoFront); } } ERROR_INFO info = new ERROR_INFO(); info.id = sensor.id; info.name = sensor.name; if (pack.error == 1) { info.status = STATUS_TYPE.ERROR; } else if (pack.error == 0) { info.status = STATUS_TYPE.NORMAL; } info.starttime = vDateTime.ToString("yyyy-MM-dd HH:mm:ss"); info.type = OBJECT_TYPE.sensor; driver.OnObjectErrorEH(info); } } break; } }