Detecting USB port connection











up vote
0
down vote

favorite












I am writing a console application in C++. So far my code can detect if my device (linux) has been connected to another device (usually windows) via TCPIP. Once I open Putty on my Windows to connect to my device that is running the console application, my code recognizes it and automatically sends data from my device(linux), to my computer.



I would like to do the same thing with USB. Right now, my console application can send/receive data from my Windows device, BUT only if I send data first. I want my console application to automatically detect if it has been connected to via putty or other application, and automatically start sending data to my microprocessor. I've read and played with libudev by running code that displays when a USB device has been connected and disconnected. I would like to know if there is a way for my device(linux) to know that it has been connected to my PC via Putty, and not a hotplug event. and if so, is there an example floating around somewhere I can use.



would it be a good idea to use sockets? Can I use sockets with usb devices?



Thanks in advanced.



Full disclosure, I am relatively new with Linux OS.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am writing a console application in C++. So far my code can detect if my device (linux) has been connected to another device (usually windows) via TCPIP. Once I open Putty on my Windows to connect to my device that is running the console application, my code recognizes it and automatically sends data from my device(linux), to my computer.



    I would like to do the same thing with USB. Right now, my console application can send/receive data from my Windows device, BUT only if I send data first. I want my console application to automatically detect if it has been connected to via putty or other application, and automatically start sending data to my microprocessor. I've read and played with libudev by running code that displays when a USB device has been connected and disconnected. I would like to know if there is a way for my device(linux) to know that it has been connected to my PC via Putty, and not a hotplug event. and if so, is there an example floating around somewhere I can use.



    would it be a good idea to use sockets? Can I use sockets with usb devices?



    Thanks in advanced.



    Full disclosure, I am relatively new with Linux OS.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am writing a console application in C++. So far my code can detect if my device (linux) has been connected to another device (usually windows) via TCPIP. Once I open Putty on my Windows to connect to my device that is running the console application, my code recognizes it and automatically sends data from my device(linux), to my computer.



      I would like to do the same thing with USB. Right now, my console application can send/receive data from my Windows device, BUT only if I send data first. I want my console application to automatically detect if it has been connected to via putty or other application, and automatically start sending data to my microprocessor. I've read and played with libudev by running code that displays when a USB device has been connected and disconnected. I would like to know if there is a way for my device(linux) to know that it has been connected to my PC via Putty, and not a hotplug event. and if so, is there an example floating around somewhere I can use.



      would it be a good idea to use sockets? Can I use sockets with usb devices?



      Thanks in advanced.



      Full disclosure, I am relatively new with Linux OS.










      share|improve this question















      I am writing a console application in C++. So far my code can detect if my device (linux) has been connected to another device (usually windows) via TCPIP. Once I open Putty on my Windows to connect to my device that is running the console application, my code recognizes it and automatically sends data from my device(linux), to my computer.



      I would like to do the same thing with USB. Right now, my console application can send/receive data from my Windows device, BUT only if I send data first. I want my console application to automatically detect if it has been connected to via putty or other application, and automatically start sending data to my microprocessor. I've read and played with libudev by running code that displays when a USB device has been connected and disconnected. I would like to know if there is a way for my device(linux) to know that it has been connected to my PC via Putty, and not a hotplug event. and if so, is there an example floating around somewhere I can use.



      would it be a good idea to use sockets? Can I use sockets with usb devices?



      Thanks in advanced.



      Full disclosure, I am relatively new with Linux OS.







      16.04 networking usb putty hotplug






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 22:02

























      asked Nov 12 at 19:10









      miceandmon

      235




      235






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Well, there are some major issues with what you are suggesting. A normal USB cable is master->slave, which means that one machine is the controlling machine, and the other is a slave. Both a Windows machine and an Ubuntu machine, would both expect to be the host, controlling the USB operations as the USB-Master. There is nothing off-the-shelf that would change this relationship (but many embedded designs that switch host-slave relationships).



          HOWEVER, you can use a USB-Bridge (or Transfer) Cable to communicate over USB between two machines. I found this one on Amazon "Plugable Windows Transfer Cable". You should be able to use this to write a console application on both sides, but would require some experience with Windows and Linux drivers. Not trivial.



          I suppose one other idea, would be to use two USB network dongles, and connect them to each other with an ethernet cross-over cable, and setup a local network. You could still use your networking capabilities to communicate between the two devices, but this would be detectable when the USB port is plugged in.



          Ethernet cross-over cables and usb networking dongles are readily available, and the drivers well defined (obviously) for Windows and Ubuntu.






          share|improve this answer








          New contributor




          Keitai Otaku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • Sorry.I didn't explain well.My linux device is a microprocessor (Boundary Device)and has the micro USB connector on it.That device is then plugged into my PC. So the microprocessor is running the console application, but it waits for commands from my PC.When I connect using TCP/IP, it works great.I want this same feature with my USB.Right now, I can connect via USB, but it does not connect until I type something into my Putty console of my Windows device.I want my console application to detect if it has been connected to, and then send data first,instead of waiting until it has received data
            – miceandmon
            Nov 12 at 21:03











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1092313%2fdetecting-usb-port-connection%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          Well, there are some major issues with what you are suggesting. A normal USB cable is master->slave, which means that one machine is the controlling machine, and the other is a slave. Both a Windows machine and an Ubuntu machine, would both expect to be the host, controlling the USB operations as the USB-Master. There is nothing off-the-shelf that would change this relationship (but many embedded designs that switch host-slave relationships).



          HOWEVER, you can use a USB-Bridge (or Transfer) Cable to communicate over USB between two machines. I found this one on Amazon "Plugable Windows Transfer Cable". You should be able to use this to write a console application on both sides, but would require some experience with Windows and Linux drivers. Not trivial.



          I suppose one other idea, would be to use two USB network dongles, and connect them to each other with an ethernet cross-over cable, and setup a local network. You could still use your networking capabilities to communicate between the two devices, but this would be detectable when the USB port is plugged in.



          Ethernet cross-over cables and usb networking dongles are readily available, and the drivers well defined (obviously) for Windows and Ubuntu.






          share|improve this answer








          New contributor




          Keitai Otaku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • Sorry.I didn't explain well.My linux device is a microprocessor (Boundary Device)and has the micro USB connector on it.That device is then plugged into my PC. So the microprocessor is running the console application, but it waits for commands from my PC.When I connect using TCP/IP, it works great.I want this same feature with my USB.Right now, I can connect via USB, but it does not connect until I type something into my Putty console of my Windows device.I want my console application to detect if it has been connected to, and then send data first,instead of waiting until it has received data
            – miceandmon
            Nov 12 at 21:03















          up vote
          0
          down vote













          Well, there are some major issues with what you are suggesting. A normal USB cable is master->slave, which means that one machine is the controlling machine, and the other is a slave. Both a Windows machine and an Ubuntu machine, would both expect to be the host, controlling the USB operations as the USB-Master. There is nothing off-the-shelf that would change this relationship (but many embedded designs that switch host-slave relationships).



          HOWEVER, you can use a USB-Bridge (or Transfer) Cable to communicate over USB between two machines. I found this one on Amazon "Plugable Windows Transfer Cable". You should be able to use this to write a console application on both sides, but would require some experience with Windows and Linux drivers. Not trivial.



          I suppose one other idea, would be to use two USB network dongles, and connect them to each other with an ethernet cross-over cable, and setup a local network. You could still use your networking capabilities to communicate between the two devices, but this would be detectable when the USB port is plugged in.



          Ethernet cross-over cables and usb networking dongles are readily available, and the drivers well defined (obviously) for Windows and Ubuntu.






          share|improve this answer








          New contributor




          Keitai Otaku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • Sorry.I didn't explain well.My linux device is a microprocessor (Boundary Device)and has the micro USB connector on it.That device is then plugged into my PC. So the microprocessor is running the console application, but it waits for commands from my PC.When I connect using TCP/IP, it works great.I want this same feature with my USB.Right now, I can connect via USB, but it does not connect until I type something into my Putty console of my Windows device.I want my console application to detect if it has been connected to, and then send data first,instead of waiting until it has received data
            – miceandmon
            Nov 12 at 21:03













          up vote
          0
          down vote










          up vote
          0
          down vote









          Well, there are some major issues with what you are suggesting. A normal USB cable is master->slave, which means that one machine is the controlling machine, and the other is a slave. Both a Windows machine and an Ubuntu machine, would both expect to be the host, controlling the USB operations as the USB-Master. There is nothing off-the-shelf that would change this relationship (but many embedded designs that switch host-slave relationships).



          HOWEVER, you can use a USB-Bridge (or Transfer) Cable to communicate over USB between two machines. I found this one on Amazon "Plugable Windows Transfer Cable". You should be able to use this to write a console application on both sides, but would require some experience with Windows and Linux drivers. Not trivial.



          I suppose one other idea, would be to use two USB network dongles, and connect them to each other with an ethernet cross-over cable, and setup a local network. You could still use your networking capabilities to communicate between the two devices, but this would be detectable when the USB port is plugged in.



          Ethernet cross-over cables and usb networking dongles are readily available, and the drivers well defined (obviously) for Windows and Ubuntu.






          share|improve this answer








          New contributor




          Keitai Otaku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          Well, there are some major issues with what you are suggesting. A normal USB cable is master->slave, which means that one machine is the controlling machine, and the other is a slave. Both a Windows machine and an Ubuntu machine, would both expect to be the host, controlling the USB operations as the USB-Master. There is nothing off-the-shelf that would change this relationship (but many embedded designs that switch host-slave relationships).



          HOWEVER, you can use a USB-Bridge (or Transfer) Cable to communicate over USB between two machines. I found this one on Amazon "Plugable Windows Transfer Cable". You should be able to use this to write a console application on both sides, but would require some experience with Windows and Linux drivers. Not trivial.



          I suppose one other idea, would be to use two USB network dongles, and connect them to each other with an ethernet cross-over cable, and setup a local network. You could still use your networking capabilities to communicate between the two devices, but this would be detectable when the USB port is plugged in.



          Ethernet cross-over cables and usb networking dongles are readily available, and the drivers well defined (obviously) for Windows and Ubuntu.







          share|improve this answer








          New contributor




          Keitai Otaku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Keitai Otaku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered Nov 12 at 19:33









          Keitai Otaku

          463




          463




          New contributor




          Keitai Otaku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Keitai Otaku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Keitai Otaku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.












          • Sorry.I didn't explain well.My linux device is a microprocessor (Boundary Device)and has the micro USB connector on it.That device is then plugged into my PC. So the microprocessor is running the console application, but it waits for commands from my PC.When I connect using TCP/IP, it works great.I want this same feature with my USB.Right now, I can connect via USB, but it does not connect until I type something into my Putty console of my Windows device.I want my console application to detect if it has been connected to, and then send data first,instead of waiting until it has received data
            – miceandmon
            Nov 12 at 21:03


















          • Sorry.I didn't explain well.My linux device is a microprocessor (Boundary Device)and has the micro USB connector on it.That device is then plugged into my PC. So the microprocessor is running the console application, but it waits for commands from my PC.When I connect using TCP/IP, it works great.I want this same feature with my USB.Right now, I can connect via USB, but it does not connect until I type something into my Putty console of my Windows device.I want my console application to detect if it has been connected to, and then send data first,instead of waiting until it has received data
            – miceandmon
            Nov 12 at 21:03
















          Sorry.I didn't explain well.My linux device is a microprocessor (Boundary Device)and has the micro USB connector on it.That device is then plugged into my PC. So the microprocessor is running the console application, but it waits for commands from my PC.When I connect using TCP/IP, it works great.I want this same feature with my USB.Right now, I can connect via USB, but it does not connect until I type something into my Putty console of my Windows device.I want my console application to detect if it has been connected to, and then send data first,instead of waiting until it has received data
          – miceandmon
          Nov 12 at 21:03




          Sorry.I didn't explain well.My linux device is a microprocessor (Boundary Device)and has the micro USB connector on it.That device is then plugged into my PC. So the microprocessor is running the console application, but it waits for commands from my PC.When I connect using TCP/IP, it works great.I want this same feature with my USB.Right now, I can connect via USB, but it does not connect until I type something into my Putty console of my Windows device.I want my console application to detect if it has been connected to, and then send data first,instead of waiting until it has received data
          – miceandmon
          Nov 12 at 21:03


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1092313%2fdetecting-usb-port-connection%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Can I use Tabulator js library in my java Spring + Thymeleaf project?