21 m_serialNum(
std::string(
"None")),
22 m_deviceDesc(
std::string(
"None")),
34 m_showEpromState(false),
39 info(
"Todo : time efficiency by creating the buffer once for all ?");
48 unsigned char msecs=0;
55 info(
"Start USB device initialisation.",
"UsbFTInterface::init");
59 error(
"Usb device already open.",
"UsbFTInterface::init");
65 error(
"Cannot find Usb Device "+
name()+
" with device description "+
70 info(
"Device with device description "+
m_deviceDesc+
" found.",
"UsbFTInterface::init");
71 info(
"Try to open device with serial number "+
m_serialNum+
".",
"UsbFTInterface::init");
75 error(
"Could not find device with serial number "+
m_serialNum,
"UsbFTInterface::init");
78 error(
"Serial number do not match first device found.",
"UsbFTInterface::init");
82 info(
"Extracted serial number "+std::string(serial)+
".",
"UsbFTInterface::init");
86 fatal(
"Device description do not match first device either. Abort",
87 "UsbFTInterface::init");
91 info(
"Device found. Extracted description "+std::string(desc)+
".",
92 "UsbFTInterface::init");
97 fatal(
"Cannot open device. Abort.",
"UsbFTInterface::init");
102 info(
"Device opened with UsbId "+
itos(
m_usbId)+
".",
"UsbFTInterface::init");
111 fatal(
"Could not initialize the USB device "+
name()+
". Abort.",
112 "UsbFTInterface::init");
115 info(
"Usb device initialization done.",
"UsbFTInterface::init");
143 unsigned long int nWords,
144 boost::python::list &
obj)
147 verbose(
"USB Reading :",
"UsbFTInterface::read");
152 unsigned char *
data=
new unsigned char[nWords];
153 status =
usbReadU8( address, nWords, data);
155 for(
unsigned int i = 0; i < nWords; i++){
164 unsigned short *
data=
new unsigned short[nWords];
167 for(
unsigned int i = 0; i < nWords; i++){
176 unsigned long *
data=
new unsigned long[nWords];
179 for(
unsigned int i = 0; i < nWords; i++){
187 error(
"Wrong word size.",
"UsbFTInterface::read");
197 boost::python::list
obj)
199 unsigned long int nWords = len(obj);
206 unsigned char *
data=
new unsigned char[nWords];
207 for(
unsigned int i = 0; i < nWords; i++){
208 data[i]=(boost::python::extract<unsigned char>(obj[i]));
218 unsigned short *
data=
new unsigned short[nWords];
219 for(
unsigned int i = 0; i < nWords; i++){
221 data[i]=(boost::python::extract<unsigned short>(obj[i]));
230 unsigned long *
data=
new unsigned long[nWords];
231 for(
unsigned int i = 0; i < nWords; i++){
232 data[i]=(boost::python::extract<unsigned long>(obj[i]));
241 error(
"Wrong word size.",
"read");
251 unsigned long int nWords,
252 std::vector<U32> &words)
255 verbose(
"USB Reading :",
"UsbFTInterface::read");
257 words.reserve(nWords);
262 unsigned char *
data=
new unsigned char[nWords];
263 status =
usbReadU8( address, nWords, data);
264 for(
unsigned int i = 0; i < nWords; i++){
266 words.push_back(data[i]);
273 unsigned short *
data=
new unsigned short[nWords];
275 for(
unsigned int i = 0; i < nWords; i++){
277 words.push_back(data[i]);
284 unsigned long *
data=
new unsigned long[nWords];
286 for(
unsigned int i = 0; i < nWords; i++){
288 words.push_back(data[i]);
294 error(
"Wrong word size.",
"UsbFTInterface::read");
304 std::vector<U32> words)
306 unsigned long int nWords = words.size();
313 unsigned char *
data=
new unsigned char[nWords];
314 for(
unsigned int i = 0; i < nWords; i++){
325 unsigned short *
data=
new unsigned short[nWords];
326 for(
unsigned int i = 0; i < nWords; i++){
337 unsigned long *
data=
new unsigned long[nWords];
338 for(
unsigned int i = 0; i < nWords; i++){
348 error(
"Wrong word size.",
"read");
439 unsigned long int nWords,
440 unsigned char *
data ) {
443 long int bytecount=0;
445 long int nData = (
long int)(nWords);
449 if (nData==bytecount){
451 "UsbFTInterface::usbRead8");
458 " UsbFTInterface::usbRead8");
466 error(
" O Byte read from USB interface "+
name()+
".",
"UsbFTInterface::usbRead8");
470 if (nData!=bytecount){
471 error(
itos(bytecount)+
" byte(s) read from USB interface "+
name()+
472 " out of "+
itos(nData)+
" bytes expected.",
"UsbFTInterface::usbRead8");
483 unsigned long int nWords,
484 unsigned short *
data ) {
487 long int bytecount=0;
492 long int nData = (
long int)(2*nWords);
494 unsigned char *buff=
new unsigned char [nData];
501 for (
unsigned long word=0; word<nWords; ++word)
503 data[word]=buff[2*word+1];
504 data[word]=(data[word]<<8)|buff[2*word];
509 if (nData==bytecount){
511 "UsbFTInterface::usbReadU16");
518 " UsbFTInterface::usbReadU16");
526 error(
" O Byte read from USB interface "+
name()+
".",
527 "UsbFTInterface::usbReadU16");
531 if (nData!=bytecount){
532 error(
itos(bytecount)+
" byte(s) read from USB interface "+
name()+
533 " out of "+
itos(nData)+
" bytes expected.",
534 "UsbFTInterface::usbReadU16");
545 unsigned long int nWords,
546 unsigned long *
data ) {
549 long int bytecount=0;
551 long int nData = (
long int)(4*nWords);
553 unsigned char *buff=
new unsigned char [nData];
557 for (
unsigned long word=0; word<nWords; ++word)
559 data[word]=buff[4*word+3];
560 data[word]=(data[word]<<8)|buff[4*word+2];
561 data[word]=(data[word]<<8)|buff[4*word+1];
562 data[word]=(data[word]<<8)|buff[4*word];
567 if (nData==bytecount){
569 "UsbFTInterface::usbRead");
576 " UsbFTInterface::usbRead32");
584 error(
" O Byte read from USB interface "+
name()+
".",
"UsbFTInterface::usbRead32");
588 if (nData!=bytecount){
589 error(
itos(bytecount)+
" byte(s) read from USB interface "+
name()+
590 " out of "+
itos(nData)+
" bytes expected.",
"UsbFTInterface::usbRead32");
600 unsigned long int nWords,
601 unsigned char *
data ) {
603 long int bytecount=0;
605 long int nData=(
long int)(nWords);
612 "UsbFTInterface::usbWrite8");
619 if (nData==bytecount){
621 "UsbFTInterface::usbWrite8");
625 error(
" O Byte written on USB interface "+
name()+
".",
"UsbFTInterface::usbWrite8");
629 if (nData!=bytecount){
630 error(
itos(bytecount)+
" byte(s) written on USB interface "+
name()+
631 " out of "+
itos(nData)+
" bytes to be sent.",
"UsbFTInterface::usbWrite8");
642 unsigned long int nWords,
643 unsigned short *
data ) {
645 long int bytecount=0;
647 long int nData=(
long int)(2*nWords);
654 "UsbFTInterface::usbWrite16");
661 if (nData==bytecount){
663 "UsbFTInterface::usbWrite16");
667 error(
" O Byte written on USB interface "+
name()+
".",
"UsbFTInterface::usbWrite16");
671 if (nData!=bytecount){
672 error(
itos(bytecount)+
" byte(s) written on USB interface "+
name()+
673 " out of "+
itos(nData)+
" bytes to be sent.",
"UsbFTInterface::usbWrite16");
684 unsigned long int nWords,
685 unsigned long *
data ) {
687 long int bytecount=0;
689 long int nData=(
long int)(4*nWords);
696 "UsbFTInterface::usbWrite32");
703 if (nData==bytecount){
705 "UsbFTInterface::usbWrite32");
709 error(
" O Byte written on USB interface "+
name()+
".",
"UsbFTInterface::usbWrite32");
713 if (nData!=bytecount){
714 error(
itos(bytecount)+
" byte(s) written on USB interface "+
name()+
715 " out of "+
itos(nData)+
" bytes to be sent.",
"UsbFTInterface::usbWrite32");
726 std::vector<U8> dataWrite,
727 std::vector<U8> &dataRead ) {
729 long int bytecount=0;
730 long int nData=dataWrite.size();
731 const unsigned long int bufSize=nData+4;
732 U8* bufWr=
new U8[bufSize];
733 U8* bufRd=
new U8[bufSize];
735 for(
int j=0; j<nData; ++j) bufWr[j] = static_cast<unsigned char>(dataWrite[j]);
742 " UsbFTInterface::usbWriteRead");
749 if (nData==bytecount){
751 "UsbFTInterface::usbWriteRead");
755 if (nData==bytecount){
757 "UsbFTInterface::usbRead");
758 for(
int j=0; j<nData; ++j) dataRead[j] = static_cast<unsigned char>(bufRd[j]);
765 " UsbFTInterface::usbWriteRead");
773 error(
" O Byte read from USB interface "+
name()+
".",
"UsbFTInterface::usbRead");
777 if (nData!=bytecount){
778 error(
itos(bytecount)+
" byte(s) read from USB interface "+
name()+
779 " out of "+
itos(nData)+
" bytes expected.",
"UsbFTInterface::usbRead");
786 error(
" O Byte written n USB interface "+
name()+
".",
"UsbFTInterface::usbWrite");
790 if (nData!=bytecount){
791 error(
itos(bytecount)+
" byte(s) written USB interface "+
name()+
792 " out of "+
itos(nData)+
" bytes to be sent.",
"UsbFTInterface::usbWrite");
818 unsigned long int address = io->
address();
819 unsigned long int nWords = io->
length();
826 "UsbFTInterface::read");
833 for (
int i=0; i<nXfer ; ++i){
837 "UsbFTInterface::read");
846 "UsbFTInterface::read");
848 nWords%m_rdBlockMax ,
850 data+=
sizeof(
U8*)*(nWords%m_rdBlockMax);
862 error(
"Wrong word size.",
"UsbFTInterface::read");
872 unsigned long int address = io->
address();
873 unsigned long int nWords = io->
length();
880 "UsbFTInterface::write");
886 int nXfer=(int)ceil((
float)(nWords)/(
float)(
m_wrBlockMax));
889 " "+
itos(nWords),
"");
890 for (
int i=0; i<nXfer ; ++i){
894 "UsbFTInterface::write");
904 " of size "+
itos(nwords),
905 "UsbFTInterface::write");
909 data+=
sizeof(
U8)*(nwords);
921 error(
"Wrong word size.",
"UsbFTInterface::read");
void info(std::string mymsg)
void verbose(std::string mymsg)
StatusCode usbRead(unsigned long int, unsigned long int, std::vector< U32 > &)
StatusCode usbReadU8(unsigned long int, unsigned long int, unsigned char *)
LALUSB_API BOOL _cstmcall USB_GetLatencyTimer(int id, PUCHAR msecs)
LALUSB_API void _cstmcall USB_Perror(USB_Error err_code)
StatusCode usbWrite(unsigned long int, std::vector< U32 >)
StatusCode usbWriteRead(unsigned long int, std::vector< U8 >, std::vector< U8 > &)
LALUSB_API BOOL _cstmcall USB_SetLatencyTimer(int id, UCHAR msecs)
void setName(std::string name)
LALUSB_API int _cstmcall UsbRd(int id, char sub_addr, void *array, int count)
void fatal(std::string mymsg)
LALUSB_API int _cstmcall OpenUsbDevice(char *sernumstr)
LALUSB_API FT_STATUS _cstmcall GetDeviceSerNum(char *buffer, int index)
void setType(std::string type)
StatusCode read(IOdata *)
void error(std::string mymsg)
LALUSB_API void _cstmcall CloseUsbDevice(int id)
def data(object, stream=None)
StatusCode usbWriteU32(unsigned long int, unsigned long int, unsigned long *)
StatusCode usbWriteU16(unsigned long int, unsigned long int, unsigned short *)
StatusCode usbWriteU8(unsigned long int, unsigned long int, unsigned char *)
LALUSB_API BOOL _cstmcall USB_SetTimeouts(int id, int tx_timeout, int rx_timeout)
LALUSB_API BOOL _cstmcall USB_FindDevices(char *DeviceDescriptionStr)
LALUSB_API BOOL _cstmcall USB_Init(int id, BOOL verbose)
unsigned char m_latencyTimer
StatusCode write(IOdata *)
LALUSB_API FT_STATUS _cstmcall GetDeviceDesc(char *buffer, int index)
LALUSB_API int _cstmcall UsbWrt(int id, char sub_addr, void *buffer, int count)
LALUSB_API void _cstmcall UsbSetIntCheckingState(BOOL truefalse)
IOdata::WordSize wordSize()
StatusCode usbReadU16(unsigned long int, unsigned long int, unsigned short *)
StatusCode usbReadU32(unsigned long int, unsigned long int, unsigned long *)
virtual StatusCode init()
LALUSB_API BOOL _cstmcall USB_SetXferSize(int id, unsigned long txsize, unsigned long rxsize)
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
LALUSB_API void _cstmcall PrintFrameInfo(void)