示例#1
0
        static void UpdateAllStatus(TcpClient client, NetworkStream stream, bool showVerboseMessage)
        {
            TCPDigitalIOTranslator translator = new TCPDigitalIOTranslator(showVerboseMessage);
            StaticDIO staticDIO = new StaticDIO(showVerboseMessage);
            int       command   = 0;

            Console.WriteLine("*** Update All Status ***");
            staticDIO.UpdateStaticDI();
            command = translator.getTCPCommand(staticDIO.ProjectNum, staticDIO.RobotNum, (byte)TCPDigitalIOTranslator.DIOCommand.Project_GetStatus);
            Console.WriteLine("*** command: {0}", command);
            SendTCPAndUpdateDO(client, stream, command, showVerboseMessage);

            command = translator.getTCPCommand(staticDIO.ProjectNum, (byte)TCPDigitalIOTranslator.RobotNum.R1, (byte)TCPDigitalIOTranslator.DIOCommand.Robot_GetStatus);
            Console.WriteLine("*** command: {0}", command);
            SendTCPAndUpdateDO(client, stream, command, showVerboseMessage);

            command = translator.getTCPCommand(staticDIO.ProjectNum, (byte)TCPDigitalIOTranslator.RobotNum.R2, (byte)TCPDigitalIOTranslator.DIOCommand.Robot_GetStatus);
            Console.WriteLine("*** command: {0}", command);
            SendTCPAndUpdateDO(client, stream, command, showVerboseMessage);

            command = translator.getTCPCommand(staticDIO.ProjectNum, (byte)TCPDigitalIOTranslator.RobotNum.R3, (byte)TCPDigitalIOTranslator.DIOCommand.Robot_GetStatus);
            Console.WriteLine("*** command: {0}", command);
            SendTCPAndUpdateDO(client, stream, command, showVerboseMessage);

            command = translator.getTCPCommand(staticDIO.ProjectNum, (byte)TCPDigitalIOTranslator.RobotNum.R4, (byte)TCPDigitalIOTranslator.DIOCommand.Robot_GetStatus);
            Console.WriteLine("*** command: {0}", command);
            SendTCPAndUpdateDO(client, stream, command, showVerboseMessage);
        }
示例#2
0
        static void SendTCPAndUpdateDO(TcpClient client, NetworkStream stream, int message_int, bool showVerboseMessage)
        {
            TCPDigitalIOTranslator translator = new TCPDigitalIOTranslator(showVerboseMessage);

            //StaticDIO staticDIO = new StaticDIO(showVerboseMessage);
            byte[] responsebyte = { 0, 0, 0, 0 };

            responsebyte = ConnectAndSend(client, stream, message_int);
            Console.WriteLine("TCP Response: {0:X}.", translator.getDOfromTCPResponse(responsebyte));
            Console.WriteLine("TCP Response: {0}.", translator.getStatusStringfromTCPResponse(responsebyte));

            //staticDIO.UpdateStaticDO(translator.getDOfromTCPResponse(responsebyte));
        }
示例#3
0
        static void Main(string[] args)
        {
            String    IP     = "127.0.0.1";
            Int32     port   = 1700;
            TcpClient client = new TcpClient(IP, port);

            NetworkStream stream = client.GetStream();

            stream.ReadTimeout  = 2000;
            stream.WriteTimeout = 2000;

            int message_int = 0;

            bool manualInput        = true;
            bool showVerboseMessage = false;

            TCPDigitalIOTranslator translator = new TCPDigitalIOTranslator(showVerboseMessage);
            StaticDIO staticDIO = new StaticDIO(showVerboseMessage);

            //byte[] message_test = {}
            byte projectNum = 2;
            byte robotNum   = 0;
            byte command    = 1;

            Console.WriteLine("{0}", translator.getTCPCommand(projectNum, robotNum, command));
            byte[] response_test  = { 0, 202, 0, 6 };
            string yourByteString = Convert.ToString(translator.getDOfromTCPResponse(response_test), 2).PadLeft(16, '0');

            Console.WriteLine("{0:X}", translator.getDOfromTCPResponse(response_test));
            Console.WriteLine(yourByteString);
            //Thread.Sleep(2000000);

            while (true)
            {
                if (manualInput)
                {
                    Console.WriteLine("");
                    Console.Write("Value to send: ");
                    message_int = Convert.ToInt32(Console.ReadLine());
                }
                else
                {
                    staticDIO.UpdateStaticDI();
                    Console.WriteLine("TCP command: {0}. ProjectNum: {1}. RobotNum: {2}. Command: {3}", translator.getTCPCommand(staticDIO.ProjectNum, staticDIO.RobotNum, staticDIO.Command), staticDIO.ProjectNum, staticDIO.RobotNum, staticDIO.Command);
                    message_int = translator.getTCPCommand(staticDIO.ProjectNum, staticDIO.RobotNum, staticDIO.Command);
                }

                if (CheckMessageValidity(message_int))
                {
                    Console.WriteLine("Message is valid.");
                    if (staticDIO.Execute == 1 || manualInput)
                    {
                        SendTCPAndUpdateDO(client, stream, message_int, showVerboseMessage);
                    }
                }
                else
                {
                    Console.WriteLine("Message is invalid.");
                }

                //UpdateAllStatus(client, showVerboseMessage);
                Thread.Sleep(200);
                Console.WriteLine("");
            }
        }