Results 1 to 12 of 12

Thread: Not serial...USB

  1. #1

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Not serial...USB

    I have this bit of code that displays what is coming through the serial port. Now, the company has bought a box that connects via USB. So, the question becomes: "what has to be changed to monitor the USB port"?

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
      With MSComm1
        'make sure the serial port is open
        If .PortOpen = False Then .PortOpen = True
        'send the data (including a tailing carriage return as often needed)
        .Output = Text2.Text & vbCr
      End With 'MSComm1
      With Text2
        'place the focus back to the textbox
        .SetFocus
        'select the current text to be overwritten
        .SelStart = 0
        .SelLength = Len(.Text)
      End With 'Text1
    End Sub
    
    Private Sub Form_Load()
      With MSComm1
        'make sure the serial port is not open (by this program)
        If .PortOpen Then .PortOpen = False
        'set the active serial port
        .CommPort = 1
        'set the badurate,parity,databits,stopbits for the connection
        .Settings = "19200,N,8,1"
        'set the DRT and RTS flags
        .DTREnable = True
        .RTSEnable = True
        'enable the oncomm event for every reveived character
        .RThreshold = 1
        'disable the oncomm event for send characters
        .SThreshold = 0
        'open the serial port
        .PortOpen = True
      End With 'MSComm1
      With Text1
        'set the properties for the displaying textbox
        .BackColor = vbCyan
        .Locked = True
        .Text = ""
      End With 'Text1
      With Text2
        'set the properties for the 'send' textbox
        .TabIndex = 0
        .Text = ""
      End With 'Text2
      With Command1
        'set the properties for the 'send' command button
        .Caption = "&Send"
        .Default = True
        .TabIndex = 1
      End With 'Command1
    End Sub
    
    Private Sub Form_Resize()
      Dim sngWidth As Single, sngHeight As Single
      Dim sngDisplayHeight As Single
      Dim sngTxtWidth As Single
      Dim sngCmdWidth As Single, sngCmdHeight As Single
      'calculate the inner size of the form
      sngWidth = ScaleWidth
      sngHeight = ScaleHeight
      With Command1
        'resize and reposition the command button
        sngCmdHeight = .Height
        sngCmdWidth = .Width
        sngDisplayHeight = sngHeight - sngCmdHeight
        sngTxtWidth = sngWidth - sngCmdWidth
        .Move sngTxtWidth, sngDisplayHeight, sngCmdWidth, sngCmdHeight
      End With 'Command1
      'resize and reposition the label
      Text1.Move 0, 0, sngWidth, sngDisplayHeight
      'resize and reposition the textbox
      Text2.Move 0, sngDisplayHeight, sngTxtWidth, sngCmdHeight
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    MsgBox Text1.Text
    End Sub
    
    Private Sub MSComm1_OnComm()
      Dim strInput As String
      With MSComm1
        'test for incoming event
        Select Case .CommEvent
          Case comEvReceive
            'display incoming event data to displaying textbox
            strInput = Asc(.Input)
            Text1.SelText = strInput
        End Select
      End With 'MSComm1
    End Sub
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Not serial...USB

    Does this MSDN page help? Sounds like it may not be doable if the page applies. However, reading other threads and some googling, it appears whether it works or not is up to the driver that comes with USB device? I'd recommend doing some more searching; this is not in my realm of experience.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Not serial...USB

    Thanks for the reply. More research is definitely called for.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Not serial...USB

    Quote Originally Posted by Pasvorto View Post
    Thanks for the reply. More research is definitely called for.
    My google search terms were: mscomm usb serial
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Not serial...USB

    OK. Thanks again. :-)
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  6. #6
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: Not serial...USB

    If the 'box' just exposes more 'com ports' like this:-



    Then you shouldn't need to do much at all. Once the device driver for the box is installed then you'll just have more com ports.

    Is that type of box you're talking about ?

    I've used this box before - on the back is the USB connection - it comes with a 1 meter usb cable, plug one end of the cable into the box and the other into a USB port on the computer - install the drivers and suddenly you have 4 more com ports.

  7. #7

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Not serial...USB

    Maybe. I have not seen the box yet.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  8. #8
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: Not serial...USB

    Quote Originally Posted by Pasvorto View Post
    Now, the company has bought a box that connects via USB.

    Quote Originally Posted by Pasvorto View Post
    Haven't seen the box yet

    If "The Company" expects you to make physical connections with the same external peripherals/devices then I guess it's likely a USB-to-RS232 box in which case you probably won't need to do much - maybe just change the port numbers (The new ports may be numbered 5, 6, 7 and 8)

  9. #9

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Not serial...USB

    It will be interesting, for sure. It is not expected to be attached for a few days.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Not serial...USB

    From what I read, mscomm only supports ports 1-16. If your USB reports ports in a range higher than that, there is a ocx hack that appears to work. Here is something worth bookmarking until you know for sure either way.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Not serial...USB

    Cool. Thanks.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  12. #12
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: Not serial...USB

    If the USB interface is a USB serial adapter (Virtual Serial Port), then your code shouldn't have to change. On occasion USB VSPs assign port number higher than 16, thus you would need a modified version of MSComm32.ocx to use these higher port numbers. I provide the detail for this in my book, along with the modified ocx. If you send me email, I will send you the actual control.

    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width