Search code examples
c#windowsusbmodemras

How to use DotRas to connect a USB 3G modem and send AT commands?


I have found DotRas a wrapper for RAS. And this is what i was able to do with it

private void btnConnect_Click(object sender, EventArgs e)
    {
        RasDevice device = RasDevice.GetDeviceByName("ZTE Proprietary USB Modem", RasDeviceType.Modem);
        if (device != null)
        {
            MessageBox.Show("Found "+device.Name.ToString()+device.DeviceType.ToString(), "hah!", MessageBoxButtons.OK);
        }
        else
        {
            MessageBox.Show("Device not found", "Error", MessageBoxButtons.OK);
        }

        this.rasPhoneBook1.Open();
        RasEntry entry = RasEntry.CreateDialUpEntry("ZTE Proprietary USB Modem", "+880000000", device);
        this.rasPhoneBook1.Entries.Add(entry);

        this.rasDialer1.EntryName = "ZTE Proprietary USB Modem";
        this.rasDialer1.PhoneBookPath = rasPhoneBook1.Path;
        this.rasDialer1.DialAsync();
    }

    private void rasDialer1_StateChanged(object sender, StateChangedEventArgs e)
    {
        MessageBox.Show(e.State.ToString(), "Dial Status", MessageBoxButtons.OK);
    }

    private void rasDialer1_DialCompleted(object sender, DialCompletedEventArgs e)
    {
        if (e.Cancelled)
        {
            MessageBox.Show("Cancelled");
        }
        else if (e.TimedOut)
        {
            MessageBox.Show("Time out");
        }
        else if (e.Error != null)
        {
            MessageBox.Show(e.Error.ToString(),"Error");
        }
        else if (e.Connected)
        {
            MessageBox.Show("Connection successful!");
        }
    }   

The code attempts to dial the modem but shows this error message:

"The remote computer did not respond. To make sure that the server can be reached,ping the remote    computer."}

The error is caght in here:

 else if (e.Error != null)
        {
            MessageBox.Show(e.Error.ToString(),"Error");
        } 

I am trying to connect a 3g modem and send and recieve SMS via the modem. How can i achieve that with DotRas? Yes I have read the API documentation and read the discussions treads in DOtRas official site but I am still lost. Any help will be hugely appreciated. Thank you.


Solution

  • From the documentation, it looks as though DotRas is just for making RAS connections. You don't need to make a RAS connection to send & receive SMS, just be registered on the network. Personally, I would write my own code for this, because it's not too complicated, but there are plenty of 3rd party libraries like gsmcomm that deal with SMS.

    For standard AT commands see TS 27.005 (sms) and 27.007 (general AT commands) from www.3gpp.org. TS 27.005, Section 3.4, deals with receiving messages.

    (added comments that seem to be useful to an answer).