none
Argument not specified for parameter 'ComPortName' of 'Public Sub New(ComPortName As String) RRS feed

  • Question

  • I am working on an application using COMPort.
    Application executed successfully.
    But when adding a reference:- Error is coming-  Argument not specified for parameter 'ComPortName' of 'Public Sub New(ComPortName As String)'
    Please guide how to resolve.
    Tuesday, April 23, 2013 11:26 AM

All replies

  • Can you post the code you are using when calling the function from your current project?  Below is a simple project that may help you solve the problem.

    Module Module1
        Sub Main()
            Dim cPort As Port = New Port("abc")
        End Sub
        Class Port
            Public Sub New(ByVal ComPortName As String)
            End Sub
        End Class
    End Module


    jdweng

    Tuesday, April 23, 2013 3:14 PM
  • I added AxSerial Reference in my code & when i run below code, it is executed successfully.

    Imports AxSerial Imports System.Windows.Threading Public Class DeviceInfo Private _objComport As AxSerial.ComPort = New COMPort() Private Sub DeviceInfo_Loaded(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Loaded Refresh() End Sub Private Sub Refresh() If _objComport.GetDeviceCount.Equals(0) Then MessageBox.Show("No Mobile Device Available", "Device Not Found", MessageBoxButton.OK, MessageBoxImage.Error) Return End If Dim i As System.Int32 lst_device.Items.Clear() For i = 0 To _objComport.GetDeviceCount() - 1 Dim devName = _objComport.GetDeviceName(i) lst_device.Items.Add(devName)

    Next

    End Sub End Class

    But, when i integrated same code with another code.

    Public Class Demo
        Private Sub Demo_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
            Dim Ports() As String = System.IO.Ports.SerialPort.GetPortNames()
    
            If Ports.Length.Equals(0) Then
                                       lst_port.Visibility = Windows.Visibility.Collapsed
            Else
                            lst_port.ItemsSource = Ports
                            lst_port.Visibility = Windows.Visibility.Visible
            End If
            End Sub
    
    Private Sub btnSelect_Click(sender As Object, e As RoutedEventArgs)
            If lst_port.SelectedItems.Count.Equals(0) Then
                MessageBox.Show("Please select atleast one COM Port from the COM Port List", "COM Selection", MessageBoxButton.OK, MessageBoxImage.Error)
                Return
            End If
    
            Dim ComPortNames As List(Of String) = New List(Of String)()
            For Each ComPortName As String In lst_port.SelectedItems
                ComPortNames.Add(ComPortName)
            Next
            CType(Application.Current, Application).SetupComPortNames(ComPortNames)
    
            MessageBox.Show("Selected COM Ports are now selected to use", "COM Selection", MessageBoxButton.OK, MessageBoxImage.Information)
        End Sub
    End Class


    Error comes as - Argument not specified for parameter 'ComPortName' of 'Public Sub New(ComPortName As String)


    Tuesday, April 23, 2013 5:19 PM
  • I am working on an application using COMPort.
    Application executed successfully.
    Then, i created another module by adding a COM reference.
    This also 
    executed successfully.
    But when integrating both:- Error is coming-  Argument not specified for parameter 'ComPortName' of 'Public Sub New(ComPortName As String)'
    Please guide how to resolve.
    Thursday, April 25, 2013 6:43 AM
  • I've tried before to help you with this problems in a previous posting.  Maybe if I show you a simple Class below that uses two constructors you will understand the problem better.  You need to post some of your code so I can really help.

    Module Module1
        Sub Main()
            Dim port1 As Myport = New Myport()
            Dim port2 As Myport = New Myport("Com2")
        End Sub
        Class Myport
            Sub New()
                //this is the default constuctor with no parameters
            End Sub
            Sub New(ByVal port As String)
                //this is the constructor with a parameter string
            End Sub
        End Class
    End Module


    jdweng

    Thursday, April 25, 2013 9:48 AM
  • Add the following to the top of the 2nd module.  It is in the first module and is needed in the 2nd module.

    Imports AxSerial


    jdweng

    Thursday, April 25, 2013 12:23 PM
  • I tried...but still same error comes
    Friday, April 26, 2013 3:43 AM
  • My code is:-

    Imports AxSerial 
    Imports System.Windows.Threading
    
    Public Class DeviceInfo
        Private _objComport As AxSerial.ComPort = New COMPort()
    
        Private Sub DeviceInfo_Loaded(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Loaded
            Dim i As System.Int32
            lst_device.Items.Clear()
            For i = 0 To _objComport.GetDeviceCount() - 1
                Dim devName = _objComport.GetDeviceName(i)
                lst_device.Items.Add(devName)
    Next     
    
        End Sub
    End Class
    Above code executed successfully. Now, I also want to  integrate below code within above module. 
    Imports System.IO.Ports
    Dim Ports() As String = System.IO.Ports.SerialPort.GetPortNames()

    but when i compile after integrating both, Error is coming-  Argument not specified for parameter 'ComPortName' of 'Public Sub New(ComPortName As String)' & line highlighted is-

    Private _objComport As AxSerial.ComPort = New COMPort()

    Please guide how to resolve.


    • Edited by Jatin5111 Friday, April 26, 2013 7:55 AM
    Friday, April 26, 2013 6:16 AM
  • I looks like you want to add the serial ports on the computer to the listbox of Mobile Device returned from the AxSerial library.  I would add a 2nd for loop.

    Private Sub DeviceInfo_Loaded(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Loaded
            Dim i As System.Int32
            lst_device.Items.Clear()
            For i = 0 To _objComport.GetDeviceCount() - 1
                Dim devName = _objComport.GetDeviceName(i)
                lst_device.Items.Add(devName)
            Next i
            For Each port as string in Ports
                lst_device.Items.Add(port)
            Next port   
        End Sub


    jdweng

    Friday, April 26, 2013 10:12 AM
  • Thanks..it works.
    Now my next task is to select a COM Port for some operation from the list.

    Earlier i was using below code to select COM port from list which was retrieved by using code- 
    Dim Ports() As String = System.IO.Ports.SerialPort.GetPortNames()
    lst_com.ItemsSource = Ports
    Code for selecting COM Port :-
    Public Class COMSelection
    
        Private Sub COMSelection_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
            Dim Ports() As String = System.IO.Ports.SerialPort.GetPortNames()
    
                lst_com.ItemsSource = Ports
        End Sub
    
        Private Sub btnSelect_Click(sender As Object, e As RoutedEventArgs)
            Dim ComPortNames As List(Of String) = New List(Of String)()
    
            For Each ComPortName As String In lst_com.SelectedItems
                ComPortNames.Add(ComPortName)
            Next
    
            CType(Application.Current, Application).SetupComPortNames(ComPortNames)
    
            MessageBox.Show("Selected COM Ports are now selected to use", "COM Selection", MessageBoxButton.OK, MessageBoxImage.Information)
    
        End Sub
    End Class
    Now, i want to include AxSerial Library module also:-
    Imports AxSerial
    Imports System.IO.Ports
    
    Class DeviceInfo
        Public _objComport As AxSerial.ComPort = New COMPort()
        Dim Ports() As String = System.IO.Ports.SerialPort.GetPortNames()
    
        Private Sub DeviceInfo_Loaded(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Loaded
            
            Dim i As System.Int32
            lst_device.Items.Clear()
            For i = 0 To _objComport.GetDeviceCount() - 1
                Dim devName = _objComport.GetDeviceName(i)
                lst_device.Items.Add(devName)
            Next i
            
            For Each port As String In Ports
                lst_com.Items.Add(port)
            Next port
        End Sub
    End Class
    Please guide how to make changes for selecting a particular COM Port by integrating both.

    • Edited by Jatin5111 Friday, April 26, 2013 10:36 AM
    Friday, April 26, 2013 10:35 AM
  • I'm thinking of adding another column to the lst_com object that would indicate if the device is a serial port or Mobile Device.  Is the lst_com a ListView or a Listbox.  The code would be a little different. 

    You need some method of telling if a port is a mobile device or a serial port.  right now you have the object lst_device in two different classes an I'm not sure what type of object it is and how the two classes (DeviceInfo and ComSelection) are sharing the same instance of the object.  I would like to see the code that is creating the two classes (DeviceInfo and ComSelection) and where lst_com is being declared or which form the device is located on.


    jdweng

    Friday, April 26, 2013 11:35 AM
  • Port is a serial port.
    i passed AT commands over Serial port to fetch some data.
    Now, i also want to use AxSerial Library in order to fetch list of Mobile Device available.
    Therefore, want to integrate both ..
    in order to pass AT commands over serial port as well as want to fetch list of Mobile Device available via AxSerial library.

    Thanks,
    Jatin
    Monday, April 29, 2013 11:06 AM
  • I understand.  Because you are using different functons when a device is selected you need a method that associates the device name to either a mobile or serial port.  there arre a lot of ways to do this but I'm not sure which is the best method for your application at the moment.  Is there a place in the code where the two forms can access the same object so we can put a a list of device names and the type of device.  Or do you want to added another column to the lst_device object where we can add the device type.

    jdweng

    Monday, April 29, 2013 11:14 AM
  • I think another column suits good
    Monday, April 29, 2013 11:34 AM
  • What type of control is the lst_device object

    jdweng

    Monday, April 29, 2013 11:37 AM
  • lst_device is a ListBox.
    Code used:- 

    Imports AxSerial
    Imports System.IO.Ports
    
    Class DeviceInfo
        Public _objComport As AxSerial.ComPort = New COMPort()
        Dim Ports() As String = System.IO.Ports.SerialPort.GetPortNames()
    
        Private Sub DeviceInfo_Loaded(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Loaded
            
            Dim i As System.Int32
            lst_device.Items.Clear()
            For i = 0 To _objComport.GetDeviceCount() - 1
                Dim devName = _objComport.GetDeviceName(i)
                lst_device.Items.Add(devName)
            Next i
            
            For Each port As String In Ports
                lst_com.Items.Add(port)
            Next port
        End Sub
    End Class

    Monday, April 29, 2013 11:39 AM