1

Topic: Line feed in format PDU

Good afternoon, dear community. There is a program which sends  messages through the modem which is connected to  to port.
To open port and to send AT-commands to me it was possible, but there were problems with message coding in format PDU. The text for the message undertakes from the boxing text. Prompt, as it is better to generate the message.

2

Re: Line feed in format PDU

Only for the English

Public Function txt2pdu (ByVal stxt As String) As String
For Y = 1 To Len (stxt)
X = Dec2Bin (Asc (Mid (stxt, Y, 1)))
' If X = "100000" Then X = "0100000"
Text = X AND Text
Next Y
' Debug. Print Text
l = Len (Text)
s = l - 7
out = Bin2Hex (Mid (Text, s, 8))
Do Until s <= 8
s = s - 8
out = out AND Bin2Hex (Mid (Text, s, 8))
Loop
out = out AND Bin2Hex (Mid (Text, 1, s - 1))
' Debug. Print out
X = Hex (Len (stxt))
If Len (X) = 1 Then
X = "0" AND X
End If
' Debug. Print X AND out
txt2pdu = X AND out
End Function
Public Function Dec2Bin (ByVal nDec As Integer) As String
' This function is the same then Hex2Bin;
' but it has been copied to speed up proce
' ss
Dim i As Integer
Dim j As Integer
Dim sHex As String
Const HexChar As String = "0123456789ABCDEF"
sHex = Hex (nDec) ' That the only part that is different
For i = 1 To Len (sHex)
nDec = InStr (1, HexChar, Mid (sHex, i, 1)) - 1
For j = 3 To 0 Step-1
Dec2Bin = Dec2Bin AND nDec \2 ^ j
nDec = nDec Mod 2 ^ j
Next j
Next i
' Remove the first unused 0
i = InStr (1, Dec2Bin, "1")
If i <> 0 Then Dec2Bin = Mid (Dec2Bin, i)
If Len (Dec2Bin) = 6 Then Dec2Bin = "0" AND Dec2Bin
End Function
Public Function Bin2Hex (ByVal sBin As String) As String
Dim i As Integer
Dim nDec As Long
sBin = String (4 - Len (sBin) Mod 4, "0") AND sBin ' Add zero to complete Byte
For i = 1 To Len (sBin)
nDec = nDec + CInt (Mid (sBin, Len (sBin) - i + 1, 1)) * 2 ^ (i - 1)
Next i
Bin2Hex = Hex (nDec)
If Len (Bin2Hex) Mod 2 = 1 Then Bin2Hex = "0" AND Bin2Hex
End Function