I
I
Igor2020-02-27 16:09:16
PowerShell
Igor, 2020-02-27 16:09:16

[PowerShell] How to send SMS in Cyrillic via GSM modem?

Good day to all. I'm new to this, so please help.
I have a script to send SMS via USB modem.
Here is an excerpt:

If ($serialPort.IsOpen -eq $true) {
$serialPort.Write("AT+CMGF=1`r`n")
$serialPort.Write("AT+CMGS=`"$Number`"`r `n")
Start-Sleep -Seconds 1
$serialPort.Write("$Message`r`n")
$serialPort.Write($([char] 26))
<#
$time = Get-Date -Format "
[HH :mm:ss] [dd/MM/yyyy]"
$TextBoxlog1.text = $TextBoxlog1.text+$0+$2+
$time
$TextBoxlog1.Select($TextBoxlog1.TextLength, 0)
$TextBoxlog1.ScrollToCaret()
#>
Start-
Sleep -Seconds 5

SMS in Latin is sent perfectly. Tried to send in Cyrillic, only accepts questions. I'm sure it's a coding problem.
I wrote to the script:

$serialPort.Write("AT+CSCS=`"UCS2`"`r`n") the

modem shuts up and does not send a message.
I also tried to change the command
$serialPort.Write("AT+CMGF=1`r`n")
to
$serialPort.Write("AT+CMGF=0`r`n")
No result.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MaxKozlov, 2020-02-27
@MaxKozlov

I did not work with modems and SMS, but
you can try to experiment with recoding a message before sending using these functions

function Get-TextEncoding ($Encoding) {
    switch -regex ($Encoding) {
      'default' {
        [System.Text.Encoding]::Default
      }
      'utf8' {
        [System.Text.Encoding]::UTF8
      }
      'oem' {
        [System.Text.Encoding]::GetEncoding(
          (Get-Culture).TextInfo.OEMCodePage
        )
      }
      'ansi' {
        [System.Text.Encoding]::GetEncoding(
          (Get-Culture).TextInfo.ANSICodePage
        )
      }
      '^\d+$' {
        [System.Text.Encoding]::GetEncoding([int]$Encoding)
      }
      default {
        [System.Text.Encoding]::GetEncoding($Encoding)
      }
    }
}
function Convert-TextEncoding {
param (
  [Parameter(ValueFromPipeline=$true,Position=0)]
  [String[]]$InputObject,
  [Parameter(Mandatory=$true,Position=1)]
  [string]$FromEncoding,
  [Parameter(Mandatory=$true,Position=2)]
  [string]$ToEncoding
)
BEGIN {
  try {
    $FE = Get-TextEncoding $FromEncoding
    $TE = Get-TextEncoding $ToEncoding
  }
  catch {
    throw
  }
}
PROCESS{
  foreach ($s in $InputObject) {
    if ($s) {
      $TE.GetString($FE.GetBytes($s))
    }
    else {
      $s
    }
  }
}
}
# Например, читабельный вывод из удалённо выполняемых консольных приложений я получаю так:
# Invoke-Command -ComputerName remoteComp { dism /online } | Convert-TextEncoding -FromEncoding 1251 -ToEncoding 866

B
BasiC2k, 2020-02-28
@BasiC2k

Read about SMS PDU format.
When transmitting in Latin, you enter text in the AT command.
When transmitting in Cyrillic, it is necessary to recode all characters of the message according to a cunning algorithm.
Do not forget later in the AT command to switch the transmission format tex / PDU

I
Igor, 2020-03-02
@Kud93

I did not find anything better, how to use C# code for UCS2 encoding.
If anyone has a ready-made template for sending SMS via GSM using Powershell, please share =).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question