0

我目前面临一个与 SMSlib for .NET 库相关的问题(您可以在http://www.smslib.org/下载它)顺便说一句,我使用了 SendMessage 示例(您可以在 ...\Examples\SendMessage 中找到它)在库中,并尝试使用 VS2012 编译和运行它......它工作正常,但是当我在添加一点代码以重新启动服务后再次尝试重新启动服务时它从未成功......

您知道如何使服务正确重启吗?

顺便说一句,部分代码如下:

    try
        {
            Console.WriteLine("Example: Read messages from a serial gsm modem.");
            Console.WriteLine(Library.getLibraryDescription());
            Console.WriteLine("Version: " + Library.getLibraryVersion());

            // Start the COM listening thread.
            new Thread(new ThreadStart(com1.Run)).Start();

            // Lets set some callbacks.
            srv.setInboundMessageNotification(new InboundNotification());
            srv.setCallNotification(new CallNotification());
            srv.setGatewayStatusNotification(new GatewayStatusNotification());

            // Create the Gateway representing the serial GSM modem.
            // Due to the Comm2IP bridge, in SMSLib for .NET all modems are considered IP modems.
            IPModemGateway gateway = new IPModemGateway("modem.com14", "127.0.0.1", 12000, "Huawei","E173");
            gateway.setIpProtocol(ModemGateway.IPProtocols.BINARY);

            // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
            gateway.setProtocol(AGateway.Protocols.PDU);

            // Do we want the Gateway to be used for Inbound messages?
            gateway.setInbound(true);

            // Do we want the Gateway to be used for Outbound messages?
            gateway.setOutbound(true);



            // Add the Gateway to the Service object.
            srv.addGateway(gateway);

            // Similarly, you may define as many Gateway objects, representing
            // various GSM modems, add them in the Service object and control all of them.

            // Start! (i.e. connect to all defined Gateways)
            srv.startService();

            // Printout some general information about the modem.
            Console.WriteLine();
            Console.WriteLine("Modem Information:");
            Console.WriteLine("  Manufacturer: " + gateway.getManufacturer());
            Console.WriteLine("  Model: " + gateway.getModel());
            Console.WriteLine("  Serial No: " + gateway.getSerialNo());
            Console.WriteLine("  SIM IMSI: " + gateway.getImsi());
            Console.WriteLine("  Signal Level: " + gateway.getSignalLevel() + "dBm");
            Console.WriteLine("  Battery Level: " + gateway.getBatteryLevel() + "%");
            Console.WriteLine();

            // Send one message.
            // Remember to change the recipient!
            OutboundMessage msg = new OutboundMessage("0952998989", "Hello from SMSLib for .NET");
            srv.sendMessage(msg);
            Console.WriteLine(msg);



            Console.WriteLine("Press <ENTER> to terminate...");
            Console.In.ReadLine();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Console.WriteLine(e.StackTrace);
        }
        finally
        {
            com1.Stop();
            srv.stopService();

            // Start! (i.e. connect to all defined Gateways)
            srv.startService();
            new Thread(new ThreadStart(com1.Run)).Start();
        }
4

1 回答 1

0

com1.Stop();在您完全完成启动/停止服务之前,您不应该打电话。让听众保持活跃。

例如

finally
{
  srv.stopService();
  srv.startService();
  srv.stopService();
  srv.startService();
  srv.stopService();
  srv.startService();
  srv.stopService();
  srv.startService();
  srv.stopService();
  // ... and finally ...
  com1.Stop();
}
于 2014-01-04T14:09:49.343 回答