Example #1
0
        public Result EndConnect()
        {
            var result = new Result();

            if (this.Communicator.CommType == "Serial")
            {
                result = new SerialComm().EndConnect(this);
            }
            else if (this.Communicator.CommType == "OmronFinsTcp")
            {
                result = new OmronFinsTcpComm().EndConnect(this);
            }
            else if (this.Communicator.CommType == "Ethernet")
            {
                result = new EthernetComm().EndConnect(this);
            }
            Connected = false;
            return(Result.Success);
        }
Example #2
0
        public Result Write(string addr, ushort value)
        {
            var result = Result.Success;

            if (this.Communicator.CommType == "OmronFinsTcp")
            {
                result = new OmronFinsTcpComm().Write(this, addr, value);
            }
            else
            {
                result = new Result("连接为未知类型!");
            }

            if (result.IsFailed)
            {
                LogHelper.WriteError(string.Format("给 {0} 写数据出现错误: {1}", this.Communicator.Name, result.Msg));
            }
            return(result);
        }
Example #3
0
        public Result Connect()
        {
            var result = new Result();

            if (!this.Connected)
            {
                if (this.Communicator.CommType == "Serial")
                {
                    result = new SerialComm().Connect(this);
                }
                else if (this.Communicator.CommType == "OmronFinsTcp")
                {
                    result = new OmronFinsTcpComm().Connect(this);
                }
                else if (this.Communicator.CommType == "Ethernet")
                {
                    result = new EthernetComm().Connect(this);
                }
            }

            this.Connected = result.IsSucceed;
            return(result);
        }