Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example Code #1

Open
KenwoodFox opened this issue Aug 25, 2021 · 9 comments
Open

Example Code #1

KenwoodFox opened this issue Aug 25, 2021 · 9 comments

Comments

@KenwoodFox
Copy link

Could i get some help putting some example code together? Ill add it to a PR maybe under /examples?

@brandonrc
Copy link
Contributor

# This is a sample Python script.
import pyhid_usb_relay

def off(relay):
    # If relay state is on (1) then we can turn it off.
    if relay.state:
        relay.toggle_state(1)
    else:
        print("The relay is already off")

def on(relay):
    # If relay state is not on (1) then we can turn it on.
    if not relay.state:
        relay.toggle_state(1)
    else:
        print("The relay is already on")

if __name__ == '__main__':
    relay1 = pyhid_usb_relay.find()
    on(relay1)

Hope this is not too late.

Basically you want to make a relay control object using the pyhid_usb_relay.find(). Once you set that variable then you can start toggeling it or getting state information from it.

I made two functions ON/OFF. With the current library you can only toggle which is not good enough for me. I want to make sure it is on or off before flipping the switch.

@KenwoodFox
Copy link
Author

# This is a sample Python script.
import pyhid_usb_relay

def off(relay):
    # If relay state is on (1) then we can turn it off.
    if relay.state:
        relay.toggle_state(1)
    else:
        print("The relay is already off")

def on(relay):
    # If relay state is not on (1) then we can turn it on.
    if not relay.state:
        relay.toggle_state(1)
    else:
        print("The relay is already on")

if __name__ == '__main__':
    relay1 = pyhid_usb_relay.find()
    on(relay1)

Hope this is not too late.

Basically you want to make a relay control object using the pyhid_usb_relay.find(). Once you set that variable then you can start toggeling it or getting state information from it.

I made two functions ON/OFF. With the current library you can only toggle which is not good enough for me. I want to make sure it is on or off before flipping the switch.

Awesome! you should put this under an /examples folder! :3

@brandonrc
Copy link
Contributor

I can make a pull request :P

This is not my repo

@KenwoodFox
Copy link
Author

I can make a pull request :P

This is not my repo

Oh, you can make a fork lol! just fork the repo and make a new PR!

@brandonrc
Copy link
Contributor

#2

Done

@williamblair333
Copy link

os version,windows 21h2
py version,3.9

When running example code above, I get error usb.core.NoBackendError: No backend available

@JPEWdev
Copy link
Owner

JPEWdev commented Sep 15, 2022

os version,windows 21h2 py version,3.9

When running example code above, I get error usb.core.NoBackendError: No backend available

I don't have a Windows machine to test, but this is because of pyusb, not pyhid-usb-relay. If you can figure out if we are missing some dependency there, we can add it to the poetry file to make it work

@williamblair333
Copy link

I lost my comment. libusb-win32-devel-filter-1.2.6.0.exe located here https://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/1.2.6.0/, following instructions from https://stackoverflow.com/questions/13773132/pyusb-on-windows-no-backend-available made the error go away. Now to figure out how to do something useful. I can't make the relay do anything with the example code yet.

Thanks.

@JPEWdev
Copy link
Owner

JPEWdev commented Sep 15, 2022

I recently update the example code in the repository because the original example was confusing, so make sure you are looking at that one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants