public void Connect(string ip = null, int?port = null)
        {
            if (ip != null)
            {
                this.PlcIp = ip;
            }
            if (port != null)
            {
                this.PlcPortId = port.Value;
            }

            this.PlcLdd = new MvOmronPlcLdd();
            this.PlcLdd.NLPLC_Initial(this.PlcIp, this.PlcPortId);
        }
Beispiel #2
0
        public void TestPlcInsResult()
        {
            using (var plc = new MvOmronPlcLdd())
            {
                plc.NLPLC_Initial("192.168.0.200", 2);


                var test = plc.Read(MacHalPlcEnumVariable.PC_TO_IC_XPoint.ToString());
                plc.Write(MacHalPlcEnumVariable.PC_TO_IC_XPoint.ToString(), 10.0);
                test = plc.Read(MacHalPlcEnumVariable.PC_TO_IC_XPoint.ToString());

                Console.WriteLine(test);
            }
        }
Beispiel #3
0
        public void TestPlcOn()
        {
            using (var plc = new MvOmronPlcLdd())
            {
                plc.NLPLC_Initial("192.168.0.200", 2);


                plc.Write(MvEnumPlcVariable.PC_TO_PLC_CheckClock.ToString(), true);
                Thread.Sleep(500);
                var test = plc.Read(MvEnumPlcVariable.PC_TO_PLC_CheckClock_Reply.ToString());


                Console.WriteLine(test);
            }
        }
        public void Close()
        {
            if (this.PlcLdd != null)
            {
                using (var obj = this.PlcLdd)
                {
                    obj.NLPLC_ClosePort();
                    this.PlcLdd = null;
                }
            }

            if (this.m_keepConnection != null)
            {
                using (var obj = this.m_keepConnection)
                {
                    obj.Cancel();
                    SpinWait.SpinUntil(() => obj.IsEnd(), 1000);
                }
                this.m_keepConnection = null;
            }
        }
Beispiel #5
0
        public int StartAsyn()
        {
            this.PlcLdd = new MvOmronPlcLdd();
            this.PlcLdd.NLPLC_Initial("192.168.0.200", 2);


            this.m_keepConnection = MvCancelTask.RunLoop(() =>
            {
                this.Write(MvEnumPlcVariable.PC_TO_PLC_CheckClock, false);
                if (!SpinWait.SpinUntil(() => !this.Read <bool>(MvEnumPlcVariable.PC_TO_PLC_CheckClock_Reply), 2500))
                {
                    this.LockAssign(ref this.m_isConnected, false);
                    return(false);
                }
                this.LockAssign(ref this.m_isConnected, true);


                this.Write(MvEnumPlcVariable.PC_TO_PLC_CheckClock, true);
                if (!SpinWait.SpinUntil(() => this.Read <bool>(MvEnumPlcVariable.PC_TO_PLC_CheckClock_Reply), 2500))
                {
                    this.LockAssign(ref this.m_isConnected, false);
                    //throw new MvException("PLC connection T1 timeout");
                    return(false);
                }
                else
                {
                    this.LockAssign(ref this.m_isConnected, true);
                }


                return(true);
            }, 500);



            return(0);
        }
Beispiel #6
0
        public override int HalConnect()
        {
            if (this.OmronPLC == null)
            {
                //需要安裝Omron CX-Complet library才能使用
                if (!File.Exists(@"C:\Program Files (x86)\OMRON\CX-Compolet\assembly\Sgw.1.7.0.0\CIPObjectLibrary.DLL"))
                {
                    throw new Exception("請安裝Omron CX-Compolet");//return -1;
                }
                var dict = this.DevSettings;

                var asmName  = dict["Assembly"];
                var compName = this.ID;
                var ip       = dict["IP"];
                var portId   = Convert.ToInt32(dict["PortId"]);

                var compFullName = string.Format("{0}/{1}", asmName, compName);


                this.OmronPLC = MvOmronPlcMapper.Create(compFullName);
                this.OmronPLC.NLPLC_Initial(ip, portId);
            }
            return(0);
        }