Exemplo n.º 1
0
        private void button12_Click(object sender, EventArgs e)
        {
            pipeSocket?.Socket?.Close( );
            pipeSocket  = new PipeSocket("127.0.0.1", 102);
            siemensS[0] = new SiemensS7Net(SiemensPLCS.S1200);
            siemensS[1] = new SiemensS7Net(SiemensPLCS.S1200);
            siemensS[2] = new SiemensS7Net(SiemensPLCS.S1200);
            siemensS[0].SetPipeSocket(pipeSocket);
            siemensS[1].SetPipeSocket(pipeSocket);
            siemensS[2].SetPipeSocket(pipeSocket);

            thread_status     = 3;
            failed            = 0;
            thread_time_start = DateTime.Now;
            new Thread(new ParameterizedThreadStart(thread_test2))
            {
                IsBackground = true,
            }.Start("M100");
            new Thread(new ParameterizedThreadStart(thread_test2))
            {
                IsBackground = true,
            }.Start("M200");
            new Thread(new ParameterizedThreadStart(thread_test2))
            {
                IsBackground = true,
            }.Start("M300");
            button12.Enabled = false;

            timer          = new System.Windows.Forms.Timer( );
            timer.Interval = 1000;
            timer.Tick    += Timer_Tick;
            timer.Start( );
        }
Exemplo n.º 2
0
        static void Main()
        {
            var endpoint = new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), 8081);

            uv_init();

            var watch = new PrepareWatcher(() => {
                //Console.WriteLine("Prepare Watcher Called");
            });

            watch.Start();
            var server = new TcpServer((socket) => {
                clientcount++;
                socket.Stream.Write(System.Text.Encoding.ASCII.GetBytes(clientcount.ToString()), 1);
                if (clientcount > 5)
                {
                    socket.Close();
                }
                Console.WriteLine("Client Connected");
                socket.Stream.OnRead += (data) => {
                    Console.WriteLine("Data Recieved: {0}", System.Text.Encoding.ASCII.GetString(data, 0, data.Length));
                    socket.Stream.Write(data, data.Length);
                };
                //socket.OnClose += () => {
                //	Console.WriteLine("Client Disconnected");
                //};
            });

            server.Listen(endpoint);
            var client = new TcpSocket();

            client.Connect(endpoint, () => {
                client.Stream.OnRead += (data) => {
                    Console.WriteLine("Client Recieved: {0}", System.Text.Encoding.ASCII.GetString(data, 0, data.Length));
                    watch.Stop();
                    watch.Dispose();
                    client.Close();
                };
                byte[] message = System.Text.Encoding.ASCII.GetBytes("Hello World\n");
                client.Stream.Write(message, message.Length);
            });
            var pipeserver = new PipeServer((socket) => {
                clientcount++;
                socket.Stream.Write(System.Text.Encoding.ASCII.GetBytes(clientcount.ToString()), 1);
                if (clientcount > 5)
                {
                    socket.Close();
                }
                Console.WriteLine("Pipe Client Connected");
                socket.Stream.OnRead += (data) => {
                    Console.WriteLine("Pipe Data Recieved: {0}", System.Text.Encoding.ASCII.GetString(data, 0, data.Length));
                    socket.Stream.Write(data, data.Length);
                };
                //socket.OnClose += () => {
                //	Console.WriteLine("Client Disconnected");
                //};
            });

            pipeserver.Listen("libuv-csharp");
            var pipeclient = new PipeSocket();

            pipeclient.Connect("libuv-csharp", () => {
                pipeclient.Stream.OnRead += (data) => {
                    Console.WriteLine("Pipe Client Recieved: {0}", System.Text.Encoding.ASCII.GetString(data, 0, data.Length));
                    watch.Stop();
                    watch.Dispose();
                    pipeclient.Close();
                };
                byte[] message = System.Text.Encoding.ASCII.GetBytes("Hello World\n");
                pipeclient.Stream.Write(message, message.Length);
            });
            var watch2 = new PrepareWatcher(() => {
                //Console.WriteLine("Prepare Watcher 2 Called");
            });

            watch2.Start();
            var check = new CheckWatcher(() => {
                //Console.WriteLine("Check Watcher Called");
            });

            check.Start();
            var idle = new IdleWatcher(() => {
                //Console.WriteLine("Idle Watcher Called");
            });

            idle.Start();
            var after = new TimerWatcher(new TimeSpan(0, 0, 5), new TimeSpan(1, 0, 0), () => {
                //Console.WriteLine("After 5 Seconds");
            });

            after.Start();
            var every = new TimerWatcher(new TimeSpan(0, 0, 5), () => {
                //Console.WriteLine("Every 5 Seconds");
                //	after.Stop();
            });

            every.Start();
            var cp = new ChildProcess("ls");

            cp.Spawn();
            uv_run();
        }