dancingquanta / pyusbiss Goto Github PK
View Code? Open in Web Editor NEWPython API for USB-ISS Multifunction USB Communications Module
License: MIT License
Python API for USB-ISS Multifunction USB Communications Module
License: MIT License
### 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
```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'
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.
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?
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.
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
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.
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 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.
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.
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)
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
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
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.
Testing the usbiss base class and ISP protocol class gave some runtime errors, as the class properties where defined with the self. prefix.
correct the typos in usbiss and spi class.
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
Tried to use the latest usbiss.py version and got a syntax error on
raise USBISSError(error_dict[response(1)])
corrected the usbiss.py:
raise USBISSError(error_dict[response[1]])
Adapted my i2c module succesfully to reflect the new mode setup.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.