static void Main(string[] args) { EthernetSetUp setup = new EthernetSetUp("192.168.1.240", 102); ILog log = new DefaultLog("S7CommomClient") { ByteSteamLogSwicth = true, Handle = LogHandle.debug }; TimeOut timeout = new TimeOut("S7CommomClient", 1000, log); S7CommClient client = new S7CommClient(setup, timeout, log, 1); if (client.Connect()) { //DB块编号,地址,访问数据块的类型:0x81-input ,0x82-output ,0x83-flag , 0x84-DB; var address = new DeviceAddress(30, 0, 0x84, ByteOrder.BigEndian); var temp = client.ReadUShorts(address, 2); Thread.Sleep(1000); var temp1 = client.ReadBytes(address, 3); var address1 = new DeviceAddress(14, 0, 0x84, ByteOrder.BigEndian); var result = client.WriteUShort(address1, 12); var temp3 = client.ReadUShorts(address1, 1); } Console.ReadKey(); }
public ModbusTCPClient(EthernetSetUp ethernetSetUp, TimeOut timeOut, ILog log) { _ethernetSetUp = ethernetSetUp; TimeOut = timeOut; Log = log; DriType = DriverType.Ethernet; }
public TCPClientFactory(TCPClientConfig config, TimeOut timeOut, ILog log) : base() { _config = config; _setUp = new EthernetSetUp(config.IpAddress, config.Port); _timeOut = timeOut; _log = log; }
public bool OnInit() { _log.NormalLog(string.Format("ModbusTCPClientHanderTask:Init=>Initing ")); try { //获取配置 _config = ReaderXMLUtil.ReadXMLConfig <ModbusTCPClientConfig>("../../../../conf/Configuration.xml", ModbusTCPClientConfig.ReadConfig, "setup", "ModbusTCPClientHandlerTask")[0]; if (_config.IpAddress == "" || _config.SignalListFilePath == "") { _log.ErrorLog(string.Format("ModbusTCPClientHanderTask Init fail:{0}", "IP address or Signal file path is null!")); return(false); } _setup = new EthernetSetUp(_config.IpAddress, _config.Port); _timeout = new TimeOut("ModbusTCPClientHanderTask", _config.TimeOut, _log); _timeRead = new Timer.Timer(_config.PollingTime); _client = new ModbusTCPClient(_setup, _timeout, _log); //获取点数据 _workbook = XmlSerialiaztion.XmlDeserial <XMLWorkbook>(_config.SignalListFilePath, _log); _points = PointsCollcetCreate.Create(_workbook, _log); //点数据注册 PointsRegister.Register(ref _points, _log); _log.NormalLog(string.Format("ModbusTCPClientHanderTask:Initing=>Inited ")); return(true); } catch (Exception e) { _log.ErrorLog(string.Format("ModbusTCPClientHanderTask Init fail:{0}", e.Message)); return(false); } }
public FreedomServerTask(string taskName, ILog log, TimeOut timeOut, EthernetSetUp setup) { TaskName = taskName; Log = log; InitLevel = 4; TimeOut = timeOut; _freedomServer = new FreedomServer(setup, TimeOut, Log); }
public FreedomClient(EthernetSetUp ethernetSetUp, TimeOut timeOut, ILog log) { _ethernetSetUp = ethernetSetUp; _timeOut = timeOut; _log = log; _driverType = DriverType.Ethernet; _subSocketArgFlag = false; }
public TCPServerFactory(EthernetSetUp setUp, TimeOut timeOut, ILog log, int savleId, int maxConnect, SocketServerType ssType = SocketServerType.SaeaServer) { _setUp = setUp; _timeOut = timeOut; _log = log; _savleId = savleId; _maxConnect = maxConnect; _ssType = ssType; }
/// <summary> /// 自定义服务实例化 /// </summary> /// <param name="log">消息记录</param> /// <param name="timeOut">超时时间</param> /// <param name="type">socket服务格式:Apm,SAEA等</param> public FreedomServer(EthernetSetUp setUp, TimeOut timeOut, ILog log, SocketServerType type = SocketServerType.SaeaServer) { _log = log; _timeOut = timeOut; _socketServerType = type; _ipString = setUp.IPAddress; _port = setUp.PortNumber; _subscribeGroup = new List <SubscribeItem>(); }
public S7CommClient(EthernetSetUp ethernetSetUp, TimeOut timeOut, ILog log, int slotNo) { _ethernetSetUp = ethernetSetUp; _timeOut = timeOut; _log = log; _slotNo = slotNo; _driverType = DriverType.Ethernet; _handler = 0; }
/// <summary> /// ModbusTCP服务实例化 /// </summary> /// <param name="log">消息记录</param> /// <param name="timeOut">超时时间</param> /// <param name="maxConnect">最大连接数</param> /// <param name="salveId">地址码</param> /// <param name="type">socket服务格式:Apm,SAEA等</param> public ModbusTCPServer(EthernetSetUp setUp, TimeOut timeOut, ILog log, int maxConnect, int salveId, SocketServerType type = SocketServerType.SaeaServer) { _log = log; _timeOut = timeOut; _maxConnect = maxConnect; _salveId = salveId; _socketServerType = type; _ipString = setUp.IPAddress; _port = setUp.PortNumber; }
public override void Dispose() { if (_socket != null) { _socket.Shutdown(SocketShutdown.Both); _socket.Close(); } _socket = null; _ethernetSetUp = null; IsConnect = false; }
public FreedomClientAsync(EthernetSetUp ethernetSetUp, TimeOut timeOut, ILog log) { _ethernetSetUp = ethernetSetUp; _timeOut = timeOut; _log = log; _driverType = DriverType.Ethernet; _socketArg = new SocketAsyncEventArgs(); _socketArg.Completed += _socketArg_Completed; _bufferPool = new BufferMangment(_readCacheSize); _subSocketArgFlag = false; }
public override bool BuildServer() { if (_config.IpAddress == "") { _log.ErrorLog("BuildClient:IpAddres is null!!"); return(false); } var setup = new EthernetSetUp(_config.IpAddress, _config.Port); var timeout = new TimeOut(_taskName, _config.TimeOut, _log); var factory = new TCPServerFactory(setup, timeout, _log, _config.SalveId, _config.MaxConnect); _serverTask.Server = factory.CreateServer(_serverName); return(base.BuildServer()); }
static void Main(string[] args) { ILog log = new DefaultLog("FreedomServer"); PointMapping <bool> boolMaping = PointMapping <bool> .GetInstance(log); PointMapping <byte> byteMaping = PointMapping <byte> .GetInstance(log); PointMapping <ushort> ushortMaping = PointMapping <ushort> .GetInstance(log); PointMapping <short> shortMaping = PointMapping <short> .GetInstance(log); PointMapping <int> intMaping = PointMapping <int> .GetInstance(log); PointMapping <uint> uintMaping = PointMapping <uint> .GetInstance(log); PointMapping <float> floatMaping = PointMapping <float> .GetInstance(log); for (int i = 0; i < 1000; i++) { var bpoint = new VirtulPoint <bool>(string.Concat("boolSignal", i), DataServer.ValueType.Bool, new bool[] { true }); boolMaping.Register(bpoint.Name, bpoint); var bypoint = new VirtulPoint <byte>(string.Concat("byteSignal", i), DataServer.ValueType.Byte, new byte[] { 10 }); byteMaping.Register(bypoint.Name, bypoint); var ushortpoint = new VirtulPoint <ushort>(string.Concat("ushortSignal", i), DataServer.ValueType.UInt16, new ushort[] { Convert.ToUInt16(i) }); ushortMaping.Register(ushortpoint.Name, ushortpoint); var shortpoint = new VirtulPoint <short>(string.Concat("shortSignal", i), DataServer.ValueType.Int16, new short[] { Convert.ToInt16(i) }); shortMaping.Register(shortpoint.Name, shortpoint); var intpoint = new VirtulPoint <int>(string.Concat("intSignal", i), DataServer.ValueType.Int32, new int[] { i }); intMaping.Register(intpoint.Name, intpoint); var uintpoint = new VirtulPoint <uint>(string.Concat("uintSignal", i), DataServer.ValueType.UInt32, new uint[] { Convert.ToUInt32(i) }); uintMaping.Register(uintpoint.Name, uintpoint); } EthernetSetUp setup = new EthernetSetUp("127.0.0.1", 9527); TimeOut timeout = new TimeOut("FreedomeServer", 1000, log); FreedomDrivers.FreedomServer fs = new FreedomDrivers.FreedomServer(setup, timeout, log); if (fs.Init()) { fs.Start(); } Console.ReadKey(); }
private void init() { //数据配置 pointMetaData = new List <PointMetadata>(); //Meu窗口配置 searchWin = new SearchWindow() { SignalDisplayList = signalList, ClientAsync = clientAsync }; connectWindow = new ConnectWindow(); SignalMeItem.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(signalMeItemMouseLeftButtonDown), true); ConnectMeItem.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(ConnectMeItemMouseLeftButtonDown), true); ///连接到服务端配置 EthernetSetUp setUp = new EthernetSetUp("127.0.0.1", 9527); ILog log = new DefaultLog("SignalMonitor"); TimeOut timeOut = new TimeOut("SignalMonitor", 1000, log); clientAsync = new FreedomClientAsync(setUp, timeOut, log); //读服务器元数据 clientAsync.AsyncReadMetaData += asyncReadMetaData; //订阅client操作事件 clientAsync.AsyncReadOrSubsEvent += asyncReadOrSubsEvent; clientAsync.AsyncWriteEvent += ayncWriteEvent; clientAsync.DisconnectEvent += disconnectEvent; //断线重连事件 reTime = new System.Timers.Timer(3000); reTime.Elapsed += ReTime_Elapsed; if (clientAsync.Connect()) { clientAsync.ReadMetaData(); } }
private bool setUp() { //bool flag; _configs = ReaderXMLUtil.ReadXMLConfig <TaskConfig>(_configFath, ConfigUtilly.ReadConfig, _nodeElement, _handler); if (_configs != null) { _log.NormalLog(string.Format("{0}:Down=>Creating", "SetUp()")); //创建外部task var taskFactory = new ts.TaskFactory(_configFath); //task类型配置 foreach (var config in _configs) { ILog log = new DefaultLog(config.TaskName) { Handle = LogHandle.debug, ByteSteamLogSwicth = true }; //根据task类型配置创建具体的task列表 var tasks = taskFactory.CreateTasks(config, log); foreach (var task in tasks) { if (task != null) { task.InitLevel = config.InitLevel; _log.NormalLog(string.Format("{0}:Task<{1}>,Creating=>Created", "SetUp()", config.TaskName)); addTask(task); } } } //创建内部Task //自定义协议,用于信号监控及界面通讯 string freeTaskName = "FreedomServerTaskHandler"; ILog freelog = new DefaultLog(freeTaskName); TimeOut freeTimeout = new TimeOut(freeTaskName, 1000, freelog); EthernetSetUp freeSetup = new EthernetSetUp("127.0.0.1", 9527); FreedomServerTask freeServerTask = new FreedomServerTask(freeTaskName, freelog, freeTimeout, freeSetup); _log.NormalLog(string.Format("{0}:Task<{1}>,Creating=>Created", "SetUp()", freeServerTask.TaskName)); addTask(freeServerTask); sortTasks(); foreach (var t in _tasks) { ChangInitLevel(t.InitLevel); if (t.OnInit()) { continue; } else { _log.ErrorLog(string.Format("Task<{0}> Inited failed!", t.TaskName)); return(false); } } } else { _log.ErrorLog("Tasks config Error!"); return(false); } return(true); }