Modules | |
Exceptions thrown by Modem | |
Enumerations | |
Events related with Modem and SIM | |
Classes | |
class | ModemManager |
Implementation for IModemManager. Start point for interact with Modem Manager More... | |
interface | IModem |
Modem single element. Allows to interact with modem. Get information and set configuration More... | |
interface | IModemManager |
Modem Manager allows to mange all device Modem features More... | |
interface | ISim |
SIM element that allows to get information from the SIM and interact with it More... | |
Detailed Description
To work with Deepsy modem service it is necessary to use ModemManager located in GMV.ITS.HAL.DEEPSY.Modem.Facade for getting the initial ModemManager object.
ModemManager has an optional parameter indicating the ip address of remote service. For instance:
ModemManager is an IDisposable interface. An object that may hold resources (such as file or socket handles) until it is closed. The Dispose() method of an IDisposable object is called automatically when exiting a try-with-resources block, or exiting a using clause where it was declared. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur:
If this object is not inside a try with resources block, it is recommended to call to Dispose() in order to finalize properly;
Examples
-
Enabling/disabling modem
For enabling/disabling modem it is needed to call to enable and disable methods in modem.using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.DataConnection{class ModemEnableDisableApp{static void Main(string[] args){List<IModem> modemList = modemManager.GetModems().ToList();{PowerStatus.Power modemStatusPower = modem.GetModemStatus().PowerStatus;Console.WriteLine($"Power Modem status: {modem.GetModemStatus().PowerStatus}");if(modemStatusPower == PowerStatus.Power.MODEM_DISABLED){modem.Enable();}else{modem.Disable();}}}}}
-
Subscribe to events
There are 5 types of events in the modem system:- ModemListEvent : This event happens when a modem is added to or removed from the system. To receive this kind of events, it is necessary to subscribe to the ModemManager object with an object implementing interface ModemListObserver
- ModemEvent:ModemStatusEvent : This event happens when a modem status changes. To receive this kind of events, it is necessary to subscribe to the Modem object with an object implementing interface ModemObserver
- ModemEvent:ModemWarningEvent : This event happens when a modem has a warning. To receive this kind of events, it is necessary to subscribe to the Modem object with an object implementing interface ModemObserver
- ModemEvent:SimListEvent : This event happens when a sim is added or removed from a modem. To receive this kind of events, it is necessary to subscribe to the Modem object with an object implementing interface ModemObserver
- SimEvent : This event happens when a sim status changes. To receive this kind of events, it is necessary to subscribe to the Sim object with an object implementing interface SimObserver
using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.DataConnection{class ModemEventsApp{static void Main(string[] args){modemManager.ModemListEvent += ModemManager_ModemListEvent;List<IModem> modemList = modemManager.GetModems().ToList();{SubscribeToModemEvents(modem);SubscribeToSimEvents(modem.SimList);}}{modem.ModemStatusEvent += Modem_ModemStatusEvent;modem.ModemWarningEvent += Modem_ModemWarningEvent;modem.SimListEvent += Modem_SimListEvent;}private static void SubscribeToSimEvents(IEnumerable<ISim> sims){if (sims.Any()){{sim.SimStatusEvent += Sim_SimStatusEvent;}}}private static void Sim_SimStatusEvent(object sender, ISimStatusEvent e){Console.WriteLine($"Sim {e.Sim.GetInformation().Imsi} status changed to: {e.Status}");}private static void Modem_SimListEvent(object sender, ISimListEvent e){Console.WriteLine($"SIM {e.Sim.GetInformation().Imsi} event: {((e.Action == SimListAction.Action.Added) ? "ADDED" : "REMOVED")}");if (e.Action == SimListAction.Action.Added){SubscribeToSimEvents(new List<ISim> { e.Sim });}}private static void Modem_ModemWarningEvent(object sender, IModemWarningEvent e){Console.WriteLine($"Modem warning {e.Modem.GetModemInformation().Imei}: {e.Warning}");}private static void Modem_ModemStatusEvent(object sender, IModemStatusEvent e){Console.WriteLine($"Modem {e.Modem.GetModemInformation().Imei} status changed to:");Console.WriteLine($"State {e.Status.PowerStatus}");Console.WriteLine($"Power {e.Status.PowerStatus}");Console.WriteLine($"Signal {e.Status.SignalQuality}");Console.WriteLine($"Network Status {e.Status.CellularNetworkStatus}");Console.WriteLine($"Access Technology {e.Status.AccessTechnology}");}private static void ModemManager_ModemListEvent(object sender, IModemListEvent e){Console.WriteLine($"Modem {e.Modem.GetModemInformation().Imei} event: {((e.Action == ModemListAction.Action.Added) ? "ADDED" : "REMOVED")}");if (e.Action == ModemListAction.Action.Added){SubscribeToModemEvents(e.Modem);SubscribeToSimEvents(e.Modem.GetSimList());}}}}
-
Manage Forced APN After setting a forced APN it is important to restart modem in order to connect with the new APN parameters using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.DataConnection{class ModemForcedApnApp{static void Main(string[] args){//Get Forced APNConsole.WriteLine("\nGet Forced APN: ");ApnInformation apn = modemManager.GetForcedApn();printAPN(apn);//Set a Forced APNConsole.WriteLine("\nSet a new Forced APN: ");modemManager.SetForcedApn(new ApnInformation(){Apn = "myapnForced",User = "myuserForced",Password = "mypasswordForced"});apn = modemManager.GetForcedApn();printAPN(apn);//Stop the use of a Forced APNConsole.WriteLine("\nStop the use of a Forced APN: ");modemManager.StopForcedApn();apn = modemManager.GetForcedApn();printAPN(apn);}static void printAPN(ApnInformation _apn){Console.WriteLine($"Current Forced APN:" +"\n\tAPN: [" + _apn.Apn + "]" +"\n\tUser: [" + _apn.User + "]" +"\n\tPassword: [" + _apn.Password + "]");}}}
-
Get Modem data connection information and statistics using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.DataConnection{class ModemInformationApp{static void Main(string[] args){List<IModem> modemList = modemManager.GetModems().ToList();{Console.WriteLine($"Modem Name: {modem.GetInterfaceInformation().Name}");Console.WriteLine($"Modem IP: {modem.GetInterfaceInformation().IpAddress}");List<IInterfaceStatistics> stats = modem.GetInterfaceInformation().Statistics.ToList();foreach(IInterfaceStatistics stat in stats){Console.WriteLine($"{stat.Type}: {stat.Value}");}}}}}
-
Sim Operations using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.DataConnection{class ModemSimOperationsApp{static void Main(string[] args){List<IModem> modemList = modemManager.GetModems().ToList();{Console.WriteLine($"Modem: {modem.GetModemInformation().Imei}, data status enable: {(modem.DataConnectionStatus() ? "TRUE" : "FALSE")}");List<ISim> activeSims = modem.GetActiveSimList().ToList();{Console.WriteLine($"SIM IMSI: {sim.GetInformation().Imsi} is activated");}}}}}