?
Solved

declare a serial port

Posted on 2014-09-04
2
Medium Priority
?
245 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 800 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 1200 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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