Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to plug/unplug USB serial port programitically?

How to plug/unplug USB serial port programitically?

Scheduled Pinned Locked Moved Visual Basic
helphardwaretutorialquestion
11 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pallaka
    wrote on last edited by
    #1

    How to plug/unplug USB serial port problematically? I am facing some strange issue with my USB serial port. I want to unplug and plug the USB Serial port Programitically, as i need to refresh the connection between system and hardware connected.Kindly help....... Thank in advance for the great programmers

    D F 2 Replies Last reply
    0
    • P pallaka

      How to plug/unplug USB serial port problematically? I am facing some strange issue with my USB serial port. I want to unplug and plug the USB Serial port Programitically, as i need to refresh the connection between system and hardware connected.Kindly help....... Thank in advance for the great programmers

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      ...

      It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

      1 Reply Last reply
      0
      • P pallaka

        How to plug/unplug USB serial port problematically? I am facing some strange issue with my USB serial port. I want to unplug and plug the USB Serial port Programitically, as i need to refresh the connection between system and hardware connected.Kindly help....... Thank in advance for the great programmers

        F Offline
        F Offline
        freakyit
        wrote on last edited by
        #3

        hi you can do this using the registry. set the DWORD of "Start" in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\{driver}\ to "4" for disable and 3 to enable. this may help :) never tested ^^

        P 1 Reply Last reply
        0
        • F freakyit

          hi you can do this using the registry. set the DWORD of "Start" in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\{driver}\ to "4" for disable and 3 to enable. this may help :) never tested ^^

          P Offline
          P Offline
          pallaka
          wrote on last edited by
          #4

          I am looking for some one who did it problematically. But still thanks for your Solution :)

          L F 2 Replies Last reply
          0
          • P pallaka

            I am looking for some one who did it problematically. But still thanks for your Solution :)

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            WTF is 'problematically'? I did it while using a problem?

            Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]

            D 1 Reply Last reply
            0
            • L Lost User

              WTF is 'problematically'? I did it while using a problem?

              Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              OP means through code.

              It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

              1 Reply Last reply
              0
              • P pallaka

                I am looking for some one who did it problematically. But still thanks for your Solution :)

                F Offline
                F Offline
                freakyit
                wrote on last edited by
                #7

                whats the exactly problem you have with usb plugged devices ? i may can help you out, i wrote a serial component in c# that checks wheather the connection needs to be closed after unplugging the device and reopend after replug the device to usb without running into exceptions..

                P 1 Reply Last reply
                0
                • F freakyit

                  whats the exactly problem you have with usb plugged devices ? i may can help you out, i wrote a serial component in c# that checks wheather the connection needs to be closed after unplugging the device and reopend after replug the device to usb without running into exceptions..

                  P Offline
                  P Offline
                  pallaka
                  wrote on last edited by
                  #8

                  I have connected the usb serial port and started getting the data from the hardware. Suddenly i will stop the hardware and re run it .Now the problem is when i return the hardware and try to re connect the my application back and try to connect the COM port, it throws me a message the port is already connected and because of this i can not receive the data, kindly help me to understand the stuff

                  D L 2 Replies Last reply
                  0
                  • P pallaka

                    I have connected the usb serial port and started getting the data from the hardware. Suddenly i will stop the hardware and re run it .Now the problem is when i return the hardware and try to re connect the my application back and try to connect the COM port, it throws me a message the port is already connected and because of this i can not receive the data, kindly help me to understand the stuff

                    D Offline
                    D Offline
                    DaveAuld
                    wrote on last edited by
                    #9

                    If you kill the hardware, the classes relating to the serial comms have probably bombed, and your application itself is holding the serial port resource on one of its async threads. I have seen this while programming to a usb/serial device (resol solar controller). When you exit the application the lock is released and then when you start the app again all is fine. You should check that when you kill the external hardware or pull the connection, the necessary exceptions are being caught and the serial connection is closed gracefully to ensure all resource locks are released.

                    Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

                    F 1 Reply Last reply
                    0
                    • P pallaka

                      I have connected the usb serial port and started getting the data from the hardware. Suddenly i will stop the hardware and re run it .Now the problem is when i return the hardware and try to re connect the my application back and try to connect the COM port, it throws me a message the port is already connected and because of this i can not receive the data, kindly help me to understand the stuff

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      and it may be wise to call DiscardInBuffer() and DiscardOutBuffer() right after creating your serial port, and before connecting any event handlers to it. :)

                      Luc Pattyn


                      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                      1 Reply Last reply
                      0
                      • D DaveAuld

                        If you kill the hardware, the classes relating to the serial comms have probably bombed, and your application itself is holding the serial port resource on one of its async threads. I have seen this while programming to a usb/serial device (resol solar controller). When you exit the application the lock is released and then when you start the app again all is fine. You should check that when you kill the external hardware or pull the connection, the necessary exceptions are being caught and the serial connection is closed gracefully to ensure all resource locks are released.

                        Dave Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

                        F Offline
                        F Offline
                        freakyit
                        wrote on last edited by
                        #11

                        The problem is that the stream in the SerialPort class will not be closed if the external hardware will be removed. this is an bug in the framework. to prevent this behaviour the solution is to rewrite a serial port class using unmanaged code or to kill the application like daveauld described above.. serial port communication was not designed to work during the hardware will be removed. in ealy cases this was not possible because the COM was an integrated hardware in the pc not an usb plugalbe device. i had the same problem and sovled it by rewriting the serial port (internal catching read/write errors and than closing and reopening the filestream on COM). bless :)

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups