Solved

declare a serial port

Posted on 2014-09-04
2
226 Views
Last Modified: 2014-09-05
I am converting an application from VB6 to .NET

The VB6 code was:
Sub InitComPort(ComPort As Control, PortNum As Integer)
    ' -------------------------------
    ' setups the commport
    ' ------------------------------

    On Local Error Resume Next
    If ComPort.PortOpen = True Then
        ComPort.PortOpen = False
    End If
    ComPort.CommPort = PortNum
   
    ComPort.Settings = "9600,N,8,1"
   
    ComPort.PortOpen = True
   
    ComPort.RThreshold = 0
   
    SendingCmd = False
   
End Sub

How does the ComPort get defined in VB.NET.
Thanks,
0
Comment
Question by:Adam_930
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Assisted Solution

by:joekucera2002
joekucera2002 earned 200 total points
ID: 40304914
You are looking for the SerialPort class in the System.IO.Ports namespace.

Please let me know if you need a code sample. Keep in mind that in VB6, the ComPort was a control that was placed on a form, and the SerialPort is a class meant to be used in code (preferably not in the UI layer).
0
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 300 total points
ID: 40305093
Hello,

Check the following code:

Function ReceiveSerialData() As String
    ' Receive strings from a serial port.
    Dim returnStr As String = "" 

    Dim com1 As IO.Ports.SerialPort = Nothing
    Try
        com1 = My.Computer.Ports.OpenSerialPort("COM1")
        com1.ReadTimeout = 10000
        Do
            Dim Incoming As String = com1.ReadLine()
            If Incoming Is Nothing Then
                Exit Do
            Else
                returnStr &= Incoming & vbCrLf
            End If
        Loop
    Catch ex As TimeoutException
        returnStr = "Error: Serial Port read timed out."
    Finally
        If com1 IsNot Nothing Then com1.Close()
    End Try

    Return returnStr
End Function

Check the detailed article
 http://www.dreamincode.net/forums/topic/37361-serial-port-communication-in-vbnet/
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question