hbjorgo / ATLib

ATLib is a C# library that makes it easy to communicate with modems.
MIT License
49 stars 20 forks source link

How to make a phone Call? #9

Closed thuyenvinh closed 3 years ago

thuyenvinh commented 3 years ago

Hi all! How to Make a Phone Call and detect when phone is answered or rejected...?

hbjorgo commented 3 years ago

Hi! You want to make a call from this library to another device? That is currently not implemented, but if that's something you're interested in, I can implement it. Receiving a call through the library works fine.

thuyenvinh commented 3 years ago

yes! please implement it

hbjorgo commented 3 years ago

Hi Please check out the latest release: https://github.com/hbjorgo/ATLib/releases/tag/3.0.0 I hope this is what you're looking for 😃 Please let me know if you experience any issues 👌🏼

hbjorgo commented 3 years ago

Have you had a chance to try it out? Register on the OnCallEnded event and dial the number. In the event you'll get the call details which includes the call duration.

thuyenvinh commented 3 years ago

It would be good if you add Send USSD function!

hbjorgo commented 3 years ago

Thank you, I'm looking into it!

thuyenvinh commented 3 years ago

here my function public virtual async Task SendUSSDAsync(string ussdComand, string dcs = "15") { (AtError error, AtResponse response) = await channel.SendFullCommandAsync($"AT+CUSD=1,\"{ussdComand}\",{dcs}", AtCommandType.MULTILINE, "+CUSD:", null,TimeSpan.Zero); if (error == AtError.NO_ERROR) { StringBuilder builder = new StringBuilder(); foreach (string line in response.Intermediates) { builder.AppendLine(line); } return builder.ToString(); } return null; } thank you!

hbjorgo commented 3 years ago

Thank you for your code example!

I'm trying to get USSD responses on my network, but it looks like they don't offer any. I only get negative responses. Could you provide me with some real request/responses?

Example:

Request: AT+CUSD=1,"*100#",15 Response: OK +CUSD: 1,"Your balance is 100",15

Etc. Is +CUSD: response always a single line?

thuyenvinh commented 3 years ago

add this code
case ConsoleKey.U: var rsUssd = await modem.SendUSSDAsync("*101#"); Console.WriteLine($"Ussd: {rsUssd}"); break;

here result...

Opening serial port...
Serialport opened
SIM Status: SIM_READY
Signal Strength: RSSI: 17, BER: 99
Battery Status: Charge Status: Powered by battery, Charge Level: 100%
Product Information:
Manufacturer: ZTE CORPORATION
Model: MF190
Revision: BD_MF190V1.0.0B02
IMEI: 863403019673989
+GCAP: +CGSM,+DS,+ES
Setting date and time: OK
Date and time:
Setting SMS text format: OK
Setting new SMS indication: OK
Single SMS:
Done. Press 'a' to answer call, 'd' to dial, 'h' to hang up, 's' to send SMS and 'q' to exit...
uUssd:
+CUSD: 0,"00560049004E00410043004100520044002E00200054004B0020006300680069006E0068003D0031003500300035003900200056004E0044002C0020004B004D003D003000200056004E0044002C0020004B004D0031003D003000200056004E0044002C0020004B004D0032003D003000200056004E0044002C0020004B004D0033003D003000200056004E0044002C00200044004B0032003D003000200056004E0044002E002000480061006E002000730075002000640075006E0067002000300038002F00300039002F0032003000320031",72
hbjorgo commented 3 years ago

Thank you for your sample response.

Please check out the latest release: 3.1.0 Use the method "SendUssdAsync", and you'll get the response in the "UssdResponseReceived" event. I also included a UCS2 decoder :)

thuyenvinh commented 3 years ago

thank you very much!