예제 #1
0
        public static ChannelPort Build(ChannelType channelType, params string[] ports)
        {
            var port = new ChannelPort
            {
                ChannelType     = channelType,
                _serialPortInfo = ports
            };

            switch (channelType)
            {
            case ChannelType.Serial:
            {
                if (!int.TryParse(ports[0], out port._serialPort[0]))
                {
                    port._serialPort[0] = 0;
                }
                if (ports.Length == 1 || !int.TryParse(ports[1], out port._serialPort[1]))
                {
                    port._serialPort[1] = 115200;
                }
                port._id = $"{port._serialPort[0]}:{port._serialPort[1]}";
                break;
            }

            case ChannelType.Tcpip:
            {
                IPAddress ip  = IPAddress.Parse(ports[0]);
                int       p   = int.Parse(ports[1]);
                var       ipe = new IPEndPoint(ip, p);
                port._ipEndPoint = ipe;
                port._id         = ipe.ToString();
                break;
            }
            }
            return(port);
        }
예제 #2
0
 protected bool Equals(ChannelPort other)
 {
     return(_id.Equals(other._id) && ChannelType == other.ChannelType);
 }