package gammu

  1. Overview
  2. Docs

Interface to the gammu library (libGammu) to manage data in your cell phone such as contacts, calendar and messages.

NOTE: Strings used by libGammu often have a maximum allowed length. Strings too long will be trimmed before being passed to libGammu (this library considers OCaml strings as immutable).

NOTE: This library is not thread safe.

Error handling

type error =
  1. | DEVICEOPENERROR
    (*

    Error during opening device

    *)
  2. | DEVICELOCKED
    (*

    Device locked

    *)
  3. | DEVICENOTEXIST
    (*

    Device does not exist

    *)
  4. | DEVICEBUSY
    (*

    Device is busy

    *)
  5. | DEVICENOPERMISSION
    (*

    No permissions to open device

    *)
  6. | DEVICENODRIVER
    (*

    No driver installed for a device

    *)
  7. | DEVICENOTWORK
    (*

    Device doesn't seem to be working

    *)
  8. | DEVICEDTRRTSERROR
    (*

    Error during setting DTR/RTS in device

    *)
  9. | DEVICECHANGESPEEDERROR
    (*

    Error during changing speed in device

    *)
  10. | DEVICEWRITEERROR
    (*

    Error during writing device

    *)
  11. | DEVICEREADERROR
    (*

    Error during reading device

    *)
  12. | DEVICEPARITYERROR
    (*

    Can't set parity on device

    *)
  13. | TIMEOUT
    (*

    Command timed out

    *)
  14. | FRAMENOTREQUESTED
    (*

    Frame handled, but not requested in this moment

    *)
  15. | UNKNOWNRESPONSE
    (*

    Response not handled by gammu

    *)
  16. | UNKNOWNFRAME
    (*

    Frame not handled by gammu

    *)
  17. | UNKNOWNCONNECTIONTYPESTRING
    (*

    Unknown connection type given by user

    *)
  18. | UNKNOWNMODELSTRING
    (*

    Unknown model given by user

    *)
  19. | SOURCENOTAVAILABLE
    (*

    Some functions not compiled in your OS

    *)
  20. | NOTSUPPORTED
    (*

    Not supported by phone

    *)
  21. | EMPTY
    (*

    Empty entry or transfer end.

    *)
  22. | SECURITYERROR
    (*

    Not allowed

    *)
  23. | INVALIDLOCATION
    (*

    Too high or too low location...

    *)
  24. | NOTIMPLEMENTED
    (*

    Function not implemented

    *)
  25. | FULL
    (*

    Memory is full

    *)
  26. | UNKNOWN
    (*

    Unknown response from phone

    *)
  27. | CANTOPENFILE
    (*

    Error during opening file

    *)
  28. | MOREMEMORY
    (*

    More memory required

    *)
  29. | PERMISSION
    (*

    No permission

    *)
  30. | EMPTYSMSC
    (*

    SMSC number is empty

    *)
  31. | INSIDEPHONEMENU
    (*

    Inside phone menu - can't make something

    *)
  32. | NOTCONNECTED
    (*

    Phone NOT connected - can't make something

    *)
  33. | WORKINPROGRESS
    (*

    Work in progress

    *)
  34. | PHONEOFF
    (*

    Phone is disabled and connected to charger

    *)
  35. | FILENOTSUPPORTED
    (*

    File format not supported by Gammu

    *)
  36. | BUG
    (*

    Found bug in implementation or phone

    *)
  37. | CANCELED
    (*

    Action was canceled by user

    *)
  38. | NEEDANOTHERANSWER
    (*

    Inside Gammu: phone module need to send another answer frame

    *)
  39. | OTHERCONNECTIONREQUIRED
    (*

    You need other connection for this operation.

    *)
  40. | WRONGCRC
    (*

    Wrong CRC

    *)
  41. | INVALIDDATETIME
    (*

    Invalid date/time

    *)
  42. | MEMORY
    (*

    Phone memory error, maybe it is read only

    *)
  43. | INVALIDDATA
    (*

    Invalid data given to phone

    *)
  44. | FILEALREADYEXIST
    (*

    File with specified name already exist

    *)
  45. | FILENOTEXIST
    (*

    File with specified name doesn't exist

    *)
  46. | SHOULDBEFOLDER
    (*

    You have to give folder (not file) name

    *)
  47. | SHOULDBEFILE
    (*

    You have to give file (not folder) name

    *)
  48. | NOSIM
    (*

    Cannot access SIM card

    *)
  49. | GNAPPLETWRONG
    (*

    Invalid gnapplet version

    *)
  50. | FOLDERPART
    (*

    Only part of folders listed

    *)
  51. | FOLDERNOTEMPTY
    (*

    Folder is not empty

    *)
  52. | DATACONVERTED
    (*

    Data were converted

    *)
  53. | UNCONFIGURED
    (*

    Gammu is not configured.

    *)
  54. | WRONGFOLDER
    (*

    Wrong folder selected (eg. for SMS).

    *)
  55. | PHONE_INTERNAL
    (*

    Internal phone error (phone got crazy).

    *)
  56. | WRITING_FILE
    (*

    Could not write to a file (on local filesystem).

    *)
  57. | NONE_SECTION
    (*

    No such section exists.

    *)
  58. | USING_DEFAULTS
    (*

    Using default values.

    *)
  59. | CORRUPTED
    (*

    Corrupted data returned by phone.

    *)
  60. | BADFEATURE
    (*

    Bad feature string.

    *)
  61. | DISABLED
    (*

    Some functions not compiled in your OS

    *)
  62. | SPECIFYCHANNEL
    (*

    Bluetooth configuration requires channel option.

    *)
  63. | NOTRUNNING
    (*

    Service is not running.

    *)
  64. | NOSERVICE
    (*

    Service setup is missing.

    *)
  65. | BUSY
    (*

    Command failed. Try again.

    *)
  66. | COULDNT_CONNECT
    (*

    Cannot connect to server.

    *)
  67. | COULDNT_RESOLVE
    (*

    Cannot resolve host name.

    *)
  68. | GETTING_SMSC
    (*

    Failed to get SMSC number from phone.

    *)
  69. | ABORTED
    (*

    Operation aborted.

    *)
  70. | INSTALL_NOT_FOUND
    (*

    Installation data not found.

    *)
  71. | READ_ONLY
    (*

    Entry is read only.

    *)
  72. | NETWORK_ERROR
    (*

    Network error.

    *)
  73. | INI_KEY_NOT_FOUND
    (*

    Pair section/value not found in INI file.

    *)
  74. | COULD_NOT_DECODE
    (*

    Decoding SMS Message failed.

    *)
  75. | INVALID_CONFIG_NUM
    (*

    Invalid config number.

    *)

Possible errors.

val string_of_error : error -> string

string_of_error e returns a textual description of the error e.

exception Error of error

May be raised by any of the functions of this module to indicate an error.

Debugging settings

module Debug : sig ... end

State machine

type t

Value holding information about phone connection (called a "state machine").

type config = {
  1. model : string;
    (*

    Model from config file. Leave it empty for autodetection. Or define a phone model to force the phone model and bypass automatic phone model detection.

    *)
  2. debug_level : string;
    (*

    Debug level. See Gammu.Debug.set_level for acceptable level strings.

    *)
  3. device : string;
    (*

    Device name from config file such as "com2" or "/dev/ttyS1".

    *)
  4. connection : string;
    (*

    Connection type as string

    *)
  5. sync_time : bool;
    (*

    Synchronize time on startup?

    *)
  6. lock_device : bool;
    (*

    Lock device ? (Unix, ignored on Windows)

    *)
  7. debug_file : string;
    (*

    Name of debug file

    *)
  8. start_info : bool;
    (*

    Display something during start ?

    *)
  9. use_global_debug_file : bool;
    (*

    Should we use global debug file?

    *)
  10. text_reminder : string;
    (*

    Text for reminder calendar entry category in local language

    *)
  11. text_meeting : string;
    (*

    Text for meeting calendar entry category in local language

    *)
  12. text_call : string;
    (*

    Text for call calendar entry category in local language

    *)
  13. text_birthday : string;
    (*

    Text for birthday calendar entry category in local language

    *)
  14. text_memo : string;
    (*

    Text for memo calendar entry category in local language

    *)
}

Configuration of the state machine.

type connection_type =
  1. | BUS2
  2. | FBUS2
  3. | FBUS2DLR3
  4. | DKU2AT
  5. | DKU2PHONET
  6. | DKU5FBUS2
  7. | ARK3116FBUS2
  8. | FBUS2PL2303
  9. | FBUS2BLUE
  10. | FBUS2IRDA
  11. | PHONETBLUE
  12. | AT
  13. | BLUEGNAPBUS
  14. | IRDAOBEX
  15. | IRDAGNAPBUS
  16. | IRDAAT
  17. | IRDAPHONET
  18. | BLUEFBUS2
  19. | BLUEAT
  20. | BLUEPHONET
  21. | BLUEOBEX
  22. | FBUS2USB
  23. | NONE
val get_debug : t -> Debug.info

Gets debug information for state machine.

val init_locales : ?path:string -> unit -> unit

Initializes locales. This sets up things needed for proper string conversion from local charset as well as initializes gettext based translation. This module is automatically initialized the same way init_locales() would do.

  • parameter path

    Path to gettext translation. If not set, compiled in default is used.

val make : ?section:int -> unit -> t

Make a new clean state machine. It is automatically configured using load_gammurc. If you want to configure it yourself, use push_config to supersede the configuration with the one of your choice.

  • parameter section

    section number of the gammurc file to read. See Gammu.INI.config for details.

val get_config : ?num:int -> t -> config

get_config s ~num gets gammu configuration from state machine s, where num is the number of the section to read, starting from zero. If not specified, the currently used one is returned.

val push_config : t -> config -> unit

push_config s cfg push the configuration cfg on top of the configuration stack of s.

Gammu tries each configuration, from the bottom to the top of the stack, in order to connect.

val remove_config : t -> unit

remove_config s remove the top configuration from the config stack of s.

val length_config : t -> int
  • returns

    length of the configuration stack of the state machine. i.e the number of active configurations.

val load_gammurc : ?path:string -> ?section:int -> t -> unit

Automaticaly finds the gammurc file (see Gammu.INI.of_gammurc), read it and push the config in the state machine.

  • parameter path

    force the use of a custom path instead of the autodetected one (default: autodetection is performed).

  • parameter section

    section number of the gammurc file to read. See Gammu.INI.config for details.

val connect : ?log:(string -> unit) -> ?replies:int -> t -> unit

Initiates connection.

IMPORTANT: do not forget to call disconnect when done as otherwise the connection may be prematurely terminated. In fact, the problem is that if you have no reference to the state machine left, the GC may free it and by the same time terminate your connection.

  • parameter log

    logging function.

  • parameter replies

    number of replies to wait for on each request (default: 3).

val disconnect : t -> unit
val is_connected : t -> bool
val get_used_connection : t -> connection_type
val read_device : ?wait_for_reply:bool -> t -> int

Attempts to read data from phone. Thus can be used for getting status of incoming events, which would not be found out without polling device.

  • returns

    the number of read bytes.

  • parameter wait_for_reply

    whether to wait for some event (default true).

INI files

module INI : sig ... end

These functions parse ini file and make them available in easily accessible manner.

type security_code_type =
  1. | SEC_SecurityCode
    (*

    Security code.

    *)
  2. | SEC_Pin
    (*

    PIN.

    *)
  3. | SEC_Pin2
    (*

    PIN 2.

    *)
  4. | SEC_Puk
    (*

    PUK.

    *)
  5. | SEC_Puk2
    (*

    PUK 2.

    *)
  6. | SEC_None
    (*

    Code not needed.

    *)
  7. | SEC_Phone
    (*

    Phone code needed.

    *)
  8. | SEC_Network
    (*

    Network code needed.

    *)

Definition of security codes.

val enter_security_code : t -> code_type:security_code_type -> code:string -> unit

Enter security code (PIN, PUK,...).

val get_security_status : t -> security_code_type

Query whether some security code needs to be entered.

Informations on the phone

module Info : sig ... end

Informations on the phone.

Date and time

module DateTime : sig ... end

Date and time handling.

Memory

type memory_type =
  1. | ME
    (*

    Internal memory of the mobile equipment

    *)
  2. | SM
    (*

    SIM card memory

    *)
  3. | ON
    (*

    Own numbers

    *)
  4. | DC
    (*

    Dialled calls

    *)
  5. | RC
    (*

    Received calls

    *)
  6. | MC
    (*

    Missed calls

    *)
  7. | MT
    (*

    Combined ME and SIM phonebook

    *)
  8. | FD
    (*

    Fixed dial

    *)
  9. | VM
    (*

    Voice mailbox

    *)
  10. | SL
    (*

    Sent SMS logs

    *)
  11. | QD
    (*

    Quick dialing choices

    *)

Defines ID for various phone and SIM memories. Phone modules can translate them to values specific for concrete models. Two letter codes (excluding VM and SL) are from GSM 07.07.

type binary_picture
type entry_type =
  1. | Number_General of string
    (*

    General number.

    *)
  2. | Number_Mobile of string
    (*

    Mobile number.

    *)
  3. | Number_Work of string
    (*

    Work number.

    *)
  4. | Number_Fax of string
    (*

    Fax number.

    *)
  5. | Number_Home of string
    (*

    Home number.

    *)
  6. | Number_Pager of string
    (*

    Pager number.

    *)
  7. | Number_Other of string
    (*

    Other number.

    *)
  8. | Text_Note of string
    (*

    Note.

    *)
  9. | Text_Postal of string
    (*

    Complete postal address.

    *)
  10. | Text_Email of string
    (*

    Email.

    *)
  11. | Text_Email2 of string
  12. | Text_URL of string
    (*

    URL

    *)
  13. | Date of DateTime.t
    (*

    Date and time of last call.

    *)
  14. | Caller_Group of int
    (*

    Caller group.

    *)
  15. | Text_Name of string
    (*

    Name.

    *)
  16. | Text_LastName of string
    (*

    Last name.

    *)
  17. | Text_FirstName of string
    (*

    First name.

    *)
  18. | Text_Company of string
    (*

    Company.

    *)
  19. | Text_JobTitle of string
    (*

    Job title.

    *)
  20. | Category of string option
    (*

    Category.

    *)
  21. | Private of int
    (*

    Whether entry is private.

    *)
  22. | Text_StreetAddress of string
    (*

    Street address.

    *)
  23. | Text_City of string
    (*

    City.

    *)
  24. | Text_State of string
    (*

    State.

    *)
  25. | Text_Zip of string
    (*

    Zip code.

    *)
  26. | Text_Country of string
    (*

    Country.

    *)
  27. | Text_Custom1 of string
    (*

    Custom information 1.

    *)
  28. | Text_Custom2 of string
    (*

    Custom information 2.

    *)
  29. | Text_Custom3 of string
    (*

    Custom information 3.

    *)
  30. | Text_Custom4 of string
    (*

    Custom information 4.

    *)
  31. | RingtoneID of int
    (*

    Ringtone ID.

    *)
  32. | PictureID of int
    (*

    Picture ID.

    *)
  33. | Text_UserID of string
    (*

    User ID.

    *)
  34. | CallLength of int
    (*

    Length of call.

    *)
  35. | Text_LUID of string
    (*

    LUID - Unique Identifier used for synchronisation.

    *)
  36. | LastModified of DateTime.t
    (*

    Date of last modification.

    *)
  37. | Text_NickName of string
    (*

    Nick name.

    *)
  38. | Text_FormalName of string
    (*

    Formal name.

    *)
  39. | Text_WorkStreetAddress of string
    (*

    Work street address.

    *)
  40. | Text_WorkCity of string
    (*

    Work city.

    *)
  41. | Text_WorkState of string
    (*

    Work state.

    *)
  42. | Text_WorkZip of string
    (*

    Work zip code.

    *)
  43. | Text_WorkCountry of string
    (*

    Work country.

    *)
  44. | Text_WorkPostal of string
    (*

    Complete work postal address.

    *)
  45. | Text_PictureName of string
    (*

    Picture name (on phone filesystem).

    *)
  46. | PushToTalkID of string
    (*

    Push-to-talk ID.

    *)
  47. | Number_Messaging of string
    (*

    Favorite messaging number.

    *)
  48. | Photo of binary_picture
    (*

    Photo.

    *)
  49. | Number_Mobile_Home of string
    (*

    Home mobile number.

    *)
  50. | Number_Mobile_Work of string
    (*

    Work mobile number.

    *)

Type of specific phonebook entry.

type sub_memory_entry = {
  1. entry_type : entry_type;
    (*

    Type of entry, with data.

    *)
  2. voice_tag : int;
    (*

    Voice dialling tag.

    *)
  3. sms_list : int array;
  4. call_length : int;
  5. add_error : error;
    (*

    During adding SubEntry Gammu can return here info, if it was done OK.

    *)
}

One value of phonebook memory entry.

type memory_entry = {
  1. memory_type : memory_type;
    (*

    Used memory for phonebook entry.

    *)
  2. location : int;
    (*

    Used location for phonebook entry.

    *)
  3. entries : sub_memory_entry array;
    (*

    Values of SubEntries.

    *)
}

Value for saving phonebook entries.

Messages

module SMS : sig ... end

SMS messages manipulation.

Calls

module Call : sig ... end

Call entries manipulation.

Events

val incoming_sms : ?enable:bool -> t -> (SMS.message -> unit) -> unit

incoming_sms s f register f as callback function in the event of an incoming SMS.

  • parameter enable

    whether to enable notifications or not. (default = true)

val enable_incoming_sms : t -> bool -> unit

enable_incoming_sms t enable enable incoming sms events or not, according to enable.

val incoming_call : ?enable:bool -> t -> (Call.call -> unit) -> unit

incoming_call s f register f as callback function in the event of incoming call.

  • parameter enable

    whether to enable notifications or not. (default = true)

val enable_incoming_call : t -> bool -> unit

enable_incoming_call t enable enable incoming call events or not, according to enable.

OCaml

Innovation. Community. Security.