- [DEVEXPRESS] Hỗ trợ tìm kiếm highlight không dấu và không khoảng cách trên Gridview Filter
- [C#] Chia sẻ source code phần mềm Image Downloader tải hàng loạt hình ảnh từ danh sách link url
- [C#] Chụp hình và quay video từ camera trên winform
- [C#] Chia sẽ full source code tách file Pdf thành nhiều file với các tùy chọn
- Giới thiệu về Stock Tracker Widget - Công cụ theo dõi cổ phiếu và cảnh báo giá tăng giảm bằng C# và WPF
- [VB.NET] Chia sẻ công cụ nhập số tiền tự động định dạng tiền tệ Việt Nam
- [VB.NET] Hướng dẫn fill dữ liệu từ winform vào Microsoft word
- [VB.NET] Hướng dẫn chọn nhiều dòng trên Datagridview
- Hướng Dẫn Đăng Nhập Nhiều Tài Khoản Zalo Trên Máy Tính Cực Kỳ Đơn Giản
- [C#] Chia sẻ source code phần mềm đếm số trang tập tin file PDF
- [C#] Cách Sử Dụng DeviceId trong C# Để Tạo Khóa Cho Ứng Dụng
- [SQLSERVER] Loại bỏ Restricted User trên database MSSQL
- [C#] Hướng dẫn tạo mã QRcode Style trên winform
- [C#] Hướng dẫn sử dụng temp mail service api trên winform
- [C#] Hướng dẫn tạo mã thanh toán VietQR Pay không sử dụng API trên winform
- [C#] Hướng Dẫn Tạo Windows Service Đơn Giản Bằng Topshelf
- [C#] Chia sẻ source code đọc dữ liệu từ Google Sheet trên winform
- [C#] Chia sẻ source code tạo mã QR MOMO đa năng Winform
- [C#] Chia sẻ source code phần mềm lên lịch tự động chạy ứng dụng Scheduler Task Winform
- [C#] Hướng dẫn download file từ Minio Server Winform
[VB.NET] Chia sẽ source code gởi và nhận tin nhắn SMS từ Dcom 3G sử dụng AT Command
Xin chào các bạn, bài viết hôm nay mình sẽ chia sẽ cho các bạn source code gởi và nhận tin nhắn từ thiết bị Dcom 3G sử dụng tập lệnh AT command trong lập trình VB.NET.
[VB.NET] Send and Receive Message from Dcom 3G using AT Command
Dưới đây là giao diện gởi và nhận tin nhắn:

và dưới đây là giao diện nhận tin nhắn SMS

Source code Send and Receive SMS VB.NET
Imports System.ComponentModel
Imports System.Text
Imports DevExpress.XtraEditors
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Imports System.Text.RegularExpressions
Imports System.Data.OleDb
Imports VB = Microsoft.VisualBasic.Strings
Namespace CsWinFormsBlackApp
    Partial Public Class frm_sendsms
        Inherits DevExpress.XtraEditors.XtraForm
        Public Sub New()
            InitializeComponent()
        End Sub
        Public strconnect As New OleDbConnection
        Public Sub open_connect()
            Try
                strconnect.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & System.Windows.Forms.Application.StartupPath() & "Database.mdb"
                strconnect.Open()
            Catch ex As Exception
                ' XtraMessageBox.Show("Lỗi kết nối đến máy chủ. Vui lòng thử lại.")
            End Try
        End Sub
        Public Sub close_connect()
            strconnect.Close()
        End Sub
        Private Sub frm_sendsms_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            _LoadData()
            Dim ports As String() = SerialPort.GetPortNames
            Dim port As String
            For Each port In ports
                cbo_Port.Properties.Items.Add(port)
            Next port
            cbo_Port.SelectedIndex = 0
        End Sub
        Private Sub btnKetNoi_Click(sender As Object, e As EventArgs) Handles btnKetNoi.Click
            If SerialPort1.IsOpen Then
                btnKetNoi.Text = "&Kết nối"
                Me.Text = "Tình trạng chưa kết nối với thiết bị " & cbo_Port.Text
                SerialPort1.Close()
                cbo_Port.Enabled = True
                btnNgungNhanTin_Click(sender, e)
            Else
                Try
                    With SerialPort1
                        .PortName = cbo_Port.Text
                        .BaudRate = 115200
                        .Parity = Parity.None
                        .StopBits = StopBits.One
                        .DataBits = 8
                        .Handshake = Handshake.RequestToSend
                        .DtrEnable = True
                        .RtsEnable = True
                        .NewLine = vbCrLf
                        .Open()
                    End With
                    btnKetNoi.Text = "&Ngắt kết nối"
                    Me.Text = "Đã kết nối với thiết bị port " & cbo_Port.Text
                    cbo_Port.Enabled = False
                Catch ex As Exception
                    Me.Text = "Lỗi kết nối..."
                End Try
                btnNhanTinNhan_Click(sender, e)
            End If
        End Sub
        Private Sub btn_Guitinnhan_Click(sender As Object, e As EventArgs) Handles btn_Guitinnhan.Click
            Dim MESS As String = txt_NoiDung.Text
            Try
                If SerialPort1.IsOpen Then
                    With SerialPort1
                        .Write("AT" & vbCrLf)
                        .Write("AT+CMGF=1" & vbCrLf)
                        .Write("AT+CMGS=" & Chr(34) & txt_SoDT.Text & Chr(34) & vbCrLf)
                        .Write(MESS & Chr(26))
                    End With
                    Me.Text = "Đã gởi tin nhắn thành công!"
                Else
                    Me.Text = "Lỗi chưa chọn port kết nối"
                End If
            Catch ex As Exception
                Me.Text = ex.Message
            End Try
        End Sub
        Private Sub btnNhanTinNhan_Click(sender As Object, e As EventArgs) Handles btnNhanTinNhan.Click
            Timer1.Enabled = True
            btnNgungNhanTin.Enabled = True
            btnNhanTinNhan.Enabled = False
            Me.Text = "Đang chờ nhận lệnh..."
        End Sub
        Private Sub btnNgungNhanTin_Click(sender As Object, e As EventArgs) Handles btnNgungNhanTin.Click
            Timer1.Enabled = False
            btnNgungNhanTin.Enabled = False
            btnNhanTinNhan.Enabled = True
            XoaTinNhan()
            Me.Text = "Ngưng nhận lệnh thực thi"
        End Sub
        Private Sub XoaTinNhan()
            If SerialPort1.IsOpen Then
                With SerialPort1
                    .Write("AT+CMGD=1,4" & vbCrLf)
                End With
            Else
                Me.Text = "Lỗi chưa chọn port kết nối"
            End If
        End Sub
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            If SerialPort1.IsOpen Then
                With SerialPort1
                    .Write("AT+CMGL=" & Chr(34) & "REC UNREAD" & Chr(34) & vbCrLf)
                End With
                Dim response As String = SerialPort1.ReadExisting()
                'Dim r As New Regex("+CMGL: (d+),""(.+)"",""(.+)"",(.*),""(.+)""
(.+)
")
                Dim r As New Regex("+CMGL: (d+),""(.+)"",""(.+)"",(.*),""(.+)""
(.+)
(.+)")
                Dim m As Match = r.Match(response)
                txt_HienThi_Lenh.Text = response
                'get ngày tháng
                Dim id As String = m.Groups(1).Value
                Dim sodt As String = m.Groups(3).Value
                Dim noidung As String = m.Groups(6).Value
                Dim noidung2 As String = m.Groups(7).Value
                Dim website As String = ""
                Dim ngaythang As String = m.Groups(5).Value
                If _kiemtra("select count(*) from tbl_log where createdDate='" & ngaythang & "'") <> "1" Then
                    If noidung <> "" Then
                        'Dim FinalStr As String = noidung.Replace(ControlChars.Lf, ",")
                        'Dim TestArray() As String = Split(FinalStr, ",")
                        'For i As Integer = 0 To TestArray.Length - 1
                        '    If TestArray(i) <> "" Then
                        '        If i = 0 Then
                        '            noidung2 = TestArray(0)
                        '        Else
                        '            Dim a As String = TestArray(i)
                        '            If a.Length > 2 Then
                        '                website = a
                        '            End If
                        '        End If
                        '    End If
                        'Next
                        _Save("Insert into tbl_log(phone, content, createdDate, website) values('" & sodt & "','" & noidung & "','" & ngaythang & "','" & noidung2 & "')")
                        m = m.NextMatch()
                    End If
                End If
            Else
                Me.Text = "Lỗi chưa chọn port kết nối"
            End If
            XoaTinNhan()
            _LoadData()
        End Sub
        Dim cmd As New OleDbCommand
        Dim da As New OleDbDataAdapter
        Dim dt As New DataTable
        Public Sub _LoadData()
            open_connect()
            cmd = strconnect.CreateCommand
            cmd.CommandText = "select * from tbl_log order by id DESC"
            dt.Clear()
            da.SelectCommand = cmd
            da.Fill(dt)
            GridControl1.DataSource = dt
            close_connect()
        End Sub
        Public Function _kiemtra(ByVal strLenh As String) As String
            Dim str As String
            open_connect()
            Dim cmd As New OleDbCommand(strLenh, strconnect)
            str = cmd.ExecuteScalar().ToString
            close_connect()
            Return str
        End Function
        Public Sub _Save(ByVal strLenh As String)
            open_connect()
            Dim cmd As New OleDbCommand(strLenh, strconnect)
            cmd.ExecuteNonQuery()
            close_connect()
        End Sub
        Private Sub cbo_Port_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbo_Port.SelectedIndexChanged
        End Sub
    End Class
End NamespaceHAPPY CODING 

![[VB.NET] Chia sẽ source code gởi và nhận tin nhắn SMS từ Dcom 3G sử dụng AT Command](https://laptrinhvb.net/uploads/users/9a8cb514e4428e85fb4ca07588e9103f.png)

![[VB.NET] Chia sẻ công cụ nhập số tiền tự động định dạng tiền tệ Việt Nam](https://laptrinhvb.net/uploads/source/vbnet/dinhdang_tiente_vietnam.png)
![[VB.NET] Hướng dẫn fill dữ liệu từ winform vào Microsoft word](https://laptrinhvb.net/uploads/source/new_image_baiviet/thumb_fillform_toword.png)
![[VB.NET] Hướng dẫn chọn nhiều dòng trên Datagridview](https://laptrinhvb.net/uploads/source/new_image_baiviet/multi_select_gridview_vb.png)
![[VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator](https://laptrinhvb.net/uploads/source/vbnet/acc_windows.png)
![[VB.NET] Gởi tin nhắn và file đính kèm qua ứng dụng gởi tin nhắn Whats App](https://laptrinhvb.net/uploads/source/vbnet/whatsapp_vb.png)
![[VB.NET] Chia sẻ source code quản lý thu chi mô hình 3 lớp Winform](https://laptrinhvb.net/uploads/source/vbnet/QUAN_LYTIENQUY.png)
![[VB.NET] Chia sẻ source code lịch âm dương và hẹn lịch nhắc việc](https://laptrinhvb.net/uploads/source/vbnet/lich_am_vb.png)
![[VB.NET] Hướng dẫn giải captcha sử dụng dịch vụ AZCaptcha API trên winform](https://laptrinhvb.net/uploads/source/vbnet/az_captchathumb.png)
![[VB.NET] Chia sẻ source tạo sắp xếp đội hình bóng đá Line-ups đội bóng](https://laptrinhvb.net/uploads/source/vbnet/line_up_vb.png)
![[VB.NET] Hiệu ứng Acrylic, Mica, Tabbed Blur Effect trên Winform](https://laptrinhvb.net/uploads/source/vbnet/AcrylicBlurWindows11_web.png)
