Row Scanning and Delay for Automatic Sms Sending in VB2012 - vb.net

I have a MS SQL Linked-Server (from Mysql) - generated Table TBL containing
*Index
*StdNo
*MobileNo
And I have a VB2012 code for SMS sending:
Private Sub cmdsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsend.Click
Try
If SerialPort1.IsOpen Then
With SerialPort1
.Write("AT" & vbCrLf)
.Write("AT+CMGF=1" & vbCrLf)
.Write("AT+CMGS=" & Chr(34) & TextBox1.Text & Chr(34) & vbCrLf)
.Write(RichTextBox1.Text & Chr(26))
End With
Else
MsgBox("Error on the port selected")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Where TextBox1.Text is the textbox where number is actually manually inputted
and RichTextBox1.Text is the message that will be sent.
What I wanted is to create a code that will automatically select each row of the table TBL for the MobileNo and then sends SMS. Since the VB code is not really for Bulk messaging, my idea is to create a loop that will scan each row, get each MobileNo, sends the message, then delay for a few second before the next row scan. I don't even know if it is possible. But I think it is, I just don't know how to come up with the loop and I don't even know how to create the connection between the database. Does anybody have any idea how to accomplish this?

may be you can use this code:
Private Sub cmdsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsend.Click
Try
If SerialPort1.IsOpen Then
With SerialPort1
.Write("AT" & vbCrLf)
.Write("AT+CMGF=1" & vbCrLf)
.Write("AT+CMGS=" & Chr(13)
.Write(TextBox1.Text)
.Write(Chr(26))
End With
Else
MsgBox("Error on the port selected")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Related

Send data to Honeywell Xenon 1902 barcode reader via virtual com port

I am trying to send a query to the Honeywell Xenon 1902 barcode scanner. The scanner is connected via virtual com port.
Setting up the communication works fine:
With SerialPort1
If Not .IsOpen Then
Try
.PortName = "Com9"
.BaudRate = 115200
.DataBits = 8
.Parity = Parity.None
.StopBits = StopBits.One
.Handshake = Handshake.None
.DtrEnable = False
.RtsEnable = False
.Open()
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Öffnen des COM Ports", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End With
When I press manually the button for scanning I receive the data of reading from the scanner:
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Try
Dim sp As SerialPort = CType(sender, SerialPort)
PufferString = sp.ReadExisting
MsgBox(PufferString)
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Empfangen", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Now I would like to send the query command "cbr?." from the Honeywell Documentation to the scanner and receive the answer. If I do this on the Honeywell WebInterface it all works fine:
Screenshot from the Honeywell Web Interface Terminal
So my problem is that I am unable to send commands to the scanner neither via Tera Term or any other terminal nor via my code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim BefehlsString As String = "cbr?."
Dim enc As System.Text.Encoding = New System.Text.ASCIIEncoding()
Try
Dim ByteArray() As Byte ' Oder String in ...
ByteArray = enc.GetBytes(BefehlsString & vbCr) ' ... Einzelbytes umwandeln
SerialPort1.BaseStream.Write(ByteArray, 0, ByteArray.Length) ' Einzelbytes senden
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Senden", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Due to kunif tip I read the Honeywell Documentation again and I solved my problem:
The command need the prefix "SYN M CR" (ASCII 22,77,13) --> "SYNMCRcbr?." has to be send to the scanner via serial connection.
This is the code I send to the scanner:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim BefehlsString As String = Chr(&H16) & "M" & Chr(&HD) & "cbr?."
serialport.WriteLine(BefehlsString)
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace, "Fehler beim Senden", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Then I get an answer as defined in the documentation.
Perhaps, removing the "vbCr" at the end of the command may work.
There is a CR code in the prefix of "Menu Command Syntax" on page 11-1 of Area-Imaging Scanner User's Guide, but there is no CR code in "cbr?." of "Examples of Query Commands" on page 11-3.
Alternatively, you can investigate what kind of communication is occurring using software/hardware called SerialPort/USB protocol monitor/sniffer.

How to send SMS with VB.NET?

So I've been trying to send sms's with my VB.NET application but I had no luck.
I add the carrier and nothing.
#Region "Methods"
Private Sub frmMain_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' set up the carriers list - this is a fair list,
' you may wish to research the topic and add others,
' it took a while to generate this list...
cboCarrier.Items.Add("#itelemigcelular.com.br")
cboCarrier.Items.Add("#message.alltel.com")
cboCarrier.Items.Add("#message.pioneerenidcellular.com")
cboCarrier.Items.Add("#messaging.cellone-sf.com")
cboCarrier.Items.Add("#messaging.centurytel.net")
cboCarrier.Items.Add("#messaging.sprintpcs.com")
cboCarrier.Items.Add("#mobile.att.net")
cboCarrier.Items.Add("#mobile.cell1se.com")
cboCarrier.Items.Add("#mobile.celloneusa.com")
cboCarrier.Items.Add("#mobile.dobson.net")
cboCarrier.Items.Add("#mobile.mycingular.com")
cboCarrier.Items.Add("#mobile.mycingular.net")
cboCarrier.Items.Add("#mobile.surewest.com")
cboCarrier.Items.Add("#msg.acsalaska.com")
cboCarrier.Items.Add("#msg.clearnet.com")
cboCarrier.Items.Add("#msg.mactel.com")
cboCarrier.Items.Add("#msg.myvzw.com")
cboCarrier.Items.Add("#msg.telus.com")
cboCarrier.Items.Add("#mycellular.com")
cboCarrier.Items.Add("#mycingular.com")
cboCarrier.Items.Add("#mycingular.net")
cboCarrier.Items.Add("#mycingular.textmsg.com")
cboCarrier.Items.Add("#o2.net.br")
cboCarrier.Items.Add("#ondefor.com")
cboCarrier.Items.Add("#pcs.rogers.com")
cboCarrier.Items.Add("#personal-net.com.ar")
cboCarrier.Items.Add("#personal.net.py")
cboCarrier.Items.Add("#portafree.com")
cboCarrier.Items.Add("#qwest.com")
cboCarrier.Items.Add("#qwestmp.com")
cboCarrier.Items.Add("#sbcemail.com")
cboCarrier.Items.Add("#sms.bluecell.com")
cboCarrier.Items.Add("#sms.cwjamaica.com")
cboCarrier.Items.Add("#sms.edgewireless.com")
cboCarrier.Items.Add("#sms.hickorytech.com")
cboCarrier.Items.Add("#sms.net.nz")
cboCarrier.Items.Add("#sms.pscel.com")
cboCarrier.Items.Add("#smsc.vzpacifica.net")
cboCarrier.Items.Add("#speedmemo.com")
cboCarrier.Items.Add("#suncom1.com")
cboCarrier.Items.Add("#sungram.com")
cboCarrier.Items.Add("#telesurf.com.py")
cboCarrier.Items.Add("#teletexto.rcp.net.pe")
cboCarrier.Items.Add("#text.houstoncellular.net")
cboCarrier.Items.Add("#text.telus.com")
cboCarrier.Items.Add("#timnet.com")
cboCarrier.Items.Add("#timnet.com.br")
cboCarrier.Items.Add("#tms.suncom.com")
cboCarrier.Items.Add("#tmomail.net")
cboCarrier.Items.Add("#tsttmobile.co.tt")
cboCarrier.Items.Add("#txt.bellmobility.ca")
cboCarrier.Items.Add("#typetalk.ruralcellular.com")
cboCarrier.Items.Add("#unistar.unifon.com.ar")
cboCarrier.Items.Add("#uscc.textmsg.com")
cboCarrier.Items.Add("#voicestream.net")
cboCarrier.Items.Add("#vtext.com")
cboCarrier.Items.Add("#wireless.bellsouth.com")
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSend.Click
' Collect user input from the form and stow content into
' the objects member variables
mTo = Trim(txtPhoneNumber.Text) & _
Trim(cboCarrier.SelectedItem.ToString())
mFrom = Trim(txtSender.Text)
mSubject = Trim(txtSubject.Text)
mMailServer = Trim(txtMailServer.Text)
mMsg = Trim(txtMessage.Text)
' Within a try catch, format and send the message to
' the recipient. Catch and handle any errors.
Try
Dim message As New MailMessage(mFrom, mTo, mSubject, mMsg)
Dim mySmtpClient As New SmtpClient(mMailServer)
mySmtpClient.UseDefaultCredentials = True
mySmtpClient.Send(message)
MessageBox.Show("The mail message has been sent to " & _
message.To.ToString(), "Mail", _
MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Catch ex As FormatException
MessageBox.Show(ex.StackTrace, ex.Message, _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Catch ex As SmtpException
MessageBox.Show(ex.StackTrace, ex.Message, _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Catch ex As Exception
MessageBox.Show(ex.StackTrace, ex.Message, _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click
' Upon user’s request, close the application
Application.Exit()
End Sub
#End Region
If you are trying to SMS-enable a VB.NET application, I'd use this third party product:
Esendex
I used this in such a solution. The .NET SDK is devastatingly simple to understand and execute. The rates are reasonable and the support is excellent too.

Sending And Receiving SMS From GSM modem

I am trying to send message from GSM modem. I can submit AT commands the response is OK without any ERRORS. But the problem is I can't send message or read message.
I have implemented 3 functions:
Connect to port
Read SMS
Send SMS
Handles
1. Connect To Port:
Private Sub BtnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConnect.Click
If SerialPort1.IsOpen Then
SerialPort1.Close()
BtnConnect.Text = "Connect"
Else
Try
With SerialPort1
.PortName = Trim(Mid(ComboBox1.Text, 1, 5))
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = Ports.StopBits.One
.Handshake = Ports.Handshake.None
.RtsEnable = True
.DtrEnable = True
.Open()
.WriteLine("AT+CNMI=1,2,0,0,0" & vbCrLf) 'send whatever data that it receives to serial port
End With
BtnConnect.Text = "Disconnect"
Catch ex As Exception
BtnConnect.Text = "Connect"
MsgBox(ex.Message)
End Try
End If
End Sub
2. Read SMS
Private Sub btn_read_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_read.Click
Try
SerialPort1.WriteLine("AT" & vbCrLf) 'is modem okay?
Thread.Sleep(1000)
SerialPort1.WriteLine("AT+CMGF=1" & vbCrLf) 'To format SMS as a TEXT message
Thread.Sleep(1000)
SerialPort1.WriteLine("AT+CPMS=""SM""" & vbCrLf) ' Select SIM storage
Threading.Thread.Sleep(1000)
SerialPort1.WriteLine("AT+CMGL=""REC UNREAD""" & vbCrLf) 'read unread messages
Threading.Thread.Sleep(1000)
SerialPort1.WriteLine("AT+CMGL=""ALL""" & vbCrLf) 'print all message
Threading.Thread.Sleep(1000)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
3. Send SMS
Private Sub btn_send_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_send.Click
Try
With SerialPort1
.WriteLine("AT" & vbCrLf)
Threading.Thread.Sleep(1000)
.WriteLine("AT+CMGF=1" & vbCrLf) 'Instruct the GSM / GPRS modem to operate in SMS text mode
Threading.Thread.Sleep(1000)
.WriteLine("AT+CMGS=""9802100355""" & vbCr) 'sender ko no. rakhne ho tyo txtnumber ma
Threading.Thread.Sleep(1000) 'thapeko
.WriteLine("This is test message" & vbCrLf & Chr(26)) 'txtmessage automatic huna parchha haina?
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
4. Handles for Data received in Serial Port
Private Sub serialport1_datareceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
'Pause while all data is read
System.Threading.Thread.Sleep(300)
rcvdata = SerialPort1.ReadExisting()
MsgBox(rcvdata, , "Response From AT")
rcvdata = ""
End Sub
Where did I miss anything? While sending SMS I get CMS 500 error. With the software from the modem I am able to read and send sms. But I need to implement my own in my software.
There may several cause of this error. First check your network. Second set Message service center number using AT commands and save this setting. Hope this will help you
In your second function, you can try declaring a string variable to receive the data, like this:
With serialport1
rcvdata=""
.Write(All AT commands)
Threading.Thread.Sleep(1000)
Msgbox(rcvdata.Tostring)
End With
You can add a handler to datareceived to read all the bytes:
Dim entrada As String = " "
Dim numeros As Integer = SerialPort1.BytesToRead
For i As Integer = 1 To numeros
entrada&= Chr(SerialPort1.ReadChar)
Next
chama(entrada)
Private Sub chama(ByVal dados As String)
rcvdata &= dados
End Sub
AT+CMGS=""9802100355"
Your Phone number is wrong thats why you getting error 500, you need to enter full phone number including 0 at the front.

Cannot add computer to active directory using LDAP

Using the following code:
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
'see if it already exists
If DirectoryEntry.Exists("LDAP://CN=" & AdEntry.Text & ",OU=" & Machinetype.Text & ",OU=Computers,OU=" & USlocation.Text & ",OU=North America,DC=company,DC=com") = True Then
MsgBox("Object already exists")
Else
Try
'Set the directory entry
Dim de As New DirectoryEntry("LDAP://OU=" & Machinetype.Text & ",OU=Computers,OU=" & USlocation.Text & ",OU=North America,DC=company,DC=com")
Dim newComputer As DirectoryEntry = de.Children.Add("CN=TESTER", "computer")
newComputer.CommitChanges()
MsgBox("Computer added!")
Catch ex As Exception
MsgBox("Error adding computer")
End Try
End If
End Sub
End Class
According to http://msdn.microsoft.com/en-us/library/ms180851(v=VS.80).aspx this should work, but it returns an exception. Is there something I'm missing?

Issue Log in vb.Net?

I have a problem with a log in... Well let me explain you my problem, the problem is that i want to create a log in with restrictions, I have some textbox with the binding source property changed to my database. But when I type something that is not in the DataBase the program got freezes, I will post my code, hope you can help me (=
Private Sub KryptonButton1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles KryptonButton1.Click
If txtUser.Text <> UserTextBox.Text Then
While txtUser.Text <> UserTextBox.Text
Me.UsuarioContraseñaBindingSource.MoveNext()
End While
If txtUser.Text = UserTextBox.Text Then
KryptonMessageBox.Show("Welcome")
Else
KryptonMessageBox.Show("Error")
End If
End If
End Sub
Have a closer look at the loop in your code and its exit condition … under what circumstances does the loop exit? What happens otherwise?
In general you need play out and cover all scenarios but you already know the scenario here: your user input is not in the database and the application freezes. This should provide ample hints to find the cause.
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
If txt_user.Text <> vbNullString And txt_pass.Text <> vbNullString Then
Dim chkcmd As New SqlCommand("select * from users where username = '" & txt_user.Text & "' and password = '" & txt_pass.Text & "'", con)
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Dim chkval As SqlDataReader = chkcmd.ExecuteReader
If chkval.Read = True Then
Me.Hide()
Form2.Show()
Else
MsgBox("Invalid key to login!", MsgBoxStyle.Exclamation, "Message")
txt_pass.Clear()
txt_user.Clear()
txt_user.Select()
End If
con.Close()
End If
End Sub