예제 #1
0
 public static string BuildNetKey(string key, NetParameter para)
 {
     if ((key != null) && (para != null))
         return key + ":" + para.ServerIp + ":" + para.ServerPort;
     else
         return null;
 }
예제 #2
0
 public XTcpClient(NetParameter para)
     : base()
 {
     Parameter = para;
 }
예제 #3
0
 public XUdpClient(NetParameter para)
     : this(new IPEndPoint(NetPoint.LocalHostPoint[para.LocalEthIndex].IPAddress, para.LocalPort))
 {
     Parameter = para;
 }
예제 #4
0
 private static bool Load()
 {
     if (XComCfg == null)
         return false;
     try
     {
         var queryVendor = XComCfg.Doc.Descendants(XComCfg.NameSpace + "XCom").Descendants().Select(n => new { n.Name, n });
         foreach (var item in queryVendor)
         {
             XComInfo xComInfo = new XComInfo();
             xComInfo.Type = item.Name.LocalName;
             if (xComInfo.Type == "XSerialPort")
             {
                 XSerialParameter para = new XSerialParameter();
                 for (XAttribute attr = item.n.FirstAttribute; attr != null; attr = attr.NextAttribute)
                 {
                     switch (attr.Name.LocalName)
                     {
                         case "PortName":
                             para.PortName = attr.Value;
                             break;
                         case "Baudrate":
                             para.Baudrate = int.Parse(attr.Value);
                             break;
                         case "Parity":
                             para.Parity = (Parity)Enum.Parse(typeof(Parity), attr.Value);
                             break;
                         case "DataBits":
                             para.DataBits = int.Parse(attr.Value);
                             break;
                         case "StopBits":
                             para.StopBits = (StopBits)Enum.Parse(typeof(StopBits), attr.Value);
                             break;
                         case "Handshake":
                             para.Handshake = (Handshake)Enum.Parse(typeof(Handshake), attr.Value);
                             break;
                         case "Key":
                             xComInfo.Key = attr.Value;
                             break;
                         default:
                             break;
                     }
                 }
                 xComInfo.Parameter = para;
             }
             else if((xComInfo.Type == "XUdpClient") || (xComInfo.Type == "XTcpClient"))
             {
                 NetParameter para = new NetParameter();
                 for (XAttribute attr = item.n.FirstAttribute; attr != null; attr = attr.NextAttribute)
                 {
                     switch (attr.Name.LocalName)
                     {
                         case "ServerIP":
                             para.ServerIp = attr.Value;
                             break;
                         case "ServerPort":
                             para.ServerPort = int.Parse(attr.Value);
                             break;
                         case "Timeout":
                             para.Timeout = int.Parse(attr.Value);
                             break;
                         case "LocalEthIndex":
                             para.LocalEthIndex = int.Parse(attr.Value);
                             break;
                         case "LocalPort":
                             para.LocalPort = int.Parse(attr.Value);
                             break;
                         case "Key":
                             xComInfo.Key = attr.Value;
                             break;
                         default:
                             break;
                     }
                 }
                 xComInfo.Parameter = para;
             }
             _xComInfo.Add(xComInfo);
         }
     }
     catch(Exception e)
     {
         throw new APXExeception(e.Message);
     }
     return true;
 }
예제 #5
0
 public virtual bool Start()
 {
     if (IsStarted)
         return true;
     try
     {
         switch (Info.ProtType)
         {
             case LaserProtocolType.LaserTCP:
             case LaserProtocolType.LaserUDP:
                 NetParameter para = new NetParameter(Info.IPAddress, Info.Port);
                 Protocol = new LaserProtocol(XComManager.XComsDict[NetKey.BuildNetKey(Info.ComKey, para)].Instance());
                 break;
             default:
                 break;
         }
         if(Protocol!=null)
         {
             Protocol.Start();
             IsStarted = true;
         }
     }
     catch(Exception e)
     {
         throw new APXExeception(e.Message);
     }
     return true;
 }
예제 #6
0
파일: Plc.cs 프로젝트: legendmaker/Apintec
 public virtual bool Start()
 {
     if (IsStarted)
         return true;
     try
     {
         switch (Info.ProtType)
         {
             case PlcProtocolType.FinsUDP:
             case PlcProtocolType.FinsTCP:
                 NetParameter para = new NetParameter(Info.IPAddress, Info.Port);
                 Key = NetKey.BuildNetKey(Info.ComKey, para);
                 Comm = XComManager.XComsDict[Key].Instance();
                 ProtocolInstance = new Fins(Info.ProtType, Info.Network, Info.Unit, IPAddress.Parse(Info.IPAddress).GetAddressBytes()[3],
                        Info.Timeout, Info.LocalHostEthIndex, Comm);
                 break;
             case PlcProtocolType.None:
             default:
                 ProtocolInstance = new PlcProtocol(Comm);
                 break;
         }
         ProtocolInstance.Start();
         IsStarted = true;
     }
     catch(Exception e)
     {
         throw new APXExeception(e.Message);
     }
     return true;
 }