Results 1 to 6 of 6

Thread: the write timed out

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    7

    the write timed out

    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....

  2. #2

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    7

    Re: the write timed out

    by the way i am using gsm/gprs shield

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: the write timed out

    Did you have a reason for setting the write timeout? Try removing that line and see if that helps.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    7

    Re: the write timed out

    sir even though i removed that line, it still occurs

    i used GSM/GPRS shield

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: the write timed out

    What version of .Net are you using?

    See what happens if you disable WriteTimeouts
    .WriteTimeout = IO.Ports.SerialPort.InfiniteTimeout

    Any serialport IO should be enclosed in Try-Catch blocks.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    7

    Re: the write timed out

    i am using .NET 4.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width