Reply() 공개 메소드

public Reply ( byte query ) : int
query byte
리턴 int
예제 #1
0
파일: Main.cs 프로젝트: mk8/modbus-sharp
        public static int ServerTest(string listenAddress, int port, bool debug)
        {
            ModbusCore core = new ModbusCore (listenAddress, port);
            core.Debug = debug;

            if (core.MappingNew (500, 500, 500, 500)) {
                Console.WriteLine ("Failed to allocate the mapping.");
                return -1;
            }

            // Initialization for testing
            for (int i = 0; i < 500; ++i) {
                core.RegisterRWSigned[i] = (short)(1000+i);
                core.RegisterInputSigned[i] = (short)i;
            }

            core.ListenTcp (1);
            while (true) {
                core.AcceptTcp ();

                while (true) {
                    byte[] query;
                    try {
                        query = core.Receive ();
                        core.Reply (query);
                    } catch {
                        // Connection closed by the client or error
                        break;
                    }
                }
            }

            core.MappingDispose ();
            core.Close ();
            core.Dispose ();

            return 0;
        }