Project

General

Profile

Wiki - Connect to Gateway


using MessagingToolkit.Core;
using MessagingToolkit.Core.Mobile;
using MessagingToolkit.Core.Log;
using MessagingToolkit.Core.Mobile.Message;
using MessagingToolkit.Core.Mobile.Event;

using MessagingToolkit.Pdu;
using MessagingToolkit.Pdu.Ie;
using MessagingToolkit.Pdu.WapPush;


IMobileGateway mobileGateway = MobileGatewayFactory.Default();

MobileGatewayConfiguration config = MobileGatewayConfiguration.NewInstance();

config.PortName = "COM4";
config.BaudRate = (PortBaudRate)Enum.Parse(typeof(PortBaudRate), "115200");
config.DataBits = (PortDataBits)Enum.Parse(typeof(PortDataBits), "8");

// Assign a PIN if necessary
config.Pin = "123456";
// Assign a model if you want
config.Model = "Huawei";

config.Parity = PortParity.None;
config.StopBits = PortStopBits.One;

 config.Handshake = PortHandshake.None;

// Check for the PIN status during connect
config.DisablePinCheck = false;

// Default to verbose by default
config.LogLevel = LogLevel.Verbose;

// Create the gateway for mobile
MessageGateway<IMobileGateway, MobileGatewayConfiguration> messageGateway =
    MessageGateway<IMobileGateway, MobileGatewayConfiguration>.NewInstance();
try
{    
    mobileGateway = messageGateway.Find(config);
    if (mobileGateway == null)
    {
        MessageBox.Show("Error connecting to gateway. Check the log file", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }
    MessageBox.Show("Connected to gateway successfully", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Refer to the Demo program for more details.