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; }