Bonjour,

 

Thank you for your answer,

 

The DP5_Programmer's guide can be found here:

http://experimentationlab.berkeley.edu/sites/default/files/images/DP5_Programmers_Guide_A4.pdf

 

And the entire code is here (Python_SDK\pyDppUSB):

https://www.amptek.com/-/media/ametekamptek/documents/softwares/Python_SDK.zip?la=en

 

I run the pyDP5.py module (Python_SDK\pyDppUSB\pyDP5.py), and here is a 
selected part (from Python_SDK\pyDppUSB\DppLibusb.py) that I'm interested in. 
As I said, this code was provide by Amptek when I contacted them, but it's for 
demo only in python 2, and not offically supported (that's the reason why it's 
pretty "dirty", with the few correction I already added):

 

from vbfunctions import *
from vbclasses import *
import usb
import sys
import time
from dppStatus import *
import codecs

decode_hex = codecs.getdecoder("hex_codec")

LIBUSB_TIMEOUT = 500

#REQUEST_STATUS_PACKET = decode_hex('F5FA01010000FE0F')                  # 
Request Status Packet
REQUEST_STATUS_PACKET = '\xf5\xfa\x01\x01\x00\x00\xfe\x0f'


#-------------------------------------------------------------------------------
# DppLibusb Class
#-------------------------------------------------------------------------------
 
class DppLibusb():
    def __init__(self):
        self.VENDOR = 0x10C4
        self.PRODUCT = 0x842A
        self.CONFIGURATION = 1
        self.INTERFACE = 0
        self.ENDPOINT_IN = 0x81
        self.ENDPOINT_OUT = 0x02
     
        self.device = None
        self.handle = None

        self.device = usb.core.find(idVendor=0x10c4, idProduct=0x842a)
       

        #for bus in usb.busses():
        #   for dev in bus.devices:
        #      if dev.idVendor == self.VENDOR and dev.idProduct == self.PRODUCT:
        #         self.device = dev
       

        self.strStatus = str()
        self.bArrStatusIn = bytes()
        self.bArrBuffer = bytes()
        self.AckPid2 = bytes()
        self.AckMsg = str()
        #self.STATUS = STATUS
        self.DataRaw = bytes()
        self.Channels = int()
        self.Data = int()
        self.Header = bytes()
       

        self.bArrArrBuffer = bytearray()
       

        if self.open() == None:
            print (sys.stderr, "Unable to open DppLibusb device!")
            sys.exit()
        return None

    def isConnected(self):
        _ret = False
        iNumBytes = 0
        print("Get Status")
       
        try:
            iNumBytes = self.write(REQUEST_STATUS_PACKET, LIBUSB_TIMEOUT)
            
        except usb.USBError as err:
            pass
        if iNumBytes  > 0:
            print ('Bytes Out =',iNumBytes)     # debug
            try:
                
                self.bArrArrBuffer = self.read(128, LIBUSB_TIMEOUT)
                self.bArrStatusIn = bytearray(self.bArrArrBuffer)
                
            except usb.USBError as err:
                pass


            if len(self.bArrStatusIn) > 0:
                print ("STATUS.RAW type ", type(self.STATUS.RAW))
                self.STATUS.RAW = bytearray(self.bArrStatusIn[6:70])
                if len(self.STATUS.RAW) > 0:
                    Process_Status(self.STATUS)
                    if (self.STATUS.SerialNumber > 0):
                        _ret = True
        return _ret

 

 

 

While the iNumbytes get a value from the iNumBytes = 
self.write(REQUEST_STATUS_PACKET, LIBUSB_TIMEOUT) (which might be a wrong 
value), the self.bArrArrBuffer = self.read(128, LIBUSB_TIMEOUT) is never 
reached. So my guess is that the REQUEST_STATUS_PACKET is in the wrong format, 
thus my original question : how do I write and read instruction in hexadecimal 
? Is converting the whole instruction in string via REQUEST_STATUS_PACKET = 
'\xf5\xfa\x01\x01\x00\x00\xfe\x0f' correct ? (I doubt it is). Again, sorry for 
the "messy" code, and thanks for any answer provided.

 

Best regards

 

Raphaël

 

 

> Message du 21/11/19 10:11
> De : "Nicolas Pinault via pyusb-users" 

> A : pyusb-users@lists.sourceforge.net
> Copie à : "Nicolas Pinault" 
> Objet : Re: [pyusb-users] Writing and reading hexadecimal command
> 
>
Bonjour Raphaël,
> 
> You do not provide enought information.
> Can you provide a link to the DP5 documentation ?
> Can you provide a small code sample ?
> 
> Bonne journée,
> Nicolas
> 
> 
> Le 21/11/2019 à 09:43, raphael moreau a écrit :
>

> Good morning pyusb users,

>  

> I'm writing you this emial because I'm facing an issue that I did not succed 
> to resolve until now, and I'm sure you will.

>  

> I'm currently working on a Python project which involve the communication 
> witn an USB Device (DP5 Amptek SDD Detector, an x-ray detector), and after a 
> few test it seems that my device dont understand what I'm telling him to do.

>  

> I started with the basic, a Device Status request, which is the following 
> (.jgp screenshot, I hope you'll be able to see it):

> 

>  

> I tried the classic dev.write(x,test,x), with test = 
> '\xf5\xfa\x01\x01\x00\x00\xfe\x0f', or test = '\xf5\xfa1100\xfe\x0f' but the 
> expected result, which is the following(same here, .jpg screenshot):

> 

>  

> does not seems to be return with res = dev.read(x, length, x) with length = 
> 128 or length = 64 (seems odd to me for the 128 but i guess it's for the 
> array format?)

>  

>  

> My question is therefore quit simple, how do I pass and read thoses command ?

>  

> I'm using python 3, and I have no problem in term of identification of the 
> device, configuration, interface and endpoint IN and OUT, with pyusb.

>  

> The program I'm using is an old python 2 demo supplied by the manufacturer 
> which is not supported by them. 

> I precise that I'm rather new to USB and programming in general, so I 
> apologize if this question seems basic, or had already been answered to.

>  

> Thank you for any response,

>  

> Best regards,

>  

>  

>  

> Raphaël Moreau

>  

>  

>  

>  


>
>
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users



>





_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to