我正在尝试编写自己的ADS服务器(使用.NET 5)。
下面是我的代码:
public class SampleServer :AdsServer
{
private IServerLogger _serverLogger;
public Server(ushort port, string portName, ILogger logger) : base(port, portName,
logger)
{
_serverLogger = new ServerLogger(logger);
}
}
}
class Program
{
private static ILogger<Server> _logger;
static void Main(string[] args)
{
ushort port = 25000;
string portName = "TestAdsServer";
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
});
_logger = loggerFactory.CreateLogger<Server>();
Server server = new Server(port, portName, _logger);
server.ServerConnectionStateChanged += ConnectionStatusChanged;
Console.WriteLine("Press enter to close the servers ...");
Console.ReadLine();
server.Disconnect();
}
private static void ConnectionStatusChanged(object sender,
ServerConnectionStateChangedEventArgs args)
{
if (args.State == ServerConnectionState.Connected)
_logger.LogInformation("Server is connected to port" + 25000);
else if (args.State == ServerConnectionState.Disconnected)
_logger.LogInformation("Server is disconnected");
}
}
我还写了一个Twincat 3 ADS客户端:
1.为什么我看不到ServerConnectionChange状态?
1.为什么客户端无法在广告服务器中写入数据?
1条答案
按热度按时间mrwjdhj31#
也许我是有点晚了,…[![AdsServerClass][1]][1]