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.",
"UsbFTMLInterface::init");
58 error(
"Usb device already open.",
"UsbFTMLInterface::init");
64 error(
"Cannot find Usb Device "+
name()+
" with device description "+
69 info(
"Device with device description "+
m_deviceDesc+
" found.",
"UsbFTMLInterface::init");
70 info(
"Try to open device with serial number "+
m_serialNum+
".",
"UsbFTMLInterface::init");
74 error(
"Could not find device with serial number "+
m_serialNum,
"UsbFTMLInterface::init");
77 error(
"Serial number do not match first device found.",
"UsbFTMLInterface::init");
81 info(
"Extracted serial number "+std::string(serial)+
".",
"UsbFTMLInterface::init");
85 fatal(
"Device description do not match first device either. Abort",
86 "UsbFTMLInterface::init");
90 info(
"Device found. Extracted description "+std::string(desc)+
".",
91 "UsbFTMLInterface::init");
96 fatal(
"Cannot open device. Abort.",
"UsbFTMLInterface::init");
102 info(
"Device opened with UsbId "+
itos(
m_usbId)+
".",
"UsbFTMLInterface::init");
111 fatal(
"Could not initialize the USB device "+
name()+
". Abort.",
112 "UsbFTMLInterface::init");
115 info(
"Usb device initialization done.",
"UsbFTMLInterface::init");
138 unsigned long int nWords,
139 boost::python::list &
obj)
142 verbose(
"USB Reading :",
"UsbFTMLInterface::read");
147 unsigned char *
data=
new unsigned char[nWords];
148 status =
usbReadU8( address, nWords, data);
150 for(
unsigned int i = 0; i < nWords; i++){
159 unsigned short *
data=
new unsigned short[nWords];
162 for(
unsigned int i = 0; i < nWords; i++){
171 unsigned long *
data=
new unsigned long[nWords];
174 for(
unsigned int i = 0; i < nWords; i++){
182 error(
"Wrong word size.",
"UsbFTMLInterface::read");
192 boost::python::list
obj)
194 unsigned long int nWords = len(obj);
201 unsigned char *
data=
new unsigned char[nWords];
202 for(
unsigned int i = 0; i < nWords; i++){
203 data[i]=(boost::python::extract<unsigned char>(obj[i]));
213 unsigned short *
data=
new unsigned short[nWords];
214 for(
unsigned int i = 0; i < nWords; i++){
216 data[i]=(boost::python::extract<unsigned short>(obj[i]));
225 unsigned long *
data=
new unsigned long[nWords];
226 for(
unsigned int i = 0; i < nWords; i++){
227 data[i]=(boost::python::extract<unsigned long>(obj[i]));
236 error(
"Wrong word size.",
"read");
246 unsigned long int nWords,
247 std::vector<U32> &words)
250 verbose(
"USB Reading :",
"UsbFTMLInterface::read");
252 words.reserve(nWords);
257 unsigned char *
data=
new unsigned char[nWords];
258 status =
usbReadU8( address, nWords, data);
259 for(
unsigned int i = 0; i < nWords; i++){
261 words.push_back(data[i]);
268 unsigned short *
data=
new unsigned short[nWords];
270 for(
unsigned int i = 0; i < nWords; i++){
272 words.push_back(data[i]);
279 unsigned long *
data=
new unsigned long[nWords];
281 for(
unsigned int i = 0; i < nWords; i++){
283 words.push_back(data[i]);
289 error(
"Wrong word size.",
"UsbFTMLInterface::read");
299 std::vector<U32> words)
301 unsigned long int nWords = words.size();
308 unsigned char *
data=
new unsigned char[nWords];
309 for(
unsigned int i = 0; i < nWords; i++){
320 unsigned short *
data=
new unsigned short[nWords];
321 for(
unsigned int i = 0; i < nWords; i++){
332 unsigned long *
data=
new unsigned long[nWords];
333 for(
unsigned int i = 0; i < nWords; i++){
336 verbose(
"wd "+
itos(i)+
" "+
itos(data[i]) ,
"UsbFTMLInterface::usbWrite");
343 error(
"Wrong word size.",
"read");
352 unsigned long int nWords,
353 unsigned char *
data ) {
356 long int bytecount=0;
358 long int nData = (
long int)(nWords);
364 if (nData==bytecount){
366 "UsbFTMLInterface::usbRead8");
373 " UsbFTMLInterface::usbRead8");
381 error(
" O Byte read from USB interface "+
name()+
".",
"UsbFTMLInterface::usbRead8");
385 if (nData!=bytecount){
386 error(
itos(bytecount)+
" byte(s) read from USB interface "+
name()+
387 " out of "+
itos(nData)+
" bytes expected.",
"UsbFTMLInterface::usbRead8");
398 unsigned long int nWords,
399 unsigned short *
data ) {
402 long int bytecount=0;
407 long int nData = (
long int)(2*nWords);
409 unsigned char *buff=
new unsigned char [nData];
419 for (
unsigned long word=0; word<nWords; ++word)
421 data[word]=buff[2*word+1];
422 data[word]=(data[word]<<8)|buff[2*word];
427 if (nData==bytecount){
429 "UsbFTMLInterface::usbReadU16");
436 " UsbFTMLInterface::usbReadU16");
444 error(
" O Byte read from USB interface "+
name()+
".",
445 "UsbFTMLInterface::usbReadU16");
449 if (nData!=bytecount){
450 error(
itos(bytecount)+
" byte(s) read from USB interface "+
name()+
451 " out of "+
itos(nData)+
" bytes expected.",
452 "UsbFTMLInterface::usbReadU16");
463 unsigned long int nWords,
464 unsigned long *
data ) {
467 long int bytecount=0;
469 long int nData = (
long int)(4*nWords);
471 unsigned char *buff=
new unsigned char [nData];
477 for (
unsigned long word=0; word<nWords; ++word)
479 data[word]=buff[4*word+3];
480 data[word]=(data[word]<<8)|buff[4*word+2];
481 data[word]=(data[word]<<8)|buff[4*word+1];
482 data[word]=(data[word]<<8)|buff[4*word];
487 if (nData==bytecount){
489 "UsbFTMLInterface::usbRead");
496 " UsbFTMLInterface::usbRead32");
504 error(
" O Byte read from USB interface "+
name()+
".",
"UsbFTMLInterface::usbRead32");
508 if (nData!=bytecount){
509 error(
itos(bytecount)+
" byte(s) read from USB interface "+
name()+
510 " out of "+
itos(nData)+
" bytes expected.",
"UsbFTMLInterface::usbRead32");
520 unsigned long int nWords,
521 unsigned char *
data ) {
523 long int bytecount=0;
525 long int nData=(
long int)(nWords);
533 "UsbFTMLInterface::usbWrite8");
540 if (nData==bytecount){
542 "UsbFTMLInterface::usbWrite8");
546 error(
" O Byte written on USB interface "+
name()+
".",
"UsbFTMLInterface::usbWrite8");
550 if (nData!=bytecount){
551 error(
itos(bytecount)+
" byte(s) written on USB interface "+
name()+
552 " out of "+
itos(nData)+
" bytes to be sent.",
"UsbFTMLInterface::usbWrite8");
563 unsigned long int nWords,
564 unsigned short *
data ) {
566 long int bytecount=0;
568 long int nData=(
long int)(2*nWords);
576 "UsbFTMLInterface::usbWrite16");
583 if (nData==bytecount){
585 "UsbFTMLInterface::usbWrite16");
589 error(
" O Byte written on USB interface "+
name()+
".",
"UsbFTMLInterface::usbWrite16");
593 if (nData!=bytecount){
594 error(
itos(bytecount)+
" byte(s) written on USB interface "+
name()+
595 " out of "+
itos(nData)+
" bytes to be sent.",
"UsbFTMLInterface::usbWrite16");
606 unsigned long int nWords,
607 unsigned long *
data ) {
609 long int bytecount=0;
611 long int nData=(
long int)(4*nWords);
619 "UsbFTMLInterface::usbWrite32");
626 if (nData==bytecount){
628 "UsbFTMLInterface::usbWrite32");
632 error(
" O Byte written on USB interface "+
name()+
".",
"UsbFTMLInterface::usbWrite32");
636 if (nData!=bytecount){
637 error(
itos(bytecount)+
" byte(s) written on USB interface "+
name()+
638 " out of "+
itos(nData)+
" bytes to be sent.",
"UsbFTMLInterface::usbWrite32");
649 std::vector<U8> dataWrite,
650 std::vector<U8> &dataRead ) {
652 long int bytecount=0;
653 long int nData=dataWrite.size();
654 const unsigned long int bufSize=nData+4;
655 U8* bufWr=
new U8[bufSize];
656 U8* bufRd=
new U8[bufSize];
658 for(
int j=0; j<nData; ++j) bufWr[j] = static_cast<unsigned char>(dataWrite[j]);
666 " UsbFTMLInterface::usbWriteRead");
673 if (nData==bytecount){
675 "UsbFTMLInterface::usbWriteRead");
680 if (nData==bytecount){
682 "UsbFTMLInterface::usbRead");
683 for(
int j=0; j<nData; ++j) dataRead[j] = static_cast<unsigned char>(bufRd[j]);
690 " UsbFTMLInterface::usbWriteRead");
698 error(
" O Byte read from USB interface "+
name()+
".",
"UsbFTMLInterface::usbRead");
702 if (nData!=bytecount){
703 error(
itos(bytecount)+
" byte(s) read from USB interface "+
name()+
704 " out of "+
itos(nData)+
" bytes expected.",
"UsbFTMLInterface::usbRead");
711 error(
" O Byte written n USB interface "+
name()+
".",
"UsbFTMLInterface::usbWrite");
715 if (nData!=bytecount){
716 error(
itos(bytecount)+
" byte(s) written USB interface "+
name()+
717 " out of "+
itos(nData)+
" bytes to be sent.",
"UsbFTMLInterface::usbWrite");
741 unsigned long int address = io->
address();
742 unsigned long int nWords = io->
length();
750 "UsbFTMLInterface::read");
757 for (
int i=0; i<nXfer ; ++i){
761 "UsbFTMLInterface::read");
770 "UsbFTMLInterface::read");
772 nWords%m_rdBlockMax ,
774 data+=
sizeof(
U8*)*(nWords%m_rdBlockMax);
786 error(
"Wrong word size.",
"UsbFTMLInterface::read");
797 unsigned long int address = io->
address();
798 unsigned long int nWords = io->
length();
805 "UsbFTMLInterface::write");
811 int nXfer=(int)ceil((
float)(nWords)/(
float)(
m_wrBlockMax));
814 " "+
itos(nWords),
"");
815 for (
int i=0; i<nXfer ; ++i){
819 "UsbFTMLInterface::write");
829 " of size "+
itos(nwords),
830 "UsbFTMLInterface::write");
834 data+=
sizeof(
U8)*(nwords);
846 error(
"Wrong word size.",
"UsbFTMLInterface::read");
void info(std::string mymsg)
void verbose(std::string mymsg)
StatusCode usbReadU8(unsigned long int, unsigned long int, unsigned char *)
LALUSB_API BOOL _cstmcall USB_GetLatencyTimer(int id, PUCHAR msecs)
StatusCode usbWrite(unsigned long int, std::vector< U32 >)
LALUSB_API void _cstmcall USB_Perror(USB_Error err_code)
LALUSB_API BOOL _cstmcall USB_SetLatencyTimer(int id, UCHAR msecs)
void setName(std::string name)
StatusCode read(IOdata *)
StatusCode usbWriteU32(unsigned long int, unsigned long int, unsigned long *)
void fatal(std::string mymsg)
StatusCode write(IOdata *)
LALUSB_API BOOL _cstmcall USB_ResetDevice(int id)
LALUSB_API int _cstmcall OpenUsbDevice(char *sernumstr)
LALUSB_API FT_STATUS _cstmcall GetDeviceSerNum(char *buffer, int index)
void setType(std::string type)
LALUSB_API BOOL _cstmcall USB_ResetMode(int id)
void error(std::string mymsg)
LALUSB_API void _cstmcall CloseUsbDevice(int id)
def data(object, stream=None)
LALUSB_API BOOL _cstmcall USB_PurgeBuffers(int id)
LALUSB_API int _cstmcall UsbWrtML(int id, int *target_path_array, char sub_addr, void *buffer, int count)
LALUSB_API int _cstmcall UsbReadML(int id, int *target_path_array, char sub_addr, void *buffer, int usercount)
unsigned char m_latencyTimer
virtual StatusCode init()
StatusCode usbReadU16(unsigned long int, unsigned long int, unsigned short *)
StatusCode usbWriteRead(unsigned long int, std::vector< U8 >, std::vector< U8 > &)
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)
StatusCode usbReadU32(unsigned long int, unsigned long int, unsigned long *)
LALUSB_API BOOL _cstmcall USB_Init(int id, BOOL verbose)
LALUSB_API FT_STATUS _cstmcall GetDeviceDesc(char *buffer, int index)
LALUSB_API BOOL _cstmcall USB_SetSynchronousMode(int id, int sleep_time)
StatusCode usbWriteU16(unsigned long int, unsigned long int, unsigned short *)
StatusCode usbRead(unsigned long int, unsigned long int, std::vector< U32 > &)
LALUSB_API void _cstmcall UsbSetIntCheckingState(BOOL truefalse)
IOdata::WordSize wordSize()
LALUSB_API BOOL _cstmcall USB_SetXferSize(int id, unsigned long txsize, unsigned long rxsize)
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
std::string path(std::string=std::string(""))
LALUSB_API void _cstmcall PrintFrameInfo(void)