using System; using BorgCh; using BorgCh.Comm.Modbus; public class gateway { MasterRtu rtu; SlaveTcp tcp; public gateway( String serportparams, int port ) { rtu = new MasterRtu( serportparams ); tcp = new SlaveTcp( (ushort)port ); for( int i=0; i<255; i++ ) { tcp.add_calls( i, rtu ); } } public void run() { Console.WriteLine( "looping..." ); while( true ) { System.Threading.Thread.Sleep( 1000 ); } } public static int Main( String[] args ) { String serportparams; int port = 1502; if( args.Length < 1 || args.Length > 2 ) { Console.WriteLine( "\n" + "usage:\n" + " modbusgw.exe serportspec [port]\n" + "\n" + " serportspec: portname-baudrate-databits-parity-stopbits\n" + " parity: 'N' 'E' 'O'\n" + " stopbits '1' '1.5' '2'\n" + " port: TCP port number, default is 1502.\n" + "\n" + "example:\n" + " modbusgw.exe COM1:-115200-8-N-1 1502\n" + "" ); return 1; } serportparams = args[0]; if( args.Length > 1 ) { if( !Int32.TryParse( args[1], out port ) ) { Console.WriteLine( "Port must be an integer." ); return 1; } if( port < 1 || port > 65535 ) { Console.WriteLine( "Port must be between 1 and 65535." ); return 1; } } // Logger.get_logger( "" ).set_level( LogLevel.ALL ); Logger.set_default_level( LogLevel.ALL ); gateway gw = new gateway( serportparams, port ); gw.run(); return 0; } }