Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

hbjorgo/ATLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CINugetNuget

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 atWikipedia.

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

dotnet add package HeboTech.ATLib

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

usingHeboTech.ATLib.Messaging;usingHeboTech.ATLib.Misc;usingHeboTech.ATLib.Modems;usingHeboTech.ATLib.Modems.Adafruit;usingHeboTech.ATLib.Numbering;usingHeboTech.ATLib.Parsing;usingSystem;usingSystem.IO.Ports;usingSystem.Threading.Tasks;namespaceHeboTech.ATLib.TestConsole{publicclassGetStartedExample{publicstaticasyncTaskRunAsync(stringportName,intbaudRate,stringpin,stringrecepientPhoneNumber){// Set up serial portusingSerialPortserialPort=newSerialPort(portName,baudRate,Parity.None,8,StopBits.One){Handshake=Handshake.RequestToSend};serialPort.Open();// Create AT channelusingAtChannelatChannel=AtChannel.Create(serialPort.BaseStream);// Create the modemusingIModemmodem=newFona3G(atChannel);// Listen to incoming SMSsmodem.SmsReceived+=(sender,args)=>{Console.WriteLine($"SMS received:{args.SmsDeliver}");};// Listen to incoming SMSs stored in memorymodem.SmsStorageReferenceReceived+=(sender,args)=>{Console.WriteLine($"SMS received. Index{args.Index} at storage location{args.Storage}");};// Open AT channelatChannel.Open();// Configure modem with required settings before PINvarrequiredSettingsBeforePin=awaitmodem.SetRequiredSettingsBeforePinAsync();// Get SIM statusvarsimStatus=awaitmodem.GetSimStatusAsync();Console.WriteLine($"SIM Status:{simStatus}");// Check if SIM needs PINif(simStatus.Result==SimStatus.SIM_PIN){varsimPinStatus=awaitmodem.EnterSimPinAsync(newPersonalIdentificationNumber(pin));Console.WriteLine($"SIM PIN Status:{simPinStatus}");}// Configure modem with required settings after PINvarrequiredSettingsAfterPin=awaitmodem.SetRequiredSettingsAfterPinAsync();// Read SMS at index 1varsms=awaitmodem.ReadSmsAsync(1);if(sms.Success)Console.WriteLine(sms.Result);// Send SMS to the specified numberPhoneNumberphoneNumber=PhoneNumberFactory.CreateCommonIsdn(recepientPhoneNumber);stringmessage="Hello ATLib!";varsmsReferences=awaitmodem.SendSmsAsync(newSmsSubmitRequest(phoneNumber,message));foreach(varsmsReferenceinsmsReferences)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.


[8]ページ先頭

©2009-2025 Movatter.jp