Vin

Vin

  • NA
  • 3
  • 0

Serial Communication in VISUAL STUDIO .NET 2005

Jan 17 2006 2:34 AM

HI all,

     Does anyone know about how to do serial communication in VISUAL STUDIO .NET 2005.

Here is the portion of code in which port_DataReceived sub is not getting called or activated unlike the mscomm_oncomm function in VB 6.0. Please help me out by replying to this or to mail [email protected]

Imports System.IO.Ports
Imports System.Threading.Thread
Partial Class _Default
    Inherits System.Web.UI.Page
    'Dim port As SerialPort = New SerialPort
    Dim port As New SerialPort
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       With port
            .BaudRate = 9600
            .DataBits = 8
            .Parity = Parity.None
            .StopBits = StopBits.One
            ''.ReceivedBytesThreshold = 1
            .PortName = "COM1"
            ''.Handshake = Handshake.RequestToSendXOnXOff
            ''.RtsEnable = True
        End With

        Try
            If port.IsOpen = False Then
                port.Open()
                Label1.Text = "COM1 IS AVAILABLE"
            Else
                port.Close()
                Sleep(100)
                port.Open()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try

          End Sub
    Private Sub port_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)

        'Show all the incoming data in the port's buffer
        'Console.WriteLine(port.ReadExisting())
        Dim buffer As String
        buffer = SerialData.Chars

        Console.WriteLine(buffer)

        MsgBox(buffer)

    End Sub
    Private Sub port_NEWDataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventHandler)
        Dim mybuff, mybuff1 As String
        mybuff = SerialData.Chars
        MsgBox("MYBUFF" & mybuff)

        mybuff1 = port.ReadExisting
        MsgBox("MYBUFF1" & mybuff1)
    End Sub
    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        port.Close()
    End Sub