hey guys i need some help. how to fix "the write timed out" in vb 2010?
here is the code:
Imports System.IO.Ports
Imports System
Imports System.Threading
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
openport()
End Sub
Private Sub openport()
Dim ports As String() = SerialPort.GetPortNames
Dim port As String
For Each port In ports
cbPort.Items.Add(port)
Next port
cbPort.SelectedIndex = 0
End Sub
Private Sub btnConn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConn.Click
With srPort
Try
.PortName = cbPort.Text
.BaudRate = "19200"
.Parity = System.IO.Ports.Parity.None
.StopBits = System.IO.Ports.StopBits.One
.DataBits = 8
.WriteTimeout = 100
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
srPort.Open()
MsgBox("Port now open")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End With
End Sub
Private Sub SendRT_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendRT.TextChanged
Dim send As String = SendRT.Text
Select Case send
Case "Shutting Down"
Try
shutdown()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Case "The Computer is Now Restarting"
Try
shutdown()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Case "The Computer will Now Hibernate"
Try
shutdown()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Select
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
srPort.Close()
MsgBox("Disconnected")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub receiveRT_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles receiveRT.TextChanged
Dim str As String = receiveRT.Text
Select Case str
Case "Shutdown"
SendRT.Text = "Shutting Down"
Case "Restart"
SendRT.Text = "The Computer is Now Restarting"
Case "Hibernate"
SendRT.Text = "The Computer will Now Hibernate"
Case Else
SendRT.Text = ""
End Select
End Sub
Private Sub shutdown()
If srPort.IsOpen Then
With srPort
.Write("AT")
.Write("AT+CMGF=1" & vbCrLf)
.Write("AT+CMGS=" & Chr(34) & CNtbox.Text & Chr(34) & vbCrLf)
.Write(SendRT.Text & Chr(26))
receiveRT.Clear()
SendRT.Clear()
End With
End If
End Sub
End Class
basically i encountered that problem in the public sub shutdown(), where "the write timed out" occurs.
please help me fix this....![]()



Reply With Quote
