Code: Select all
sudo apt-get update
sudo apt-get install libusb-dev
git clone https://github.com/codazoda/hub-ctrl.c
cd hub-ctrl.c
gcc -o hub-ctrl hub-ctrl.c -lusb
cp hub-ctrl ..
cd ..The printer is being turned off by a relay board triggered by the GPIO pins so how would I be able to tell the raspberry to run this code to turn off the usb at the same time?At this point you're back where you started in the root but hub-ctrl will now function and can turn off your USB and Ethernet port. For a detailed walk through of what the commands above do
Update the list of what Linux updates/versions exist and where they are located
Install the current version of libusb-dev
Copy the source code of hub-ctrl.c to your machine
Change into the directory where the hub-ctrl.c code was copied
Compile it into an executable named hub-ctrl (note the lack of a .c)
Copy the compiled exectuable to the root directory
Change back into the root directory
Now it all comes down to running commands against your newly compiled hub-ctrl command.
To jump right into it, here are some examples:
Turn off Ethernet Port: sudo ./hub-ctrl -h 0 -P 1 -p 0
Turn on Ethernet Port: sudo ./hub-ctrl -h 0 -P 1 -p 1
Turn off all USB Ports: sudo ./hub-ctrl -h 0 -P 2 -p 0
Turn on all USB Ports: sudo ./hub-ctrl -h 0 -P 2 -p 1
Essentially the number after the -P determines the port while the number after the -p (case matters in Linux don't you know) determines the state (0 = off, 1 = on).
Now, the information elsewhere refers to shutting down individual ports and using values of -P to do it. They claim a -P 3 would shut down an individual port. My own experience is...no. While it did not throw an error, no USB devices shut down when attempting individual control. It only worked when I shut all USB ports down.
So to do a full USB reset via power-off/on you could munge together a command like this:
This would bounce all USB devices via a power off, wait 5 seconds, then power them all back on.Code: Select all
sudo ./hub-ctrl -h 0 -P 2 -p 0 ; sleep 5; sudo ./hub-ctrl -h 0 -P 2 -p 1;