Code Monkey home page Code Monkey logo

pyusbiss's People

Contributors

dancingquanta avatar dependabot[bot] avatar dhhagan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyusbiss's Issues

attributeError: 'module' object has no attribute 'USBISS'

  • pyusbiss version: 0.1.2
  • Python version: 3.4.2
  • Operating System: Raspbian

### Description

Hey Dancing Quanta,
Following your patch to pyusbiss, establishing communication to a alphasense OPC is greeted by an error: attributeError: 'module' object has no attribute 'USBISS'.

This is using dhhagan's sample script from py-opc to connect the sensor to Rpi via USB interface, line 5: s_pi = usbiss.USBISS("/dev/ttyACM0", "spi", spi_mode=1, freq=500000)_

Looking into the script of usbiss.py, i am unsure how to adjust to make the class USBISS work. Would you have any advice?

Thank you,
Zanati123

### What I Did

  • Factory reset Raspian and updated all
  • Downloaded and installed py-opc & pyusbiss
  • Using python 3.4.2, copied dhhagan's sample script to connect sensor via USB interface.
  • Error in spi = usbiss.USBISS("/dev/ttyACM0", "spi", spi_mode=1, freq=500000), error message attributeError: 'module' object has no attribute 'USBISS'

```import usbiss
import opc

# Build the connector
spi = usbiss.USBISS("/dev/ttyACM0", "spi", spi_mode=1, freq=500000)

alpha = opc.OPCN2(spi)

# Turn on the device
alpha.on()

# Read the histogram
alpha.histogram()

# Turn the device off
alpha.off()

-------------------------------------------------
>>>Traceback (most recent call last):
  File "/home/pi/test1.py", line 5, in <module>
    spi = usbiss.USBISS("/dev/ttyACM0", "spi", spi_mode=1, freq=500000)
AttributeError: 'module' object has no attribute 'USBISS'










Add GPIO support

on IO :
When I look at the RPI.GPIO and https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/FT232H.py (and pyftfi) the instance is a spichannel or a pin. Up until now the instance in my implementation has been the USBISS module itself :

t=GPIO('COM3', 'input', 'output', 'input', 'adc')
# default GPIO function for pin 1..4
t.SetPinOn(2) # set Led connected to pin 2

RPI / pyftdi / FT232H.py

#init
led = gpio.GPIO(17)
led.setDirection(1)
led.setValue(1)

Would you agree to the following :

t=GPIO('COM3')
led = t.IO.pin(2) #
led.setDirection(OUTPUT)
led.setValue(HIGH)  

We can discuss the exact names for the methods.
SPI / I2C / Serial are modes that have a single instance and fixed HW pins associated, whereas GPIO is configurable per pin as input, output or ADC.

Proper Releases

  • pyusbiss version: all
  • Python version: all
  • Operating System: all

It may be a good idea to start "releasing" the library in a more structured way; I noticed that there is currently no way for me to easily download the previous version of the code, which means I have to always keep the py-opc library up to date with what is happening here. While I try to do that as best as possible, it would be nice to be able to point people to specific releases!

It's as easy as just going to the "Releases" tab and using the GUI to make one. Does that seem reasonable?

Feasibility of a class for each USBISS mode

I wanted to start a discussion on how the code for USBISS should be structured.
The motivation for this discussion is because some people are starting to develop on top of my library and I wanted to make that easier.

My proposal is to restructure the code so that there will be a base class containing functions that mediates connections to USBISS from the host.
Then separate classes for each USBISS mode in its own file which inherits the base class.

I love to know your thoughts on this.

CC: @dhhagan, @vignkri and @gwdehaan

Sending data through USBISS

I am currently working on project in i am using usbiss module along with attached the DAC70502 and i am trying to read power on power meter attached at the end of circuitry. The thing is i am having hard time in sending the data through DAC because i could able to access it yet. It would be helpful if you can guide me in this and i also possess MATLAB code which is giving results but i get stuck in python.
what further can be done in this code to write in DAC registers?

Thanks in advance

Issue with Python3.2 handling of byte arrays

  • pyusbiss version: 0.1.0
  • Python version: 3.2.3
  • Operating System: Raspbian

Description

Using Python3.2, upon initialization of the opc.OPCN2 class, an error is thrown due to the way byte arrays are handled in python3 vs python2.

What I Did

TypeError: 'int' does not support the buffer interface

decoded = [struct.unpack('B', response[i + 1])[0] for i in range(0, len(data))]

This is a fairly straightforward fix..I think the bytes need to be sent as arrays...I'll take a look at it tomorrow morning.

NOTE: I was able to get this up and running with Python2.7 without any issues.

SPI driver creating an usbiss instance.

  • pyusbiss version: 0.2.2
  • Python version: 3.6
  • Operating System: Windows10

Description

SPI is the only usbiss mode that does not allow any coexistence with another protocol, as it uses all 4 available pins.
Therefore in the current implementation of SPI it made sense to open the COM port within the SPI driver.

What I Did

As I2C, Serial and GPIO can be used in combination with each other and therefor it is not possible to open usbiss within
The driver, you can only open the COM port once. These 3 drivers expect the user to instantiate a usbiss class and then pass on the instance to the driver.

Example

from usbiss import usbiss
from usbiss import gpio
from usbiss import i2c

port = 'COM3'
# open the COM port for the USBISS
usbissdev = usbiss.USBISS(port)
# use the GPIO in I2C mode (2 pins available for GPIO)
io2 = gpio.GPIO(usbissdev, gpio.I2C)
io2.setup(1, gpio.OUT)
io2.output(1, gpio.HIGH)
io2.setup(2, gpio.IN)
# Open an i2c channel
i2c_chan = I2C.I2C(usbissdev, 'H', 100)

Proposal

To prevent having 2 different driver architectures I would like to suggest to adapt the SPI driver to the same setup.

Current :

def __init__(self, port, mode=0, max_speed_hz=3000000):
    self._usbiss = USBISS(port)

Proposal :

def __init__(self, usbissdev, mode=0, max_speed_hz=3000000):
    self._usbiss = usbissdev

HELP: What I am doing wrong here with SPI ?

  • pyusbiss version: 0.2.2
  • Python version: 3.6.9
  • Operating System: Ubuntu 18.04

Description

Describe what you were trying to get done.
I am trying to read readings from OPC N2 sensor via SPI
I am using the library https://github.com/dhhagan/py-opc which using this library to access the OPC N2.

Tell us what happened, what went wrong, and what you expected to happen.
I am getting this error when I run the test

python test-device.py
Traceback (most recent call last):
File "test-device.py", line 10, in
spi = SPI("/dev/ttyUSB0")
File "/root/spi_dev/lib/python3.6/site-packages/usbiss/spi.py", line 16, in init
self._usbiss = USBISS(port)
File "/root/spi_dev/lib/python3.6/site-packages/usbiss/usbiss.py", line 63, in init
self.get_iss_info()
File "/root/spi_dev/lib/python3.6/site-packages/usbiss/usbiss.py", line 110, in get_iss_info
raise USBISSError("Could not get version details")
usbiss.usbiss.USBISSError: Could not get version details

What I Did

I have connected OPC n2 via spi to adafruit ft232H board.
Connections
OPC FT232H

5V <------> 5V
GND <------> GND
MOSI <------> D1
MISO <------> D2
SCK <------> D0
SS <------> C0

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

USBISS

  • pyusbiss version: 0.1.0
  • Python version: 3.6.0
  • Operating System: WIN10

Description

Testing the usbiss base class and ISP protocol class gave some runtime errors, as the class properties where defined with the self. prefix.

What I Did

  1. correct the typos in usbiss and spi class.

  2. in the 'old' module versioninfo was shown by default, you now added the _repr() method, but it is never called within the module, so I was wondering how you intended to use this.

for now I added it to the USBISS.init()

    def __init__(self, port):

        # Open serial port
        serial_opts = {"port": port,
                       "baudrate": 9600,
                       "parity": serial.PARITY_NONE,
                       "bytesize": serial.EIGHTBITS,
                       "stopbits": serial.STOPBITS_ONE,
                       "xonxoff": False,
                       "timeout": 1}
        self.serial = serial.Serial(**serial_opts)
        self.get_iss_info()
        self.get_iss_serial_no()
        print(self.__repr__())

with these changes I succesfully ran the following test. As I don't have a spi device at this point in time I can only confirm that spi initialisation works

from spi import SPI

t=SPI('COM3', spi_mode = 1, freq = 25000)

Output :

36-32/python.exe c:\Users\Geert\Documents\Project\pyusbiss\usbiss\spi-test.py
The module ID is 7
The firmware version is 0x4
The current operating mode is 0x91
The serial number is b'00006910'

Edits : typos

USBISS - Syntax error

  • pyusbiss version: 0.2.2
  • Python version: 3.6
  • Operating System: WIN10

Description

Tried to use the latest usbiss.py version and got a syntax error on

raise USBISSError(error_dict[response(1)])

What I Did

corrected the usbiss.py:

raise USBISSError(error_dict[response[1]])

Adapted my i2c module succesfully to reflect the new mode setup.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.