https://github.com/hbjorgo/atlib
ATLib is a C# library that makes it easy to communicate with modems.
https://github.com/hbjorgo/atlib
at atcommand atcommands c-sharp gsm gsm-modem hayes modem sms
Last synced: 3 months ago
JSON representation
ATLib is a C# library that makes it easy to communicate with modems.
- Host: GitHub
- URL: https://github.com/hbjorgo/atlib
- Owner: hbjorgo
- License: mit
- Created: 2018-06-15T10:42:57.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-12-21T10:33:36.000Z (10 months ago)
- Last Synced: 2025-04-05T02:02:37.148Z (6 months ago)
- Topics: at, atcommand, atcommands, c-sharp, gsm, gsm-modem, hayes, modem, sms
- Language: C#
- Homepage:
- Size: 494 KB
- Stars: 54
- Watchers: 3
- Forks: 20
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ATLib
[](https://github.com/hbjorgo/ATLib)
[](https://www.nuget.org/packages/HeboTech.ATLib)
[](https://www.nuget.org/packages/HeboTech.ATLib)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](https://en.wikipedia.org/wiki/Hayes_command_set).
Feedback is very much welcome and please request features 🙂
## 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
- Get SMS Status Report (delivery status)
- 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
- SMS Status Report 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
```shell
dotnet add package HeboTech.ATLib
```Using a serial port to communicate with a modem is easy:
```csharp
using HeboTech.ATLib.Messaging;
using HeboTech.ATLib.Misc;
using HeboTech.ATLib.Modems;
using HeboTech.ATLib.Modems.Adafruit;
using HeboTech.ATLib.Numbering;
using HeboTech.ATLib.Parsing;
using System;
using System.IO.Ports;
using System.Threading.Tasks;namespace HeboTech.ATLib.TestConsole
{
public class GetStartedExample
{
public static async Task RunAsync(string portName, int baudRate, string pin, string recepientPhoneNumber)
{
// Set up serial port
using SerialPort serialPort = new SerialPort(portName, baudRate, 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);// Listen to incoming SMSs
modem.SmsReceived += (sender, args) =>
{
Console.WriteLine($"SMS received: {args.SmsDeliver}");
};// Listen to incoming SMSs stored in memory
modem.SmsStorageReferenceReceived += (sender, args) =>
{
Console.WriteLine($"SMS received. Index {args.Index} at storage location {args.Storage}");
};// 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}");// Check if SIM needs PIN
if (simStatus.Result == 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();// Read SMS at index 1
var sms = await modem.ReadSmsAsync(1);
if (sms.Success)
Console.WriteLine(sms.Result);// Send SMS to the specified number
PhoneNumber phoneNumber = PhoneNumberFactory.CreateCommonIsdn(recepientPhoneNumber);
string message = "Hello ATLib!";
var smsReferences = await modem.SendSmsAsync(new SmsSubmitRequest(phoneNumber, message));
foreach (var smsReference in smsReferences)
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.