コード例 #1
0
        public async Task CreateAndSendReciveMessage()
        {
            var cMessage = new CommunicationMessage();
            var MI10     = new MIReadOperation(10, 1);

            cMessage.AddOperation(MI10);
            cMessage.AddOperation(new MIWriteOperation(12, 1));
            var client = new PcomTcpClient(new CancellationTokenSource(), new FileLogger(new FileLoggerSettings
            {
                BytesPerLine = 16,
                FileName     = string.Empty, //Use this file to hexdump messages sent
                ShowAscii    = false,
                ShowHeader   = true,
                ShowOffset   = true
            }));

            await client.TcpClient.ConnectAsync("192.168.100.101", 20258);

            if (client.TcpClient.Connected)
            {
                var response = await client.SendAndReceive(cMessage.GetMessage());

                cMessage.ParseMessage(response);
                Assert.AreNotEqual(0, MI10.GetValue(0));
            }
            else
            {
                throw  new Exception("Not Connected");
            }
        }
コード例 #2
0
        static async Task Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("PlcName IP Port");
                Console.WriteLine("Example: PlcName 192.168.100.10 20256");
            }
            else
            {
                try
                {
                    var plc = new PcomTcpClient(new CancellationTokenSource(), null);
                    await plc.TcpClient.ConnectAsync(args[1], int.Parse(args[2]));

                    var message = new CommunicationMessage();
                    var plcName = plc.SendAndReceive(message.GetPlcName());
                    Console.WriteLine("PlcName: " + plcName);
                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Något gick fel!, Kontrollera IP och Port");
                    Console.WriteLine("Example: PlcName 192.168.100.10 20256");
                    Console.ReadLine();
                }
            }
        }