Coder Social home page Coder Social logo

hbjorgo / atlib Goto Github PK

View Code? Open in Web Editor NEW
48.0 3.0 20.0 375 KB

ATLib is a C# library that makes it easy to communicate with modems.

License: MIT License

C# 99.35% Smalltalk 0.19% PowerShell 0.47%
at atcommand atcommands sms gsm gsm-modem c-sharp hayes modem

atlib's Introduction

ATLib

CI Nuget Nuget

ATLib is a C# AT command library that abstracts away the commands and makes it easy to communicate with modems.

Hayes command set (commonly known as AT commands) is a command set frequently used in modems. Read more about it at Wikipedia.

Feedback is very much welcome and please request features ๐Ÿ™‚

HeboTech.GsmApi is a REST API wrapping this library.

Supported commands:

  • Send SMS in PDU format (GSM 7 bit or UCS2 encoding)
  • Send concatenated SMS (message that spans over multiple SMSs) in PDU format (GSM 7 bit or UCS2 encoding)
  • SMS supports emojies
  • List SMSs
  • Read SMS (PDU format (GSM 7 bit or UCS2 encoding))
  • Delete SMS
  • Dial number
  • Answer incoming call
  • Hang up call
  • Get SIM status
  • Enter SIM PIN
  • Get remaining PIN & PUK attempts
  • Get product information
  • Get battery status
  • Get signal strength
  • Get / set date and time
  • Disable echo
  • Send USSD code
  • Get / set character set
  • Get IMSI
  • Some modems may also support modem specific commands

Events

  • Incoming call
  • Missed call
  • Call started
  • Call ended
  • SMS received
  • Error received
  • USSD response received
  • Generic event

Supported modems:

  • Adafruit FONA 3G (based on SIMCOM SIM5320 chipset)
  • D-Link DWM-222 (based on Qualcomm MDM9225 chipset)
  • TP-LINK MA260 (based on a Qualcomm chipset)
  • Cinterion MC55i
  • Other modems may work using one of the implementations above. You can add your own implementation using the existing functionality as base.

Other

  • Debug functionality that lets you intercept incoming and outgoing data

Usage

Install as NuGet package

dotnet add package HeboTech.ATLib

Using a serial port to communicate with a modem is easy:

// Set up serial port
using SerialPort serialPort = new SerialPort(args[0], 9600, Parity.None, 8, StopBits.One)
{
    Handshake = Handshake.RequestToSend
};
serialPort.Open();

// Create AT channel
using AtChannel atChannel = AtChannel.Create(serialPort.BaseStream);

// Create the modem
using IModem modem = new Fona3G(atChannel);

// Open AT channel
atChannel.Open();

// Configure modem with required settings before PIN
var requiredSettingsBeforePin = await modem.SetRequiredSettingsBeforePinAsync();

// Get SIM status
var simStatus = await modem.GetSimStatusAsync();
Console.WriteLine($"SIM Status: {simStatus}");

if (simStatus == SimStatus.SIM_PIN)
{
    var simPinStatus = await modem.EnterSimPinAsync(new PersonalIdentificationNumber("<PIN>"));
    Console.WriteLine($"SIM PIN Status: {simPinStatus}");
}

// Configure modem with required settings after PIN
var requiredSettingsAfterPin = await modem.SetRequiredSettingsAfterPinAsync();

// Send SMS to the specified number
var smsReference = await modem.SendSmsAsync(new PhoneNumber("123456789"), "Hello ATLib!");
Console.WriteLine($"SMS Reference: {smsReference}");

Because it relies on a stream, you can even control a modem over a network! Either use a network attached modem, or forward a modem serial port to a network port.

For more examples, check out the TestConsole project in the code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.