.net Twincat 3将数据写入AdsServer

ctehm74n  于 2023-05-19  发布在  .NET
关注(0)|答案(1)|浏览(119)

我正在尝试编写自己的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.为什么客户端无法在广告服务器中写入数据?

mrwjdhj3

mrwjdhj31#

也许我是有点晚了,…[![AdsServerClass][1]][1]

Server server = new Server(25000, "AdsServer", logger);
server.ConnectServer();

相关问题