예제 #1
0
        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);
        }
예제 #2
0
        private static void ThreadCheckConnection(object o)
        {
            ProtocolMoxa moxa   = (ProtocolMoxa)o;
            Device       device = moxa.device;

            while (true)
            {
                Thread.Sleep(3000);
                if (!device.enable)
                {
                    continue;
                }
                if (!moxa.IsRun)
                {
                    continue;
                }
                lock (lc)
                {
                    byte value = 100;
                    if (MXEIO_CheckConnection(moxa.handle, 300, ref value) == 0)
                    {
                        if (value != 0)
                        {
                            MXEIO_Connect(device.ip, (UInt16)device.port, 300, ref moxa.handle);

                            /*
                             * if (MXEIO_Connect(device.ip, (UInt16)device.port, 300, ref moxa.handle) != 0)
                             * {
                             *  moxa.OnConnectEH(device, 1);
                             * }
                             * else
                             * {
                             *  moxa.OnConnectEH(device, 0);
                             * }
                             */
                        }
                    }
                }
            }
        }
예제 #3
0
        private static void ThreadMethod(object o)
        {
            ProtocolMoxa moxa   = (ProtocolMoxa)o;
            Device       device = moxa.device;

            while (true)
            {
                Thread.Sleep(1000);
                if (!device.enable)
                {
                    continue;
                }
                if (moxa.handle == -1)
                {
                    continue;
                }
                lock (lc)
                {
                    foreach (var group in device.listChannel)
                    {
                        if (group.number != 1)
                        {
                            continue;
                        }
                        foreach (var sensor in group.listSensor)
                        {
                            byte value   = 100;
                            byte channel = (byte)sensor.number;
                            if (DI_Read(moxa.handle, 1, channel, ref value) == 0)
                            {
                                if (value == 0)
                                {
                                    STATUS_INFO old = moxa.listAlarm.Find(x => x.id == sensor.id);
                                    if (old != null)
                                    {
                                        continue;
                                    }
                                    STATUS_INFO info = new STATUS_INFO();
                                    info.id         = sensor.id;
                                    info.name       = sensor.name;
                                    info.status     = STATUS_TYPE.ALARM;
                                    info.time       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                    info.type       = MONITOR_TYPE.io;
                                    info.confidence = 100;
                                    moxa.listAlarm.Add(info);
                                    moxa.OnObjectStatusEH(info);
                                }
                                else
                                {
                                    STATUS_INFO old = moxa.listAlarm.Find(x => x.id == sensor.id);
                                    if (old != null)
                                    {
                                        moxa.listAlarm.Remove(old);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }