Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
        public static void cbNetMsgProc(int id, int nType, IntPtr pointer)
        {
            switch ((CMD_CODE)nType)
            {
            case CMD_CODE.R_CONNECT:
                g_protocalInanter.OnConnectEH(g_protocalInanter.device, 0);
                break;

            case CMD_CODE.R_DISCONNECT:
                g_protocalInanter.OnConnectEH(g_protocalInanter.device, 1);
                break;

            case CMD_CODE.R_EVENT:
            {
                EVENT_PACK pack   = (EVENT_PACK)Marshal.PtrToStructure(pointer, typeof(EVENT_PACK));
                Sensor     sensor = g_protocalInanter.FindSensorBySID(pack.channel, pack.id);
                if (sensor != null)
                {
                    STATUS_INFO info = new STATUS_INFO();
                    info.no             = (int)sensor.id;
                    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;
                    info.classification = (CLASSIFICATION)pack.classification;
                    if (pack.alarmneed == 0)
                    {
                        info.status = STATUS_TYPE.WARNING;
                    }
                    else
                    {
                        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");
                    g_protocalInanter.OnObjectStatusEH(info);
                }
            }
            break;

            case CMD_CODE.R_STATUS:
            {
                STATUS_PACK pack   = (STATUS_PACK)Marshal.PtrToStructure(pointer, typeof(STATUS_PACK));
                Sensor      sensor = g_protocalInanter.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 = g_protocalInanter.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;
                            g_protocalInanter.OnObjectErrorEH(infoFront);
                        }
                    }

                    ERROR_INFO info = new ERROR_INFO();
                    info.id   = sensor.id;
                    info.name = sensor.name;
                    if (pack.status == 0)
                    {
                        info.status = STATUS_TYPE.NORMAL;
                    }
                    else if (pack.status == 1)
                    {
                        info.status = STATUS_TYPE.ERROR;
                    }
                    else if (pack.status == 2)
                    {
                        info.status = STATUS_TYPE.DISABLE;
                    }
                    else if (pack.status == 3)
                    {
                        info.status = STATUS_TYPE.OFFLINE;
                    }
                    else if (pack.status == 4)
                    {
                        info.status = STATUS_TYPE.UNCOVER;
                    }
                    info.starttime = vDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                    info.type      = OBJECT_TYPE.sensor;
                    g_protocalInanter.OnObjectErrorEH(info);
                }
            }
            break;
            }
        }