public static ILaser CreateLaserController(LaserConfig laserPara, TcpClientStream tcpClient) { ILaser laser = null; string typeStr = laserPara.LaserType.ToString(); switch (typeStr) { case "Raycus": if (laserPara.ControlType == LaserControlTypes.Extern) { laser = new LaserController(tcpClient, laserPara.MaxVoltage); } else { var serialPortStream = new SerialPortStream(laserPara.PortName, 9600); laser = new RaycusLaserController(serialPortStream); } break; case "Other": laser = new LaserController(tcpClient, laserPara.MaxVoltage); break; default: throw new Exception("LaserFactory: not support!"); } return(laser); }
private static void InitHardware() { //TODO: Ethernet not found, set dummy mode string ip = SystemContext.SystemPara.IpAddress; int port = SystemContext.SystemPara.Port; var device = TcpClientStream.SearchDevice(ip, port); if (device == null) { SystemContext.IsDummyMode = true; var motor = new DummyMotorController(); var laser = new DummyLaser(); var blowing = new DummyIO(); SystemContext.Hardware = new HardwareProxy(motor, laser, blowing); } else { SystemContext.IsDummyMode = false; var para = SystemContext.SystemPara; Func <AxisParameter, MotorParameter> convert = x => new MotorParameter { Ratio = x.Ratio, IsReversed = x.Reversed }; var motorPara = new Dictionary <AxisTypes, MotorParameter>(); motorPara[AxisTypes.AxisX] = convert(para.XPara); motorPara[AxisTypes.AxisY] = convert(para.YPara); motorPara[AxisTypes.AxisY].IsDualDriven = true; motorPara[AxisTypes.AxisZ] = convert(para.ZPara); motorPara[AxisTypes.AxisW] = new MotorParameter(); var motor = new MotorController(device, motorPara); var laser = new LaserController(device, 10); var blowing = new IOController(device); SystemContext.Hardware = new HardwareProxy(motor, laser, blowing); } }
public LaserController(TcpClientStream tcpClient, double maxVoltage) { this.tcpClient = tcpClient; this.maxVoltage = maxVoltage; //Initialize hardware //this.SetVoltage(1); //this.SetVoltage(2); }
public MotorController(TcpClientStream tcpClient, Dictionary <AxisTypes, MotorParameter> motorPara) { this.tcpClient = tcpClient; this.motorParaMap = new Dictionary <AxisTypes, MotorParameter>(); var axises = EnumHelper.GetAllEnumMembers <AxisTypes>(); foreach (var m in axises) { this.motorParaMap[m] = motorPara.Keys.Contains(m) ? motorPara[m] : new MotorParameter(); } this.LoadMotorInfo(); this.EnableAllMotor(); }
public void Dispose() { if (TcpClientStream != null) { TcpClientStream.Dispose(); TcpClientStream = null; } if (TcpClient != null) { TcpClient.Close(); TcpClient = null; } OutgoingPackets.Clear(); }
public IOController(TcpClientStream tcpClient) { this.tcpClient = tcpClient; }
protected ServiceUpnp(Device aDevice, ServiceType aType, IProtocol aProtocol, IEventUpnpProvider aEventServer) : base(aDevice, aType, aProtocol) { Server = aEventServer; iMutex = new Mutex(); iUnsubscribeCompleted = new ManualResetEvent(false); iControlUri = new Uri(Location.Find(ServiceLocationUpnp.kKeyUpnpControlUri)); iSubscribing = false; iUnsubscribing = false; iPendingSubscribe = false; iPendingUnsubscribe = false; iClosing = false; if (Server != null) { iEventUri = new Uri(Location.Find(ServiceLocationUpnp.kKeyUpnpSubscriptionUri)); IPAddress address; if (IPAddress.TryParse(iEventUri.Host, out address)) { iEventEndpoint = new IPEndPoint(address, iEventUri.Port); } else { try { IPAddress[] addresses = Dns.GetHostEntry(iEventUri.Host).AddressList; for (int i = 0; i < addresses.Length && address == null; i++) { if (addresses[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { address = addresses[i]; break; } } if (address != null) { iEventEndpoint = new IPEndPoint(address, iEventUri.Port); } else { UserLog.WriteLine("Endpoint not found: " + iEventUri.Host + ":" + iEventUri.Port); throw new NetworkError(); } } catch (Exception ex) { throw (new ServiceException(903, "Endpoint lookup failure: " + iEventUri.Host + ":" + iEventUri.Port + ", " + ex)); } } iSubscriptionTimer = new System.Threading.Timer(SubscriptionTimerElapsed, null, Timeout.Infinite, Timeout.Infinite); iRequest = new TcpClientStream(); iWriteBuffer = new Swb(kMaxWriteBufferBytes, iRequest); iReadBuffer = new Srb(kMaxReadBufferBytes, iRequest); iWriter = new WriterRequest(iWriteBuffer); iReader = new ReaderResponse2(iReadBuffer); iHeaderUpnpSid = new HeaderUpnpSid(); iHeaderUpnpServer = new HeaderUpnpServer(); iHeaderUpnpTimeout = new HeaderUpnpTimeout(); iReader.AddHeader(iHeaderUpnpSid); iReader.AddHeader(iHeaderUpnpServer); iReader.AddHeader(iHeaderUpnpTimeout); } }