Trying to send bytes over USB - python

I have downloaded Python 3.5, am using PyCharm, have downloaded a library for my bridge chip, MCP2210, am trying to communicate over USB after successfully communicating over the utility and terminal softwares that come with the chip. I found an instruction about using USB, copied:
import usb.core
import usb.util
tried to run, got an error message about Module not found: No module named 'usb'. What am I doing wrong?
Have I neglected to first download something?

Related

Access USB device on Mac in python using pyusb an libusb

I would like to read the signal from a USB keyboard that is attached to my MacBook Pro. I am using PyCharm to write my script and I installed pyusb and libusb for the backend. Really, I am at the very beginning so please excuse my little knowledge. The problems I am faced with is that I do [Errno 13] permission error when running the script in PyCharm or when saving it and running it with PyLauncher I get a "No backend available error".
The final aim of this project is to control the vlc-media player using the vlc module based on the input of a usb device.
The current code:
import usb
import libusb_package
backend = libusb_package.get_libusb1_backend()
# find device
keyboard = usb.core.find(idVendor=0x046d, idProduct=0xc318, backend = backend)
if keyboard is None:
raise ValueError('ADU Device not found. Please ensure it is connected.')
sys.exit(1)
usb.util.claim_interface(keyboard, 0)
I would really appreciate any hints or suggestions what packages to use, which tutorials to read for usb devices and python and how to improve in this project.
Thank you very much!
All the best,
ie

PyVisa - Cannot connect via VICP but TCPIP works?

I am having an issue connect to a LeCroy oscilloscope using PyVisa v1.9.
If I trying to connect using the code:
import visa
from pyvisa.resources import MessageBasedResource
visa.log_to_screen()
rm = visa.ResourceManager()
my_instrument = rm.open_resource('VICP::10.2.72.141:INSTR', resource_pyclass=MessageBasedResource)
I get the error: VisaIOError: VI_ERROR_RSRC_NFOUND (-1073807343): Insufficient location information or the requested device or resource is not present in the system.
However, if I change to:
my_instrument = rm.open_resource('TCPIP::10.2.72.141:INSTR', resource_pyclass=MessageBasedResource)
The code with connect with the instrument, but the functions in my driver no longer work. Read commands also respond with:
‘WARNING : CURRENT REMOTE CONTROL INTERFACE IS TCPIP’
I never saw an issue before moving to version 1.9 of pyvisa.
Python version is 2.7 64-bit, running on windows 10 64bit
Any hints would be appreciated.

Import error while calling from IIS hosted .NET Core API

I am facing the below issue while running a python script from a .NET Core api which is hosted in windows server IIS .I am using pyrfc 1.9.5 SAP connector in this script. Here is the code below
from pyrfc import Connection
def GetConnection(connmeta):
return Connection(**connmeta)
Here is the error which I got -
from pyrfc import Connection
File "<C:\Program Files\Python35\lib\site-packages\pyrfc-1.9.5-py3.5-win-amd64.egg\pyrfc_init_.py>", line 22, in
from pyrfc._pyrfc import get_nwrfclib_version, Connection, TypeDescription, FunctionDescription, Server
ImportError: DLL load failed: The specified module could not be found
It's working fine from the command prompt, python IDLE, Powershell etc. Previously I got this error when the visual c++ redistributable package was not installed. But now it is installed properly as the same script is working from IDLE and Powershell.
Here are the installed software and server details -
windows server 2016 64 bit
Visual C++ 2013 redistributable 64 bit
Python 3.5 64 bit,
pyrfc 1.9.5 for python 3.5 64 bit (amd64)
SAP NW RFC SDK 7.5.0 64 bit
Python executable and the path to the lib folder of the SDK is already added to the Environment variable. I have also tried to execute the sample rfcexec.exe program from the bin directory it's working fine. I am only getting the error while running the application from IIS. The app pool identity has full permission on the python scripts.
The script is working fine from IIS if I comment the pyrfc import part.
Please help .
Finally I have found the solution after debugging for atleast 1 week. The problem was access related issue. the SAP NW RFC SDK was installed in the path C:\nwrfcsdk\lib as per the documentation.
link : Installation documentation
But the user account under which the .NET Core API was running in the application pool of IIS didn't have any read/write access to this nwrfcsdk folder. Hence pyrfc was not able to import the DLL (SAPNWRFC.dll) when the python script was being called from the .NET Core API.I have provided read/write access to that particular account and the script is running fine now .
I have followed the below steps to debug the diagnose the issue -
I have used profiling with Procmon.exe from sysinternals to monitor w3wp.exe IIS worker process and python.exe after calling the API
I have also used dependency walker to track the dependent dll.
Hope this helps someone who is facing a similar type of issue.

Find mounted volumes and mountpoint of USB hard drives

I am trying to write a Python script to identify USB devices that did not get auto-mounted correctly in Linux. I am currently using subprocess and calling lsusb to gather the USB devices and then using PyUsb (A libusb 1.0 python wrap library) to find the category of the USB device so I can identify if it is a Mass Storage Media. What I can't figure out is how to bridge the information I have into the mountpoint that belongs to that USB drive. I need a combination of Linux commands that will get me the information I can use to link a mountpoint to a specific USB device so I can use subprocess and some basic parsing to create the script. Or maybe some other way to do this with Python modules I haven't thought of using.
I found a way to do it using information from mount and fdisk. I wrote a python module that encapsulates everything if anyone has the need for something similar: https://github.com/arthurbayerlein/Python/blob/master/storage_media.py

USB-to-serial driver for Linux

I have a USB device that I need to control in Linux using Python and serial commands, it works with ASCII commands.
In Windows it works fine after I install the vendor driver and in Device Manager I see it as a COM3 port and I communicate using pyserial or pyvisa modules.
In Linux I see it as /dev/ttyUSB1 but I cannot communicate with it using pyserial or pyvisa. The problem is that the vendor doesn't provide Linux drivers.
How am I able to get the device behave as a serial port in Linux?
try python -m serial.tools.miniterm /dev/ttyUSB1 and read the issue on https://github.com/pyserial/pyserial/issues/67 especially the version of pyserial
if this issue is related to yours possibly this also works :
Managed to bypass this issue by passing dsrdtr=True and rtscts=True to
serial.Serial() ... as described here
your device is based on an FTDI chip, the inbuilt linux kernel module for this is ftdi_sio and usb_serial see http://www.ftdichip.com/Support/Documents/AppNotes/AN_220_FTDI_Drivers_Installation_Guide_for_Linux.pdf

Categories