예제 #1
0
#pragma warning disable IDE0060 // Remove unused parameter
        static async Task Main(string[] args)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            Console.Title = $"{Globals.App.Name} {Globals.App.Version}";
            await Task.Delay(1);

            // C:\ProgramData\Rowa\Protocol\ProLog3Server\ProLog3Server
            // Log und WWi
            using var rowaLogProxy       = new RowaLogProxy(Globals.App.Name, false);
            using var TableCommunication = new Table.ImageProcessingCommunication(4711)
                                           .DoRun();

            TableCommunication.OnConnect.Add((communication, socket) =>
            {
                Console.WriteLine($"Table new connection {socket.RemoteEndPoint.ToString()}".LogInfo());
            });
            TableCommunication.OnDisconnect.Add((communication, socket) =>
            {
                Console.WriteLine($"Table removed connection {socket.RemoteEndPoint.ToString()}".LogInfo());
            });

            TableCommunication.OnReceived.Add(async(communication, message) =>
            {
                Console.WriteLine($"Table recevied {message?.GetType().Name ?? "unkown"}".LogInfo());
                switch (message)
                {
                case Table.Messages.SetLightsRequest setLights:
                    communication.Send(new Table.Messages.SetLightsResponse().SetStateOk());
                    break;

                case Table.Messages.TurnRelativeRequest turnRelative:
                    int wait = 2;
                    if (turnRelative.Velocity < 100)
                    {
                        communication.Send(new Table.Messages.TurnRelativeResponse().SetStateError($"Velocity {turnRelative.Velocity} less 100"));
                        return;
                    }

                    Console.WriteLine($"TurnRelativ start and wait={wait} seconds".LogInfo());
                    await Task.Delay(TimeSpan.FromSeconds(wait));
                    Console.WriteLine($"TurnRelativ ready".LogInfo());
                    communication.Send(new Table.Messages.TurnRelativeResponse().SetStateOk());
                    break;

                default:
                    Console.WriteLine($"unhandled message {message?.GetType().Name ?? "unkown"}".LogError());
                    break;
                }
            });

            Console.WriteLine("End with return");
            Console.ReadLine();
            Console.WriteLine($"{Globals.App.Name} finshed".LogInfo());
        }
예제 #2
0
 public static async Task <int> SetLightsAsync()
 {
     #region setlights
     using var TableCommunication = new Table.ImageProcessingCommunication(6002, "127.0.0.1").DoRun();
     if (!await TableCommunication.WaitConnectedAsync(TimeSpan.FromSeconds(2)))
     {
         Console.WriteLine("Not connected");
         return(0);
     }
     Console.WriteLine("Connected");
     if (await TableCommunication.SendAndWaitAsync <Table.Messages.SetLightsResponse>
             (new Table.Messages.SetLightsRequest
     {
         Top = true,
         Bottom = true,
         SideLeft = false,
         SideMiddle = false,
         SideRight = false
     }, TimeSpan.FromSeconds(1)) is var result && result.IsMessageOk())
     {
         Console.WriteLine("Message Ok");
     }
예제 #3
0
        public async Task VoidCommunication()
        {
            #region createcommunication
            var port = 4711;
            var host = "127.0.0.1";
            // host is optional,
            // if host is null or empty the communication is running as a server
            using var Position3DCommunication = new Position3D.ImageProcessingCommunication(port, host);
            using var Size3DCommunication     = new Size3D.ImageProcessingCommunication(port, host);
            using var TableCommunication      = new Table.ImageProcessingCommunication(port, host);
            using var OcrCommunication        = new Ocr.ImageProcessingCommunication(port, host);
            #endregion

            {
                #region sendmessage
                // Communication.Send(message)
                TableCommunication.Send(new Table.Messages.TurnRelativeRequest(0, 100.0));
                #endregion
            }

            {
                #region receiveevent
                var eventHandler = TableCommunication.OnReceived.Add(
                    (communication, message) =>
                {
                    switch (message)
                    {
                    case Table.Messages.TurnRelativeRequest turnRelative:
                        communication.Send(new Table.Messages.TurnRelativeResponse().SetStateOk());
                        break;

                    default:
                        Console.WriteLine($"unhandled message {message?.GetType().Name ?? "unkown"}".LogError());
                        break;
                    }
                });


                // wenn der Handler nicht mehr benötigt wird entfernen
                TableCommunication.OnReceived.Remove(eventHandler);
                #endregion
            }

            {
                #region receivemessage
                await TableCommunication.WaitAsync <Table.Messages.TurnRelativeResponse>();

                // mit timeout oder CancellationToken
                var result = await TableCommunication.WaitAsync <Table.Messages.TurnRelativeResponse>(TimeSpan.FromSeconds(1));

                // A. Prüfung der Antwort
                if (result.IsOk())
                {
                    "Es ist eine Antwort vorhanden".LogInfo();
                    // in message steht die response message
                    if (result.Message.IsOk())
                    {
                        "Die Antwort vom Server is auch Ok".LogInfo();
                    }
                    // Hier die Langform und .....
                    if (result.Message.Result.State == CommunicationMessageResultState.Ok)
                    {
                        "Die Antwort vom Server is auch Ok".LogInfo();
                    }
                }
                else
                {
                    "Timeout".LogInfo();
                }

                // B. oder kurz und die Fehler stehen im log
                if (result.IsMessageOk())
                {
                    "Die Antwort vom Server is auch Ok".LogInfo();
                }
                #endregion
            }

            {
                #region receivemessagewithsend
                var result1 = await TableCommunication.SendAndWaitAsync <Table.Messages.TurnRelativeResponse>
                                  (new Table.Messages.TurnRelativeRequest(0, 100.0), TimeSpan.FromSeconds(1));

                if (result1.IsMessageOk())
                {
                    // everthing is ok
                }
                ;

                if (await TableCommunication.SendAndWaitAsync <Table.Messages.TurnRelativeResponse>
                        (new Table.Messages.TurnRelativeRequest(0, 100.0), TimeSpan.FromSeconds(1))
                    is var result2 && result2.IsMessageOk())
                {
                    // everthing is ok
                }
                ;
                #endregion
            }
            {
                #region receivemessageproblem
                TableCommunication.Send(new Table.Messages.TurnRelativeRequest(0, 100.0));
                // hier verbraten wir Zeit
                var result = await TableCommunication.WaitAsync <Table.Messages.TurnRelativeResponse>(TimeSpan.FromSeconds(1));

                // Jetzt kann es sein das die Nachricht vor dem Aufruf
                // von WaitAsync schon da ist und WaitAsync gibt result.Ok mit false zurück
                #endregion
            }
            {
                #region receivemessagemark
                var mark = TableCommunication.Send(new Table.Messages.TurnRelativeRequest(0, 100.0));
                // hier verbraten wir Zeit
                var result = await mark.WaitAsync <Table.Messages.TurnRelativeResponse>(TimeSpan.FromSeconds(1));

                if (result.IsOk())
                {
                    if (result.Message.IsOk())
                    {
                    }
                    else
                    {
                    }
                }
                else
                {
                }
                #endregion
            }

            {
                #region icommunicationmessageresultsend
                // Message erzeugen
                var message = new Table.Messages.TurnRelativeResponse { /* und füllen */
                };

                // Result setzen
                // ok Meldungen
                message.Result.State = CommunicationMessageResultState.Ok;
                message.Result.Messages.Add("Mit Message");
                message.SetStateOk();
                message.SetStateOk("Mit Message");

                // FehlerMeldungen
                message.Result.State = CommunicationMessageResultState.Error;
                message.SetStateError();
                message.SetStateError("Mit Message");
                message.SetStateError(new Exception());
                message.SetStateSystemNotReady();
                message.SetStateSystemNotReady("Mit Message");

                // Oder durch boolschen Wert
                message.SetState(true);  // => message.SetStateOk();
                message.SetState(false); // => message.SetStateError();
                #endregion
            }

            {
                #region icommunicationmessageresultreceive
                // Message erzeugen
                var message = new Table.Messages.TurnRelativeResponse { /* und füllen */
                };

                // Message abfragen
                if (message.Result.State == CommunicationMessageResultState.Ok)
                {
                }
                if (message.IsOk())
                {
                }

                if (message.Result.State == CommunicationMessageResultState.Error)
                {
                }
                if (message.IsError())
                {
                }

                var messages = message.Result.Messages; // Hier stehen die Fehlermeldungen drin.
                #endregion
            }
        }
예제 #4
0
#pragma warning disable IDE0060 // Remove unused parameter
        static async Task Main(string[] args)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            Console.Title = $"{Globals.App.Name} {Globals.App.Version}";
            // C:\ProgramData\Rowa\Protocol\EagClient\EagClient
            // Log und WWi
            using var rowaLogProxy       = new RowaLogProxy(Globals.App.Name, true);
            using var TableCommunication = new Table.ImageProcessingCommunication(6002, "127.0.0.1")
                                           .DoRun();

            TableCommunication.OnConnect.Add((communication, socket) =>
            {
                Console.WriteLine($"Table new connection {socket.RemoteEndPoint.ToString()}".LogInfo());
            });
            TableCommunication.OnDisconnect.Add((communication, socket) =>
            {
                Console.WriteLine($"Table removed connection {socket.RemoteEndPoint.ToString()}".LogInfo());
            });

            TableCommunication.OnReceived.Add((communication, message) =>
            {
                Console.WriteLine($"Table recevied {message?.GetType().Name ?? "unkown"}".LogInfo());
            });

            Console.WriteLine("Make your selection\r\nreturn => ende\r\ns or S => setlights\r\nt or T => turntable\r\n");
            bool running = true;

            while (running)
            {
                while (!Console.KeyAvailable)
                {
                    await Task.Delay(100);
                }
                var key = Console.ReadKey(true);
                Console.WriteLine();
                var elapsedTime = Stopwatch.StartNew();
                switch (key.KeyChar)
                {
                case '\r':
                case 'c':
                case 'C':
                    running = false;
                    break;

                case 's':
                {
                    var result = await TableCommunication.Send(new Table.Messages.SetLightsRequest
                        {
                            Top        = false,
                            Bottom     = false,
                            SideLeft   = false,
                            SideMiddle = false,
                            SideRight  = false
                        }).WaitAsync <Table.Messages.SetLightsResponse>();

                    if (result.IsOk())         // No Timeout
                    {
                        if (result.Message.IsOk())
                        {
                            Console.WriteLine("SetLight Ok".LogInfo());
                        }
                        else
                        {
                            Console.WriteLine("SetLight Server Error".LogError());
                        }
                    }
                    else
                    {
                        Console.WriteLine("SetLight Client TimeOut".LogError());
                    }
                }
                break;

                case 'S':
                {
                    if (await TableCommunication.SendAndWaitAsync <Table.Messages.SetLightsResponse>(new Table.Messages.SetLightsRequest
                        {
                            Top = true,
                            Bottom = true,
                            SideLeft = true,
                            SideMiddle = true,
                            SideRight = true
                        }) is var result && result.IsMessageOk())
                    {
                        Console.WriteLine("message Ok");
                    }