Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
C

charlie3636

@charlie3636
About
Posts
3
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Serial Port Strange Error!
    C charlie3636

    I seem to have solved the issue by modifying my ClosePort sub to:

    Public Sub ClosePort()
    bAllowSndRcv = False
    If IsNothing(comPort) Then Exit Sub
    If comPort.IsOpen Then
    comPort.DiscardOutBuffer()
    RemoveHandler comPort.DataReceived, AddressOf comPort_DataReceived
    Threading.Thread.Sleep(200)
    comPort.Close()
    End If
    End Sub

    C# data-structures help question

  • Serial Port Strange Error!
    C charlie3636

    Hi, Thanks for your answer. Ok, I will try the sleep. Interesting link you sent. What I am worried about is that once it's locked into the:

    ERROR The I/O operation has been aborted because of either a thread exit or an application request.
    Port Open Failed.

    it seems to stay there even if I start and stop my application again (both in dev environment in debug config, and using a released exe). The only way to unlock it is by opening and closing the port with hyperterminal. I wonder how I might be able to do this programatically? Is there any ways to run a batch file to open and close a hyperterminal? It's not the best solution but will have to do for a quick-fix... Thanks, Charlie

    C# data-structures help question

  • Serial Port Strange Error!
    C charlie3636

    Hi, I am getting a similar error. I am just trying to read from a serial COM port. It works fine. Then if I open and close the COM port a few times I get the following error when trying to open again:

    The I/O operation has been aborted because of either a thread exit or an application request.

    Starnagely enough the error is still tehre if I stop debugging (VisualStuio 2008, vb.net) and start again. The only way I can get it to work again is by opening and closing the port with hyperterminal! Here is my wrapper class:

    Public Class clComPort
    Private WithEvents comPort As System.IO.Ports.SerialPort
    Private write As Boolean = True
    Private bAllowSndRcv As Boolean = False
    Private thRec As System.Threading.Thread

    Public Event WroteData(ByVal msg As String)
    Public Event DataRecieved(ByVal msg As String)
    Public Event COMError(ByVal msg As String)

    Public Function OpenPort(ByVal ComNum As Integer, ByVal baudRate As Integer, ByVal dataBits As Integer, _
    ByVal parity As IO.Ports.Parity, ByVal stpBits As IO.Ports.StopBits) As Boolean
    bAllowSndRcv = False
    Try
    'first check if the port is already open
    'if its open then close it
    If Not IsNothing(comPort) Then
    Me.ClosePort()
    End If
    comPort = New System.IO.Ports.SerialPort()
    'set the properties of our SerialPort Object
    comPort.BaudRate = Integer.Parse(baudRate)
    comPort.DataBits = Integer.Parse(dataBits)
    comPort.StopBits = stpBits
    comPort.Parity = parity
    comPort.PortName = "COM" & ComNum
    comPort.ReadTimeout = 500
    comPort.WriteTimeout = 500

      'now open the port
      Dim b As Boolean = comPort.IsOpen
      comPort.Open()
      bAllowSndRcv = True
      'return true
      Return True
    Catch ex As Exception
      bAllowSndRcv = False
      RaiseEvent COMError(ex.Message)
      Return False
    End Try
    

    End Function
    Public Sub ClosePort()
    bAllowSndRcv = False
    If IsNothing(comPort) Then Exit Sub
    If comPort.IsOpen Then
    RemoveHandler comPort.DataReceived, AddressOf comPort_DataReceived
    comPort.Close()
    End If
    comPort.Dispose()
    End Sub
    Private Sub comPort_DataReceived(ByVal sender As Object, _
    ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles comPort.DataReceived
    'This event will Receive the data from the selected COM port..
    If Not bAllowSndRcv Then Exit Sub
    If e.Eve

    C# data-structures help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups