Exemple #1
0
        private string I7565DNM_SETIO()
        {
            string   result     = "I7565DNM_SETIO ERROR";
            string   device     = "";
            string   value      = "";
            string   io         = "";
            I7565DNM deviceCtrl = null;

            try
            {
                if (!checkI7565DNM(ref result, ref device, ref io, ref deviceCtrl))
                {
                    return(result);
                }
                varMap.TryGetValue("@value", out value);
                if (value == null || value.Equals("undefined"))
                {
                    result = "value not define";
                    return(result);
                }
                deviceCtrl.I7565DNM_SETIO(io, Convert.ToUInt32(value));
                result = deviceCtrl.errorCode;
                return(result);
            }
            catch (Exception e)
            {
                logger.Error(e.StackTrace);
                return(result);
            }
        }
Exemple #2
0
        private string I7565DNM_CHECK_SLAVE()
        {
            string   result     = "I7565DNM_CHECK_SLAVE ERROR";
            string   device     = "";
            I7565DNM deviceCtrl = null;

            try
            {
                varMap.TryGetValue("@device", out device);
                if (device == null)
                {
                    result = "device not define";
                    return(result);
                }
                Marco.deviceMap.TryGetValue(device, out object obj);
                if (obj == null)
                {
                    result = "Device:" + device + " not exist.";
                    return(result);
                }
                deviceCtrl = (I7565DNM)obj;
                deviceCtrl.I7565DNM_CHECK_SLAVE();
                result = deviceCtrl.errorCode;
                return(result);
            }
            catch (Exception e)
            {
                logger.Error(e.StackTrace);
                return(result);
            }
        }
Exemple #3
0
        private string I7556DNM_CHECK_EMS(ref string a_values)  //讀取EMS Bit
        {
            string result = "I7565DNM_CHECK_EMS ERROR";
            string device = "";

            //check iems_io
            if (!varMap.TryGetValue("@ems_input", out string s_ems_io))
            {
                result = "ems_io not define";
                return(result);
            }

            //check ems_values
            if (!varMap.TryGetValue("@ems_values", out string s_ems_values))
            {
                result = "ems_values not define";
                return(result);
            }


            varMap.TryGetValue("@device", out device);
            if (device == null || device.Equals("undefined"))
            {
                result = "device not define";
                return(result);
            }

            Marco.deviceMap.TryGetValue(device, out object obj);

            I7565DNM deviceCtrl = (I7565DNM)obj;

            //確認單點或這是多點
            if (!s_ems_io.Contains(";"))
            {
                uint s = deviceCtrl.I7565DNM_GETIO(s_ems_io, true);
                a_values = s.ToString();
                result   = deviceCtrl.errorCode;
            }
            else
            {
                string   deviceErrorCode = "";
                string[] ioAry           = s_ems_io.Split(';'); //檢查點位(Address)
                foreach (string ss in ioAry)
                {
                    uint s = deviceCtrl.I7565DNM_GETIO(ss, true);
                    a_values        = a_values + s.ToString();
                    deviceErrorCode = deviceCtrl.errorCode;

                    //硬體讀取值異常
                    if (!deviceErrorCode.Equals(""))
                    {
                        result = deviceErrorCode;
                    }
                }
            }

            return(result);
        }
Exemple #4
0
        private string I7565DNM_SETIOS()
        {
            string   result     = "I7565DNM_SETIOS ERROR";
            string   device     = "";
            string   values     = "";
            string   ios        = "";
            I7565DNM deviceCtrl = null;

            try
            {
                if (!checkI7565DNM(ref result, ref device, ref ios, ref deviceCtrl))
                {
                    return(result);
                }
                varMap.TryGetValue("@value", out values);
                if (values == null || values.Equals("undefined"))
                {
                    result = "value not define";
                    return(result);
                }
                string[] valueAry = values.Split(';');
                if (valueAry.Length != 1 & (valueAry.Length != ios.Split(';').Length))
                {
                    result = "value item count error";
                    return(result);
                }
                int idx = 0;
                foreach (string io in ios.Split(';'))
                {
                    uint value = valueAry.Length == 1 ? Convert.ToUInt32(valueAry[0]) : Convert.ToUInt32(valueAry[idx]);
                    deviceCtrl.I7565DNM_SETIO(io, value);
                    result = deviceCtrl.errorCode;
                    if (!result.Equals(""))
                    {
                        return(result);
                    }
                    idx++;
                }
                return(result);
            }
            catch (Exception e)
            {
                logger.Error(e.StackTrace);
                return(result);
            }
        }
Exemple #5
0
        private string I7565DNM_READIO(ref string value)
        {
            string   result     = "I7565DNM_READIO ERROR";
            string   device     = "";
            string   io         = "";
            I7565DNM deviceCtrl = null;

            try
            {
                if (!checkI7565DNM(ref result, ref device, ref io, ref deviceCtrl))
                {
                    return(result);
                }
                uint s = deviceCtrl.I7565DNM_READIO(io);
                value  = s.ToString();
                result = deviceCtrl.errorCode;
                return(result);
            }
            catch (Exception e)
            {
                logger.Error(e.StackTrace);
                return(result);
            }
        }
Exemple #6
0
        private string I7565DNM_READIOS(ref string values)
        {
            string   result     = "I7565DNM_READIOS ERROR";
            string   device     = "";
            string   ios        = "";
            I7565DNM deviceCtrl = null;

            if (!checkI7565DNM(ref result, ref device, ref ios, ref deviceCtrl))
            {
                return(result);
            }
            string[] ioAry = ios.Split(';');
            foreach (string io in ioAry)
            {
                uint s = deviceCtrl.I7565DNM_READIO(io);
                values = values + s.ToString();
                result = deviceCtrl.errorCode;
                if (!result.Equals(""))
                {
                    return(result);
                }
            }
            return(result);
        }
Exemple #7
0
        public static void ConnDevice()
        {
            //util.Connect();
            //XmlConfigurator.Configure();//Log4N 需要
            var configFile = Directory.GetCurrentDirectory() + "\\" + "Device.config";
            ConfigurationFileMap fileMap = new ConfigurationFileMap(configFile);
            DeviceConfiguration  config  = ConfigurationManager.OpenMappedMachineConfiguration(fileMap).GetSection("deviceSettingGroup/deviceConfig") as DeviceConfiguration;

            Console.WriteLine();
            deviceMap.Clear();

            runMode = RunMode.Normal;
            foreach (DeviceSettingElement foo in config.DeviceSettings)
            {
                IDevice dvcCtrl;

                if (!foo.Enable.Equals("1"))
                {
                    Console.WriteLine("---Device:" + foo.Name + " is disabled !-------------------");
                    continue;
                }
                DeviceConfig dc = new DeviceConfig();
                dc.DeviceName     = foo.Name;
                dc.ConnectionType = foo.Conn_Type;
                dc.Vendor         = foo.Vendor;
                if (foo.Conn_Type.Equals("Socket"))
                {
                    dc.IPAdress = foo.Conn_Address;
                    dc.Port     = Int32.Parse(foo.Conn_Port);
                    dvcCtrl     = new DeviceController(dc);
                    dvcCtrl.AssignedRecevicedEvent(ReceivedEventMessage);
                    dvcCtrl.start();

                    Marco.deviceMap.Add(foo.Name, dvcCtrl);
                }
                else if (foo.Conn_Type.Equals("ComPort"))
                {
                    if (foo.Conn_Address.Equals(""))
                    {
                        string[] ports = SerialPort.GetPortNames();
                        if (ports.Count() == 0)
                        {
                            dc.PortName = "";
                        }
                        else
                        {
                            dc.PortName = ports[0];
                        }
                    }
                    else
                    {
                        dc.PortName = foo.Conn_Address;
                    }
                    dc.BaudRate  = foo.Com_Baud_Rate;
                    dc.DataBits  = foo.Com_Data_Bits;
                    dc.ParityBit = foo.Com_Parity_Bit;
                    dc.StopBit   = foo.Com_Stop_Bit;
                    dvcCtrl      = new DeviceController(dc);
                    dvcCtrl.AssignedRecevicedEvent(ReceivedEventMessage);
                    dvcCtrl.start();
                    Marco.deviceMap.Add(foo.Name, dvcCtrl);
                }
                else if (foo.Conn_Type.Equals("ICPDeviceNet"))
                {
                    if (foo.Conn_Address.Equals(""))
                    {
                        string[] ports = SerialPort.GetPortNames();
                        if (ports.Count() == 0)
                        {
                            dc.PortName = "";
                        }
                        else
                        {
                            dc.PortName = ports[0];
                        }
                    }
                    else
                    {
                        dc.PortName = foo.Conn_Address;
                    }

                    //暫時固定路徑
                    if (machineType == MachineType.Normal)
                    {
                        dc.File = "mini_18port.xls";
                    }
                    else
                    {
                        dc.File = "mini.xls";
                    }
                    //dc.File = foo.File;
                    dvcCtrl = new I7565DNM(dc);
                    if (!dvcCtrl.start() && foo.Conn_Address.Equals(""))
                    {
                        string[] ports = SerialPort.GetPortNames();

                        for (int i = 1; i < ports.Count(); i++)
                        {
                            dc.PortName = ports[i];
                            //dvcCtrlarray[].= ports[0];
                            dvcCtrl = new I7565DNM(dc);

                            if (dvcCtrl.start())
                            {
                                Marco.deviceMap.Add(foo.Name, dvcCtrl);
                                break;
                            }
                        }
                    }
                    else
                    {
                        Marco.deviceMap.Add(foo.Name, dvcCtrl);
                    }
                }
            }
            ////設定停用
            //var xmlDoc = new XmlDocument();
            //xmlDoc.Load(configFile);
            //xmlDoc.SelectSingleNode("//deviceSettingGroup/deviceConfig/devices/device[@name='Robot02']").Attributes["enable"].Value = "0";
            //xmlDoc.Save(configFile);
            //ConfigurationManager.RefreshSection("deviceSettingGroup/deviceConfig");
        }
Exemple #8
0
 private bool checkI7565DNM(ref string result, ref string device, ref string io, ref I7565DNM deviceCtrl)
 {
     try
     {
         varMap.TryGetValue("@device", out device);
         if (device == null || device.Equals("undefined"))
         {
             result = "device not define";
             return(false);
         }
         varMap.TryGetValue("@io", out io);
         if (io == null || io.Equals("undefined"))
         {
             result = "io not define";
             return(false);
         }
         Marco.deviceMap.TryGetValue(device, out object obj);
         if (obj == null)
         {
             result = "Device:" + device + " not exist.";
             return(false);
         }
         deviceCtrl = (I7565DNM)obj;
         return(true);
     }
     catch (Exception e)
     {
         result = e.StackTrace;
         return(false);
     }
 }