Cat
Public Types | Public Member Functions | Private Attributes | List of all members
UsbFTMLInterface Class Reference

#include <include/UsbFTMLInterface.h>

Inheritance diagram for UsbFTMLInterface:
Interface Element Hierarchy Object Attrib

Public Types

enum  WordSize { WS_Byte =1, WS_Word, WS_DWord }
 
enum  IOMode {
  USB_IORead, USB_IOWrite, USB_IOReadWrite, USB_WriteReadBurst,
  USB_IOExtebdedRead
}
 
typedef unsigned long U32
 
typedef unsigned short U16
 
typedef unsigned char U8
 
- Public Types inherited from Attrib
enum  Attribut {
  UNDEFINED, PASSIVE, ACTIVE, INTERFACE,
  IO, IODATA, ELEMENT, HARDWARE,
  PROCESSUS, SOFTWARE
}
 

Public Member Functions

 UsbFTMLInterface ()
 
virtual ~UsbFTMLInterface ()
 
virtual void help ()
 
virtual StatusCode init ()
 
void close ()
 
virtual void reset ()
 
virtual void update ()
 
StatusCode read (IOdata *)
 
StatusCode write (IOdata *)
 
StatusCode read (unsigned long int, unsigned long int, boost::python::list &)
 
StatusCode write (unsigned long int, boost::python::list)
 
StatusCode usbRead (unsigned long int, unsigned long int, std::vector< U32 > &)
 
StatusCode usbWrite (unsigned long int, std::vector< U32 >)
 
StatusCode usbReadU8 (unsigned long int, unsigned long int, unsigned char *)
 
StatusCode usbReadU16 (unsigned long int, unsigned long int, unsigned short *)
 
StatusCode usbReadU32 (unsigned long int, unsigned long int, unsigned long *)
 
StatusCode usbWriteU8 (unsigned long int, unsigned long int, unsigned char *)
 
StatusCode usbWriteU16 (unsigned long int, unsigned long int, unsigned short *)
 
StatusCode usbWriteU32 (unsigned long int, unsigned long int, unsigned long *)
 
StatusCode usbWriteRead (unsigned long int, std::vector< U8 >, std::vector< U8 > &)
 
void setUsbId (int usbId)
 
int usbId ()
 
void setSerialNum (std::string serialNum)
 
std::string serialNum ()
 
void setDeviceDesc (std::string deviceDesc)
 
std::string deviceDesc ()
 
void setLatencyTimer (unsigned char latencyTimer)
 
unsigned char latencyTimer ()
 
void setTimeOut (int txTimeOut, int rxTimeOut)
 
int txTimeOut ()
 
int rxTimeOut ()
 
void setBuffer (int txBuffer, int rxBuffer)
 
int txBuffer ()
 
int rxBuffer ()
 
void setNFrames (long int nFrames)
 
long int nFrames ()
 
void setWordCount (unsigned long wordCount)
 
unsigned long wordCount ()
 
void setWordSize (unsigned long wordSize)
 
unsigned long wordSize ()
 
void setFakeErr (unsigned int fakeErr)
 
unsigned int fakeErr ()
 
void setInterrupts (bool interrupts)
 
bool interrupts ()
 
void setShowEpromState (bool showEpromState)
 
bool showEpromState ()
 
bool wrBlockMax ()
 
void setWrBlockMax (bool wrBlockMax)
 
bool rdBlockMax ()
 
void setRdBlockMax (bool rdBlockMax)
 
void setPrintout (bool printout)
 
bool printout ()
 
void resetMode ()
 
void purgeBuffers ()
 
void setSynchronousMode ()
 
- Public Member Functions inherited from Interface
 Interface ()
 Standard constructor. More...
 
virtual ~Interface ()
 Destructor. More...
 
- Public Member Functions inherited from Element
 Element ()
 Standard constructor. More...
 
virtual ~Element ()
 Destructor. More...
 
void recursiveInitElement ()
 
void recursiveInitCommunications ()
 
StatusCode setConnection (Hierarchy *)
 
Hierarchyconnection ()
 
- Public Member Functions inherited from Hierarchy
 Hierarchy ()
 Standard constructor. More...
 
virtual ~Hierarchy ()
 Destructor. More...
 
void clear ()
 
void setParent (Hierarchy *parent)
 
Hierarchyparent ()
 
Hierarchyparent (std::string)
 
Hierarchyorigin ()
 
virtual void addChild (Hierarchy *element)
 
std::vector< Hierarchy * > children ()
 
Hierarchychild (std::string)
 
HierarchychildTyped (std::string)
 
unsigned long numberOfChildren ()
 
bool hasChildren ()
 
void delChild (Hierarchy *)
 
void delChild (std::string)
 
std::string path (std::string=std::string(""))
 
std::string pathTyped (std::string=std::string(""))
 
void tree (std::string indent=std::string(""))
 
void tree ()
 
- Public Member Functions inherited from Object
 Object ()
 Standard constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
std::string name () const
 
std::string type ()
 
unsigned char id ()
 
std::string title ()
 
void msgSvc (int level, std::string msg, std::string name)
 
void msg (std::string mymsg)
 
void verbose (std::string mymsg)
 
void debug (std::string mymsg)
 
void info (std::string mymsg)
 
void warning (std::string mymsg)
 
void error (std::string mymsg)
 
void fatal (std::string mymsg)
 
void msg (std::string mymsg, std::string name)
 
void verbose (std::string mymsg, std::string name)
 
void debug (std::string mymsg, std::string name)
 
void info (std::string mymsg, std::string name)
 
void warning (std::string mymsg, std::string name)
 
void error (std::string mymsg, std::string name)
 
void fatal (std::string mymsg, std::string name)
 
void setName (std::string name)
 
void setType (std::string type)
 
void setId (unsigned char id)
 
void setTitle (std::string title)
 
void setDllName (std::string dllName)
 
std::string dllName ()
 
- Public Member Functions inherited from Attrib
 Attrib ()
 Standard constructor. More...
 
virtual ~Attrib ()
 Destructor. More...
 
bool is (int attribut)
 
void add (int attribut)
 
void remove (int attribut)
 
std::string attributs ()
 

Private Attributes

int m_usbId
 
std::string m_serialNum
 
std::string m_deviceDesc
 
unsigned char m_latencyTimer
 
int m_txTimeOut
 
int m_rxTimeOut
 
int m_txBuffer
 
int m_rxBuffer
 
long int m_nFrames
 
unsigned long m_wordCount
 
unsigned long m_wordSize
 
unsigned int m_fakeErr
 
bool m_interrupts
 
bool m_showEpromState
 
bool m_printout
 
int m_rdBlockMax
 
int m_wrBlockMax
 

Additional Inherited Members

- Protected Attributes inherited from Element
Hierarchym_connection
 
- Protected Attributes inherited from Attrib
std::string m_attribString [10]
 

Detailed Description

Class to describe general electronics object

Author
Frederic Machefert
Date
2004-01-18

Definition at line 41 of file UsbFTMLInterface.h.

Member Typedef Documentation

◆ U16

typedef unsigned short UsbFTMLInterface::U16

Definition at line 44 of file UsbFTMLInterface.h.

◆ U32

typedef unsigned long UsbFTMLInterface::U32

Definition at line 43 of file UsbFTMLInterface.h.

◆ U8

typedef unsigned char UsbFTMLInterface::U8

Definition at line 45 of file UsbFTMLInterface.h.

Member Enumeration Documentation

◆ IOMode

Enumerator
USB_IORead 
USB_IOWrite 
USB_IOReadWrite 
USB_WriteReadBurst 
USB_IOExtebdedRead 

Definition at line 54 of file UsbFTMLInterface.h.

◆ WordSize

Enumerator
WS_Byte 
WS_Word 
WS_DWord 

Definition at line 47 of file UsbFTMLInterface.h.

Constructor & Destructor Documentation

◆ UsbFTMLInterface()

UsbFTMLInterface::UsbFTMLInterface ( )

Definition at line 19 of file UsbFTMLInterface.cpp.

References Object::info(), Object::setName(), and Object::setType().

19  :
20  m_usbId(-1),
21  m_serialNum(std::string("None")),
22  m_deviceDesc(std::string("None")),
23  m_latencyTimer(2),
24  m_txTimeOut(1000),
25  m_rxTimeOut(1000),
26  m_txBuffer(4096),
27  m_rxBuffer(32768),
28  m_nFrames (0),
31  m_rdBlockMax(65536),
32  m_wrBlockMax(65536),
33  m_interrupts(true),
34  m_showEpromState(false),
35  m_printout(false)
36 {
37  setName("usb");
38  setType("UsbFTMLInterface");
39  info("Todo : time efficiency by creating the buffer once for all ?");
40  // add(Attrib::INTERFACE);
41 }
void info(std::string mymsg)
Definition: Object.h:38
unsigned long m_wordSize
void setName(std::string name)
Definition: Object.h:51
void setType(std::string type)
Definition: Object.h:52
unsigned int m_fakeErr
unsigned char m_latencyTimer
std::string m_deviceDesc
std::string m_serialNum

◆ ~UsbFTMLInterface()

virtual UsbFTMLInterface::~UsbFTMLInterface ( )
inlinevirtual

Definition at line 64 of file UsbFTMLInterface.h.

References close().

64  {
65  close();
66  } //< Destructor

Member Function Documentation

◆ close()

void UsbFTMLInterface::close ( )

Close the usb device

Definition at line 727 of file UsbFTMLInterface.cpp.

References CloseUsbDevice(), Object::info(), itos(), m_usbId, and Object::name().

Referenced by BOOST_PYTHON_MODULE(), help(), init(), reset(), and ~UsbFTMLInterface().

727  {
728  if (m_usbId>0)
729  {
730  info("Close USB device "+name()+" [id="+itos(m_usbId)+"]","UsbFTMLInterface::close");
732  }
733  m_usbId=-1;
734 }
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
LALUSB_API void _cstmcall CloseUsbDevice(int id)
std::string name() const
Definition: Object.h:28

◆ deviceDesc()

std::string UsbFTMLInterface::deviceDesc ( )
inline

Get accessor to member m_deviceDesc

Returns
the current value of m_deviceDesc

Definition at line 273 of file UsbFTMLInterface.h.

References m_deviceDesc.

Referenced by BOOST_PYTHON_MODULE(), and setDeviceDesc().

273  {
274  return m_deviceDesc;
275  }
std::string m_deviceDesc

◆ fakeErr()

unsigned int UsbFTMLInterface::fakeErr ( )
inline

Get accessor to member m_fakeErr

Returns
the current value of m_fakeErr

Definition at line 410 of file UsbFTMLInterface.h.

References m_fakeErr.

Referenced by setFakeErr().

410  {
411  return m_fakeErr;
412  }
unsigned int m_fakeErr

◆ help()

virtual void UsbFTMLInterface::help ( )
inlinevirtual

printout help for the element

Implements Interface.

Definition at line 71 of file UsbFTMLInterface.h.

References close(), Object::info(), init(), and Object::name().

71 { info("UsbFTMLInterface "+name()+". No help.","UsbFTMLInterface::help"); };
void info(std::string mymsg)
Definition: Object.h:38
std::string name() const
Definition: Object.h:28

◆ init()

StatusCode UsbFTMLInterface::init ( )
virtual

init the component

Returns
void

Implements Interface.

Definition at line 47 of file UsbFTMLInterface.cpp.

References close(), Object::error(), Object::fatal(), FT_OK, GetDeviceDesc(), GetDeviceSerNum(), Object::info(), itos(), m_deviceDesc, m_interrupts, m_latencyTimer, m_rxBuffer, m_rxTimeOut, m_serialNum, m_txBuffer, m_txTimeOut, m_usbId, Object::name(), OpenUsbDevice(), StatusCode::SUCCESS, USB_FindDevices(), USB_GetLastError(), USB_GetLatencyTimer(), USB_Init(), USB_Perror(), USB_PurgeBuffers(), USB_ResetDevice(), USB_ResetMode(), USB_SetLatencyTimer(), USB_SetSynchronousMode(), USB_SetTimeouts(), USB_SetXferSize(), UsbSetIntCheckingState(), and wait().

Referenced by BOOST_PYTHON_MODULE(), help(), and reset().

47  {
48  unsigned char msecs=0;
49  char desc[256];
50  char serial[64];
51 
52  strcpy(desc , m_deviceDesc.c_str());
53  strcpy(serial, m_serialNum.c_str());
54 
55  info("Start USB device initialisation.","UsbFTMLInterface::init");
56  if (m_usbId>0)
57  {
58  error("Usb device already open.","UsbFTMLInterface::init");
59  close();
60  }
61  if (!USB_FindDevices(desc))
62  {
64  error("Cannot find Usb Device "+name()+" with device description "+
65  m_deviceDesc,"UsbFTMLInterface::init");
66  }
67  else
68  {
69  info("Device with device description "+m_deviceDesc+" found.","UsbFTMLInterface::init");
70  info("Try to open device with serial number "+m_serialNum+".","UsbFTMLInterface::init");
71  m_usbId=OpenUsbDevice(serial);
72  if (m_usbId<0)
73  {
74  error("Could not find device with serial number "+m_serialNum,"UsbFTMLInterface::init");
75  if (GetDeviceSerNum(serial,0)!=FT_OK)
76  {
77  error("Serial number do not match first device found.","UsbFTMLInterface::init");
78  }
79  else
80  {
81  info("Extracted serial number "+std::string(serial)+".","UsbFTMLInterface::init");
82  if (GetDeviceDesc(desc,0)!=FT_OK)
83  {
85  fatal("Device description do not match first device either. Abort",
86  "UsbFTMLInterface::init");
87  }
88  else
89  {
90  info("Device found. Extracted description "+std::string(desc)+".",
91  "UsbFTMLInterface::init");
92  m_usbId=OpenUsbDevice(serial);
93  if (m_usbId<0)
94  {
96  fatal("Cannot open device. Abort.","UsbFTMLInterface::init");
97  }
98  }
99  }
100  }
101 
102  info("Device opened with UsbId "+itos(m_usbId)+".","UsbFTMLInterface::init");
103 
104  m_deviceDesc = std::string(desc);
105  m_serialNum = std::string(serial);
106 
108  if (!USB_Init(m_usbId,true))
109  {
111  fatal("Could not initialize the USB device "+name()+". Abort.",
112  "UsbFTMLInterface::init");
113  }
114 
115  info("Usb device initialization done.","UsbFTMLInterface::init");
116 
120  USB_GetLatencyTimer(m_usbId, &msecs);
121 
124  // UsbSetMaxLayer(m_usbId,1);
125  }
126  USB_PurgeBuffers(m_usbId); // PurgeBuffers après le reset cause une erreur lors de la première lecture effectuée via le port usb.
128  wait(1000);
130  return StatusCode::SUCCESS;
131 }
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
LALUSB_API BOOL _cstmcall USB_GetLatencyTimer(int id, PUCHAR msecs)
LALUSB_API void _cstmcall USB_Perror(USB_Error err_code)
LALUSB_API BOOL _cstmcall USB_SetLatencyTimer(int id, UCHAR msecs)
void fatal(std::string mymsg)
Definition: Object.h:41
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)
Definition: ftd2xx.h:80
LALUSB_API BOOL _cstmcall USB_ResetMode(int id)
void error(std::string mymsg)
Definition: Object.h:40
LALUSB_API BOOL _cstmcall USB_PurgeBuffers(int id)
unsigned char m_latencyTimer
std::string m_deviceDesc
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)
std::string name() const
Definition: Object.h:28
LALUSB_API FT_STATUS _cstmcall GetDeviceDesc(char *buffer, int index)
LALUSB_API BOOL _cstmcall USB_SetSynchronousMode(int id, int sleep_time)
LALUSB_API void _cstmcall UsbSetIntCheckingState(BOOL truefalse)
void wait(int nbr_ms)
Definition: Tools.cpp:271
std::string m_serialNum
LALUSB_API BOOL _cstmcall USB_SetXferSize(int id, unsigned long txsize, unsigned long rxsize)
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)

◆ interrupts()

bool UsbFTMLInterface::interrupts ( )
inline

Get accessor to member m_interrupts

Returns
the current value of m_interrupts

Definition at line 426 of file UsbFTMLInterface.h.

References m_interrupts.

Referenced by setInterrupts().

426  {
427  return m_interrupts;
428  }

◆ latencyTimer()

unsigned char UsbFTMLInterface::latencyTimer ( )
inline

Get accessor to member m_latTimer

Returns
the current value of m_latTimer

Definition at line 290 of file UsbFTMLInterface.h.

References m_latencyTimer, m_usbId, and USB_GetLatencyTimer().

Referenced by BOOST_PYTHON_MODULE(), and setLatencyTimer().

290  {
292  return m_latencyTimer;
293  }
LALUSB_API BOOL _cstmcall USB_GetLatencyTimer(int id, PUCHAR msecs)
unsigned char m_latencyTimer

◆ nFrames()

long int UsbFTMLInterface::nFrames ( )
inline

Get accessor to member m_nFrames

Returns
the current value of m_nFrames

Definition at line 361 of file UsbFTMLInterface.h.

References m_nFrames.

Referenced by setNFrames().

361  {
362  return m_nFrames;
363  }

◆ printout()

bool UsbFTMLInterface::printout ( )
inline

Get accessor to member m_printout

Returns
the current value of m_printout

Definition at line 490 of file UsbFTMLInterface.h.

References m_printout.

Referenced by setPrintout().

490  {
491  return m_printout;
492  }

◆ purgeBuffers()

void UsbFTMLInterface::purgeBuffers ( )
inline

Definition at line 496 of file UsbFTMLInterface.h.

References m_usbId, and USB_PurgeBuffers().

Referenced by BOOST_PYTHON_MODULE().

LALUSB_API BOOL _cstmcall USB_PurgeBuffers(int id)

◆ rdBlockMax()

bool UsbFTMLInterface::rdBlockMax ( )
inline

Get accessor to member m_rdBlockMax

Returns
the current value of m_rdBlockMax

Definition at line 466 of file UsbFTMLInterface.h.

References m_rdBlockMax.

Referenced by setRdBlockMax().

466  {
467  return m_rdBlockMax;
468  }

◆ read() [1/2]

StatusCode UsbFTMLInterface::read ( IOdata io)
virtual

Implements Interface.

Definition at line 739 of file UsbFTMLInterface.cpp.

References IOdata::address(), IOdata::Byte, shell::data(), IOdata::dataU16(), IOdata::dataU32(), IOdata::dataU8(), IOdata::DWord, Object::error(), StatusCode::FAILURE, itos(), IOdata::length(), m_rdBlockMax, usbReadU16(), usbReadU32(), usbReadU8(), Object::verbose(), IOdata::Word, and IOdata::wordSize().

Referenced by BOOST_PYTHON_MODULE(), and update().

739  {
740 
741  unsigned long int address = io->address();
742  unsigned long int nWords = io->length();
743 
744  StatusCode status;
745  switch (io->wordSize())
746  {
747  case (IOdata::Byte):
748  if (nWords<m_rdBlockMax+1){
749  verbose("Reading a single block "+itos(nWords)+"/"+itos(m_rdBlockMax),
750  "UsbFTMLInterface::read");
751  status = usbReadU8( address, nWords, io->dataU8());
752  }
753  else {
754  // int nwords=nWords;
755  U8* data=io->dataU8();
756  int nXfer=(int)(nWords/m_rdBlockMax)+1;
757  for (int i=0; i<nXfer ; ++i){
758  if (i<nXfer-1){
759  verbose("Reading block "+itos(i)+
760  " of size "+itos(m_rdBlockMax),
761  "UsbFTMLInterface::read");
762  status = usbReadU8( address,
763  m_rdBlockMax ,
764  data);
765  data+=sizeof(U8*)*m_rdBlockMax;
766  }
767  else {
768  verbose("Reading last block "+itos(i)+
769  " of size "+itos(nWords%m_rdBlockMax),
770  "UsbFTMLInterface::read");
771  status = usbReadU8( address,
772  nWords%m_rdBlockMax ,
773  data);
774  data+=sizeof(U8*)*(nWords%m_rdBlockMax);
775  }
776  }
777  }
778  break;
779  case (IOdata::Word):
780  status = usbReadU16( address, nWords, io->dataU16());
781  break;
782  case (IOdata::DWord):
783  status = usbReadU32( address, nWords, io->dataU32());
784  break;
785  default:
786  error("Wrong word size.","UsbFTMLInterface::read");
787  status=StatusCode::FAILURE;
788  }
789  return status;
790 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
StatusCode usbReadU8(unsigned long int, unsigned long int, unsigned char *)
U32 address()
Definition: IOdata.h:59
U32 * dataU32()
Definition: IOdata.h:222
unsigned char U8
Definition: ICECALv3.h:55
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
U32 length()
Definition: IOdata.h:175
U16 * dataU16()
Definition: IOdata.h:218
StatusCode usbReadU16(unsigned long int, unsigned long int, unsigned short *)
U8 * dataU8()
Definition: IOdata.h:214
StatusCode usbReadU32(unsigned long int, unsigned long int, unsigned long *)
IOdata::WordSize wordSize()
Definition: IOdata.h:133

◆ read() [2/2]

StatusCode UsbFTMLInterface::read ( unsigned long int  address,
unsigned long int  nWords,
boost::python::list &  obj 
)

Python interpreter wrapping for usb read

Definition at line 137 of file UsbFTMLInterface.cpp.

References shell::data(), Object::error(), StatusCode::FAILURE, Object::info(), itos(), m_wordSize, usbReadU16(), usbReadU32(), usbReadU8(), Object::verbose(), WS_Byte, WS_DWord, and WS_Word.

140 {
141  StatusCode status;
142  verbose("USB Reading :","UsbFTMLInterface::read");
143  switch (m_wordSize)
144  {
145  case WS_Byte:
146  {
147  unsigned char *data=new unsigned char[nWords];
148  status = usbReadU8( address, nWords, data);
149  info("Data format is "+itos(WS_Byte),"UsbFTMLInterface::read");
150  for(unsigned int i = 0; i < nWords; i++){
151  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::read");
152  obj.append(data[i]);
153  };
154  delete data;
155  }
156  break;
157  case WS_Word:
158  {
159  unsigned short *data=new unsigned short[nWords];
160  status = usbReadU16( address, nWords, data);
161  verbose("Data format is "+itos(WS_Word),"UsbFTMLInterface::read");
162  for(unsigned int i = 0; i < nWords; i++){
163  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::read");
164  obj.append(data[i]);
165  };
166  delete data;
167  }
168  break;
169  case WS_DWord:
170  {
171  unsigned long *data=new unsigned long[nWords];
172  status = usbReadU32( address, nWords, data);
173  verbose("Data format is "+itos(WS_DWord),"UsbFTMLInterface::read");
174  for(unsigned int i = 0; i < nWords; i++){
175  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::read");
176  obj.append(data[i]);
177  };
178  delete data;
179  }
180  break;
181  default:
182  error("Wrong word size.","UsbFTMLInterface::read");
183  status=StatusCode::FAILURE;
184  }
185  return status;
186 }
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
StatusCode usbReadU8(unsigned long int, unsigned long int, unsigned char *)
unsigned long m_wordSize
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
StatusCode usbReadU16(unsigned long int, unsigned long int, unsigned short *)
StatusCode usbReadU32(unsigned long int, unsigned long int, unsigned long *)
def obj()
Definition: shell.py:26

◆ reset()

virtual void UsbFTMLInterface::reset ( )
inlinevirtual

Resets the Element so that is is in a standard and safe situation. Different from Element::init which configure the Element. Element::reset() is more an Emergency pull. It is often/usually called by the recursiveInitElement method at the start of the program.

Implements Interface.

Definition at line 91 of file UsbFTMLInterface.h.

References close(), Object::info(), init(), m_usbId, Object::name(), and USB_ResetDevice().

91  {
93  info("Reset of the Usb interface "+name(),"UsbFTMLInterface::reset");
94  close();
95  init();
96  };
void info(std::string mymsg)
Definition: Object.h:38
LALUSB_API BOOL _cstmcall USB_ResetDevice(int id)
virtual StatusCode init()
std::string name() const
Definition: Object.h:28

◆ resetMode()

void UsbFTMLInterface::resetMode ( )
inline

Definition at line 494 of file UsbFTMLInterface.h.

References m_usbId, and USB_ResetMode().

Referenced by BOOST_PYTHON_MODULE().

LALUSB_API BOOL _cstmcall USB_ResetMode(int id)

◆ rxBuffer()

int UsbFTMLInterface::rxBuffer ( )
inline

Get accessor to member m_rxBuffer

Returns
the current value of m_rxBuffer

Definition at line 345 of file UsbFTMLInterface.h.

References m_rxBuffer.

Referenced by BOOST_PYTHON_MODULE(), and setBuffer().

345  {
346  return m_rxBuffer;
347  }

◆ rxTimeOut()

int UsbFTMLInterface::rxTimeOut ( )
inline

Get accessor to member m_rxTimeOut

Returns
the current value of m_rxTimeOut

Definition at line 318 of file UsbFTMLInterface.h.

References m_rxTimeOut.

Referenced by BOOST_PYTHON_MODULE(), and setTimeOut().

318  {
319  // USB_SetTimeouts(m_usbId,&m_txTimeOut,&m_rxTimeOut)
320  return m_rxTimeOut;
321  }

◆ serialNum()

std::string UsbFTMLInterface::serialNum ( )
inline

Get accessor to member m_serialNum

Returns
the current value of m_serialNum

Definition at line 257 of file UsbFTMLInterface.h.

References m_serialNum.

Referenced by BOOST_PYTHON_MODULE(), and setSerialNum().

257  {
258  return m_serialNum;
259  }
std::string m_serialNum

◆ setBuffer()

void UsbFTMLInterface::setBuffer ( int  txBuffer,
int  rxBuffer 
)
inline

Set accessor to member m_txBuffer

Parameters
txBufferthe new value for m_txBuffer

Definition at line 327 of file UsbFTMLInterface.h.

References m_rxBuffer, m_txBuffer, m_usbId, rxBuffer(), txBuffer(), and USB_SetXferSize().

Referenced by BOOST_PYTHON_MODULE().

327  {
331  }
LALUSB_API BOOL _cstmcall USB_SetXferSize(int id, unsigned long txsize, unsigned long rxsize)

◆ setDeviceDesc()

void UsbFTMLInterface::setDeviceDesc ( std::string  deviceDesc)
inline

Set accessor to member m_deviceDesc

Parameters
deviceDescthe new value for m_deviceDesc

Definition at line 265 of file UsbFTMLInterface.h.

References deviceDesc(), and m_deviceDesc.

Referenced by BOOST_PYTHON_MODULE().

265  {
267  }
std::string deviceDesc()
std::string m_deviceDesc

◆ setFakeErr()

void UsbFTMLInterface::setFakeErr ( unsigned int  fakeErr)
inline

Set accessor to member m_fakeErr

Parameters
fakeErrthe new value for m_fakeErr

Definition at line 402 of file UsbFTMLInterface.h.

References fakeErr(), and m_fakeErr.

402  {
403  m_fakeErr = fakeErr;
404  }
unsigned int m_fakeErr
unsigned int fakeErr()

◆ setInterrupts()

void UsbFTMLInterface::setInterrupts ( bool  interrupts)
inline

Set accessor to member m_interrupts

Parameters
interruptsthe new value for m_interrupts

Definition at line 418 of file UsbFTMLInterface.h.

References interrupts(), and m_interrupts.

418  {
420  }

◆ setLatencyTimer()

void UsbFTMLInterface::setLatencyTimer ( unsigned char  latencyTimer)
inline

Set accessor to member m_latencyTimer

Parameters
latTimerthe new value for m_latencyTimer

Definition at line 281 of file UsbFTMLInterface.h.

References latencyTimer(), m_latencyTimer, m_usbId, and USB_SetLatencyTimer().

Referenced by BOOST_PYTHON_MODULE().

281  {
284  }
LALUSB_API BOOL _cstmcall USB_SetLatencyTimer(int id, UCHAR msecs)
unsigned char m_latencyTimer
unsigned char latencyTimer()

◆ setNFrames()

void UsbFTMLInterface::setNFrames ( long int  nFrames)
inline

Set accessor to member m_nFrames

Parameters
nFramesthe new value for m_nFrames

Definition at line 353 of file UsbFTMLInterface.h.

References m_nFrames, and nFrames().

353  {
354  m_nFrames = nFrames;
355  }

◆ setPrintout()

void UsbFTMLInterface::setPrintout ( bool  printout)
inline

Set accessor to member m_printout

Parameters
printoutthe new value for m_printout

Definition at line 482 of file UsbFTMLInterface.h.

References m_printout, and printout().

482  {
484  }

◆ setRdBlockMax()

void UsbFTMLInterface::setRdBlockMax ( bool  rdBlockMax)
inline

Set accessor to member m_rdBlockMax

Parameters
rdBlockMaxthe new value for m_rdBlockMax

Definition at line 474 of file UsbFTMLInterface.h.

References m_rdBlockMax, and rdBlockMax().

474  {
476  }

◆ setSerialNum()

void UsbFTMLInterface::setSerialNum ( std::string  serialNum)
inline

Set accessor to member m_serialNum

Parameters
serialNumthe new value for m_serialNum

Definition at line 249 of file UsbFTMLInterface.h.

References m_serialNum, and serialNum().

Referenced by BOOST_PYTHON_MODULE().

249  {
251  }
std::string serialNum()
std::string m_serialNum

◆ setShowEpromState()

void UsbFTMLInterface::setShowEpromState ( bool  showEpromState)
inline

Set accessor to member m_showEpromState

Parameters
showEpromStatethe new value for m_showEpromState

Definition at line 434 of file UsbFTMLInterface.h.

References m_showEpromState, and showEpromState().

434  {
436  }

◆ setSynchronousMode()

void UsbFTMLInterface::setSynchronousMode ( )
inline

Definition at line 498 of file UsbFTMLInterface.h.

References m_usbId, and USB_SetSynchronousMode().

Referenced by BOOST_PYTHON_MODULE().

LALUSB_API BOOL _cstmcall USB_SetSynchronousMode(int id, int sleep_time)

◆ setTimeOut()

void UsbFTMLInterface::setTimeOut ( int  txTimeOut,
int  rxTimeOut 
)
inline

Set accessor to member m_txTimeOut

Parameters
txTimeOutthe new value for m_txTimeOut

Definition at line 299 of file UsbFTMLInterface.h.

References m_rxTimeOut, m_txTimeOut, m_usbId, rxTimeOut(), txTimeOut(), and USB_SetTimeouts().

Referenced by BOOST_PYTHON_MODULE().

299  {
303  }
LALUSB_API BOOL _cstmcall USB_SetTimeouts(int id, int tx_timeout, int rx_timeout)

◆ setUsbId()

void UsbFTMLInterface::setUsbId ( int  usbId)
inline

Set accessor to member m_usbId

Parameters
usbIdthe new value for m_usbId

Definition at line 232 of file UsbFTMLInterface.h.

References m_usbId, and usbId().

232  {
233  m_usbId = usbId;
234  }

◆ setWordCount()

void UsbFTMLInterface::setWordCount ( unsigned long  wordCount)
inline

Set accessor to member m_wordCount

Parameters
wordCountthe new value for m_wordCount

Definition at line 370 of file UsbFTMLInterface.h.

References m_wordCount, and wordCount().

370  {
372  }
unsigned long m_wordCount
unsigned long wordCount()

◆ setWordSize()

void UsbFTMLInterface::setWordSize ( unsigned long  wordSize)
inline

Set accessor to member m_wordSize

Parameters
wordSizethe new value for m_wordSize

Definition at line 386 of file UsbFTMLInterface.h.

References m_wordSize, and wordSize().

Referenced by BOOST_PYTHON_MODULE().

386  {
388  }
unsigned long m_wordSize
unsigned long wordSize()

◆ setWrBlockMax()

void UsbFTMLInterface::setWrBlockMax ( bool  wrBlockMax)
inline

Set accessor to member m_wrBlockMax

Parameters
wrBlockMaxthe new value for m_wrBlockMax

Definition at line 458 of file UsbFTMLInterface.h.

References m_wrBlockMax, and wrBlockMax().

458  {
460  }

◆ showEpromState()

bool UsbFTMLInterface::showEpromState ( )
inline

Get accessor to member m_showEpromState

Returns
the current value of m_showEpromState

Definition at line 442 of file UsbFTMLInterface.h.

References m_showEpromState.

Referenced by setShowEpromState().

442  {
443  return m_showEpromState;
444  }

◆ txBuffer()

int UsbFTMLInterface::txBuffer ( )
inline

Get accessor to member m_txBuffer

Returns
the current value of m_txBuffer

Definition at line 337 of file UsbFTMLInterface.h.

References m_txBuffer.

Referenced by BOOST_PYTHON_MODULE(), and setBuffer().

337  {
338  return m_txBuffer;
339  }

◆ txTimeOut()

int UsbFTMLInterface::txTimeOut ( )
inline

Get accessor to member m_txTimeOut

Returns
the current value of m_txTimeOut

Definition at line 309 of file UsbFTMLInterface.h.

References m_txTimeOut.

Referenced by BOOST_PYTHON_MODULE(), and setTimeOut().

309  {
310  // USB_SetTimeouts(m_usbId,&m_txTimeOut,&m_rxTimeOut)
311  return m_txTimeOut;
312  }

◆ update()

virtual void UsbFTMLInterface::update ( )
inlinevirtual

◆ usbId()

int UsbFTMLInterface::usbId ( )
inline

Get accessor to member m_usbId

Returns
the current value of m_usbId

Definition at line 240 of file UsbFTMLInterface.h.

References m_usbId.

Referenced by setUsbId().

240  {
241  return m_usbId;
242  }

◆ usbRead()

StatusCode UsbFTMLInterface::usbRead ( unsigned long int  address,
unsigned long int  nWords,
std::vector< U32 > &  words 
)

Read usb in std::vector format – Do not use : Only supports U8 ! Write usb in std::vector<U8> format – Do not use yet : Only supports U8 ! Read usb in std::vector format – Do not use : Only supports U8 ! Write usb in std::vector<U16> format – Do not use yet : Only supports U8 ! Read usb in std::vector format – Do not use : Only supports U8 !

Definition at line 245 of file UsbFTMLInterface.cpp.

References shell::data(), Object::error(), StatusCode::FAILURE, itos(), m_wordSize, usbReadU16(), usbReadU32(), usbReadU8(), Object::verbose(), WS_Byte, WS_DWord, and WS_Word.

Referenced by update().

248 {
249  StatusCode status;
250  verbose("USB Reading :","UsbFTMLInterface::read");
251  words.clear();
252  words.reserve(nWords);
253  switch (m_wordSize)
254  {
255  case WS_Byte:
256  {
257  unsigned char *data=new unsigned char[nWords];
258  status = usbReadU8( address, nWords, data);
259  for(unsigned int i = 0; i < nWords; i++){
260  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::usbRead");
261  words.push_back(data[i]);
262  };
263  delete data;
264  }
265  break;
266  case WS_Word:
267  {
268  unsigned short *data=new unsigned short[nWords];
269  status = usbReadU16( address, nWords, data);
270  for(unsigned int i = 0; i < nWords; i++){
271  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::usbRead");
272  words.push_back(data[i]);
273  };
274  delete data;
275  }
276  break;
277  case WS_DWord:
278  {
279  unsigned long *data=new unsigned long[nWords];
280  status = usbReadU32( address, nWords, data);
281  for(unsigned int i = 0; i < nWords; i++){
282  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::usbRead");
283  words.push_back(data[i]);
284  };
285  delete data;
286  }
287  break;
288  default:
289  error("Wrong word size.","UsbFTMLInterface::read");
290  status=StatusCode::FAILURE;
291  }
292  return status;
293 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
StatusCode usbReadU8(unsigned long int, unsigned long int, unsigned char *)
unsigned long m_wordSize
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
StatusCode usbReadU16(unsigned long int, unsigned long int, unsigned short *)
StatusCode usbReadU32(unsigned long int, unsigned long int, unsigned long *)

◆ usbReadU16()

StatusCode UsbFTMLInterface::usbReadU16 ( unsigned long int  address,
unsigned long int  nWords,
unsigned short *  data 
)

Definition at line 397 of file UsbFTMLInterface.cpp.

References Object::error(), StatusCode::FAILURE, itos(), m_usbId, Object::name(), Hierarchy::path(), PrintFrameInfo(), StatusCode::SUCCESS, USB_GetLastError(), USB_INT_FRAME, USB_NoErr, UsbReadML(), and Object::verbose().

Referenced by read(), update(), and usbRead().

399  {
400 
401  USB_Error rdErr=USB_NoErr;
402  long int bytecount=0;
403 
404  verbose("in UsbReadU16.");
405 
406 
407  long int nData = (long int)(2*nWords);
408 
409  unsigned char *buff=new unsigned char [nData];
410 
411 
412  verbose("before usbread");
413 
414  int path = -1;
415  bytecount=UsbReadML(m_usbId, &path, address, buff, nData);
416 
417  verbose("after usbread");
418 
419  for (unsigned long word=0; word<nWords; ++word)
420  {
421  data[word]=buff[2*word+1];
422  data[word]=(data[word]<<8)|buff[2*word];
423  }
424 
425  delete buff;
426 
427  if (nData==bytecount){
428  verbose(itos(bytecount)+" bytes read from USB Interface "+name(),
429  "UsbFTMLInterface::usbReadU16");
430  return StatusCode::SUCCESS;
431  }
432 
433  if (bytecount<0){
434  rdErr=USB_GetLastError();
435  error("USB error number "+itos(rdErr)+" - USB_INT_FRAME="+itos(USB_INT_FRAME),
436  " UsbFTMLInterface::usbReadU16");
437  if (rdErr==USB_INT_FRAME){
438  PrintFrameInfo();
439  }
440  return StatusCode::FAILURE;
441  }
442 
443  if (0==bytecount){
444  error(" O Byte read from USB interface "+name()+".",
445  "UsbFTMLInterface::usbReadU16");
446  return StatusCode::FAILURE;
447  }
448 
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");
453  return StatusCode::FAILURE;
454  }
455 
456  return StatusCode::SUCCESS;
457 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
#define USB_NoErr
Definition: LALUsbML.h:69
FT_STATUS USB_Error
Definition: LALUsbML.h:72
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
LALUSB_API int _cstmcall UsbReadML(int id, int *target_path_array, char sub_addr, void *buffer, int usercount)
std::string name() const
Definition: Object.h:28
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344
LALUSB_API void _cstmcall PrintFrameInfo(void)

◆ usbReadU32()

StatusCode UsbFTMLInterface::usbReadU32 ( unsigned long int  address,
unsigned long int  nWords,
unsigned long *  data 
)

Definition at line 462 of file UsbFTMLInterface.cpp.

References Object::error(), StatusCode::FAILURE, itos(), m_usbId, Object::name(), Hierarchy::path(), PrintFrameInfo(), StatusCode::SUCCESS, USB_GetLastError(), USB_INT_FRAME, USB_NoErr, UsbReadML(), and Object::verbose().

Referenced by read(), update(), and usbRead().

464  {
465 
466  USB_Error rdErr=USB_NoErr;
467  long int bytecount=0;
468 
469  long int nData = (long int)(4*nWords);
470 
471  unsigned char *buff=new unsigned char [nData];
472 
473  int path = -1;
474 
475  bytecount=UsbReadML(m_usbId, &path, address, buff, nData);
476 
477  for (unsigned long word=0; word<nWords; ++word)
478  {
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];
483  }
484 
485  delete buff;
486 
487  if (nData==bytecount){
488  verbose(itos(bytecount)+" bytes read from USB Interface "+name(),
489  "UsbFTMLInterface::usbRead");
490  return StatusCode::SUCCESS;
491  }
492 
493  if (bytecount<0){
494  rdErr=USB_GetLastError();
495  error("USB error number "+itos(rdErr)+" - USB_INT_FRAME="+itos(USB_INT_FRAME),
496  " UsbFTMLInterface::usbRead32");
497  if (rdErr==USB_INT_FRAME){
498  PrintFrameInfo();
499  }
500  return StatusCode::FAILURE;
501  }
502 
503  if (0==bytecount){
504  error(" O Byte read from USB interface "+name()+".","UsbFTMLInterface::usbRead32");
505  return StatusCode::FAILURE;
506  }
507 
508  if (nData!=bytecount){
509  error(itos(bytecount)+" byte(s) read from USB interface "+name()+
510  " out of "+itos(nData)+" bytes expected.","UsbFTMLInterface::usbRead32");
511  return StatusCode::FAILURE;
512  }
513  return StatusCode::SUCCESS;
514 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
#define USB_NoErr
Definition: LALUsbML.h:69
FT_STATUS USB_Error
Definition: LALUsbML.h:72
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
LALUSB_API int _cstmcall UsbReadML(int id, int *target_path_array, char sub_addr, void *buffer, int usercount)
std::string name() const
Definition: Object.h:28
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344
LALUSB_API void _cstmcall PrintFrameInfo(void)

◆ usbReadU8()

StatusCode UsbFTMLInterface::usbReadU8 ( unsigned long int  address,
unsigned long int  nWords,
unsigned char *  data 
)

Read usb (U8 format)

Definition at line 351 of file UsbFTMLInterface.cpp.

References Object::error(), StatusCode::FAILURE, itos(), m_usbId, Object::name(), Hierarchy::path(), PrintFrameInfo(), StatusCode::SUCCESS, USB_GetLastError(), USB_INT_FRAME, USB_NoErr, UsbReadML(), and Object::verbose().

Referenced by read(), update(), and usbRead().

353  {
354 
355  USB_Error rdErr=USB_NoErr;
356  long int bytecount=0;
357 
358  long int nData = (long int)(nWords);
359 
360  int path = -1;
361 
362  bytecount=UsbReadML(m_usbId, &path, address, data, nData);
363 
364  if (nData==bytecount){
365  verbose(itos(bytecount)+" bytes read from USB Interface "+name(),
366  "UsbFTMLInterface::usbRead8");
367  return StatusCode::SUCCESS;
368  }
369 
370  if (bytecount<0){
371  rdErr=USB_GetLastError();
372  error("USB error number "+itos(rdErr)+" - USB_INT_FRAME="+itos(USB_INT_FRAME),
373  " UsbFTMLInterface::usbRead8");
374  if (rdErr==USB_INT_FRAME){
375  PrintFrameInfo();
376  }
377  return StatusCode::FAILURE;
378  }
379 
380  if (0==bytecount){
381  error(" O Byte read from USB interface "+name()+".","UsbFTMLInterface::usbRead8");
382  return StatusCode::FAILURE;
383  }
384 
385  if (nData!=bytecount){
386  error(itos(bytecount)+" byte(s) read from USB interface "+name()+
387  " out of "+itos(nData)+" bytes expected.","UsbFTMLInterface::usbRead8");
388  return StatusCode::FAILURE;
389  }
390 
391  return StatusCode::SUCCESS;
392 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
#define USB_NoErr
Definition: LALUsbML.h:69
FT_STATUS USB_Error
Definition: LALUsbML.h:72
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
LALUSB_API int _cstmcall UsbReadML(int id, int *target_path_array, char sub_addr, void *buffer, int usercount)
std::string name() const
Definition: Object.h:28
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344
LALUSB_API void _cstmcall PrintFrameInfo(void)

◆ usbWrite()

StatusCode UsbFTMLInterface::usbWrite ( unsigned long int  address,
std::vector< U32 words 
)

Write usb in std::vector<U32> format – Do not use yet : Only supports U8 !

Definition at line 298 of file UsbFTMLInterface.cpp.

References shell::data(), Object::error(), StatusCode::FAILURE, itos(), m_wordSize, usbWriteU16(), usbWriteU32(), usbWriteU8(), Object::verbose(), WS_Byte, WS_DWord, and WS_Word.

Referenced by update().

300 {
301  unsigned long int nWords = words.size();
302  StatusCode status;
303  verbose("USB Writing :");
304  switch (m_wordSize)
305  {
306  case WS_Byte:
307  {
308  unsigned char *data=new unsigned char[nWords];
309  for(unsigned int i = 0; i < nWords; i++){
310  data[i]=words[i];
311  verbose("Data format is "+itos(WS_Byte),"UsbFTMLInterface::usbWrite");
312  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::usbWrite");
313  };
314  status = usbWriteU8(address, nWords, data);
315  delete data;
316  }
317  break;
318  case WS_Word:
319  {
320  unsigned short *data=new unsigned short[nWords];
321  for(unsigned int i = 0; i < nWords; i++){
322  data[i]=words[i];
323  verbose("Data format is "+itos(WS_Word),"UsbFTMLInterface::usbWrite");
324  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::usbWrite");
325  };
326  status = usbWriteU16(address, nWords, data);
327  delete data;
328  }
329  break;
330  case WS_DWord:
331  {
332  unsigned long *data=new unsigned long[nWords];
333  for(unsigned int i = 0; i < nWords; i++){
334  data[i]=words[i];
335  verbose("Data format is "+itos(WS_DWord),"UsbFTMLInterface::usbWrite");
336  verbose("wd "+itos(i)+" "+itos(data[i]) ,"UsbFTMLInterface::usbWrite");
337  }
338  status = usbWriteU32(address, nWords, data);
339  delete data;
340  }
341  break;
342  default:
343  error("Wrong word size.","read");
344  status=StatusCode::FAILURE;
345  }
346  return status;
347 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
unsigned long m_wordSize
StatusCode usbWriteU32(unsigned long int, unsigned long int, unsigned long *)
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
StatusCode usbWriteU8(unsigned long int, unsigned long int, unsigned char *)
StatusCode usbWriteU16(unsigned long int, unsigned long int, unsigned short *)

◆ usbWriteRead()

StatusCode UsbFTMLInterface::usbWriteRead ( unsigned long int  address,
std::vector< U8 dataWrite,
std::vector< U8 > &  dataRead 
)

Write/Read std::vector<U8> format – Do not use yet : Only supports U8 !

Definition at line 648 of file UsbFTMLInterface.cpp.

References Object::error(), StatusCode::FAILURE, itos(), m_usbId, Object::name(), Hierarchy::path(), PrintFrameInfo(), StatusCode::SUCCESS, USB_GetLastError(), USB_INT_FRAME, USB_NoErr, UsbReadML(), UsbWrtML(), and Object::verbose().

Referenced by update().

650  {
651  USB_Error rdErr=USB_NoErr, wrErr=USB_NoErr;
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];
657 
658  for(int j=0; j<nData; ++j) bufWr[j] = static_cast<unsigned char>(dataWrite[j]);
659 
660  int path = -1;
661  bytecount=UsbWrtML(m_usbId, &path, address, bufWr, nData);
662 
663  if (bytecount<0){
664  wrErr=USB_GetLastError();
665  error("USB error number "+itos(wrErr)+" - USB_INT_FRAME="+itos(USB_INT_FRAME),
666  " UsbFTMLInterface::usbWriteRead");
667  if (wrErr==USB_INT_FRAME){
668  PrintFrameInfo();
669  }
670  return StatusCode::FAILURE;
671  }
672 
673  if (nData==bytecount){
674  verbose(itos(bytecount)+" bytes written on USB Interface "+name(),
675  "UsbFTMLInterface::usbWriteRead");
676 
677  int path = -1;
678  bytecount=UsbReadML(m_usbId, &path, address, bufRd, nData);
679 
680  if (nData==bytecount){
681  verbose(itos(bytecount)+" bytes read from USB Interface "+name(),
682  "UsbFTMLInterface::usbRead");
683  for(int j=0; j<nData; ++j) dataRead[j] = static_cast<unsigned char>(bufRd[j]);
684  return StatusCode::SUCCESS;
685  }
686 
687  if (bytecount<0){
688  rdErr=USB_GetLastError();
689  error("USB error number "+itos(rdErr)+" - USB_INT_FRAME="+itos(USB_INT_FRAME),
690  " UsbFTMLInterface::usbWriteRead");
691  if (rdErr==USB_INT_FRAME){
692  PrintFrameInfo();
693  }
694  return StatusCode::FAILURE;
695  }
696 
697  if (0==bytecount){
698  error(" O Byte read from USB interface "+name()+".","UsbFTMLInterface::usbRead");
699  return StatusCode::FAILURE;
700  }
701 
702  if (nData!=bytecount){
703  error(itos(bytecount)+" byte(s) read from USB interface "+name()+
704  " out of "+itos(nData)+" bytes expected.","UsbFTMLInterface::usbRead");
705  return StatusCode::FAILURE;
706  }
707  }
708 
709 
710  if (0==bytecount){
711  error(" O Byte written n USB interface "+name()+".","UsbFTMLInterface::usbWrite");
712  return StatusCode::FAILURE;
713  }
714 
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");
718  return StatusCode::FAILURE;
719  }
720 
722 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
#define USB_NoErr
Definition: LALUsbML.h:69
FT_STATUS USB_Error
Definition: LALUsbML.h:72
unsigned char U8
Definition: ICECALv3.h:55
void error(std::string mymsg)
Definition: Object.h:40
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)
std::string name() const
Definition: Object.h:28
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344
LALUSB_API void _cstmcall PrintFrameInfo(void)

◆ usbWriteU16()

StatusCode UsbFTMLInterface::usbWriteU16 ( unsigned long int  address,
unsigned long int  nWords,
unsigned short *  data 
)

Write usb (U16 format)

Definition at line 562 of file UsbFTMLInterface.cpp.

References Object::error(), StatusCode::FAILURE, itos(), m_usbId, Object::name(), Hierarchy::path(), PrintFrameInfo(), StatusCode::SUCCESS, USB_GetLastError(), USB_INT_FRAME, USB_NoErr, UsbWrtML(), and Object::verbose().

Referenced by update(), usbWrite(), and write().

564  {
565  USB_Error wrErr=USB_NoErr;
566  long int bytecount=0;
567 
568  long int nData=(long int)(2*nWords);
569 
570  int path = -1;
571  bytecount=UsbWrtML(m_usbId, &path, address, data, nData);
572 
573  if (bytecount<0){
574  wrErr=USB_GetLastError();
575  error("USB error number "+itos(wrErr)+" - USB_INT_FRAME="+itos(USB_INT_FRAME),
576  "UsbFTMLInterface::usbWrite16");
577  if (wrErr==USB_INT_FRAME){
578  PrintFrameInfo();
579  }
580  return StatusCode::FAILURE;
581  }
582 
583  if (nData==bytecount){
584  verbose(itos(bytecount)+" bytes written on USB Interface "+name(),
585  "UsbFTMLInterface::usbWrite16");
586  }
587 
588  if (0==bytecount){
589  error(" O Byte written on USB interface "+name()+".","UsbFTMLInterface::usbWrite16");
590  return StatusCode::FAILURE;
591  }
592 
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");
596  return StatusCode::FAILURE;
597  }
598 
599  return StatusCode::SUCCESS;
600 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
#define USB_NoErr
Definition: LALUsbML.h:69
FT_STATUS USB_Error
Definition: LALUsbML.h:72
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
LALUSB_API int _cstmcall UsbWrtML(int id, int *target_path_array, char sub_addr, void *buffer, int count)
std::string name() const
Definition: Object.h:28
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344
LALUSB_API void _cstmcall PrintFrameInfo(void)

◆ usbWriteU32()

StatusCode UsbFTMLInterface::usbWriteU32 ( unsigned long int  address,
unsigned long int  nWords,
unsigned long *  data 
)

Write usb (U32 format)

Definition at line 605 of file UsbFTMLInterface.cpp.

References Object::error(), StatusCode::FAILURE, itos(), m_usbId, Object::name(), Hierarchy::path(), PrintFrameInfo(), StatusCode::SUCCESS, USB_GetLastError(), USB_INT_FRAME, USB_NoErr, UsbWrtML(), and Object::verbose().

Referenced by update(), usbWrite(), and write().

607  {
608  USB_Error wrErr=USB_NoErr;
609  long int bytecount=0;
610 
611  long int nData=(long int)(4*nWords);
612 
613  int path = -1;
614  bytecount=UsbWrtML(m_usbId, &path, address, data, nData);
615 
616  if (bytecount<0){
617  wrErr=USB_GetLastError();
618  error("USB error number "+itos(wrErr)+" - USB_INT_FRAME="+itos(USB_INT_FRAME),
619  "UsbFTMLInterface::usbWrite32");
620  if (wrErr==USB_INT_FRAME){
621  PrintFrameInfo();
622  }
623  return StatusCode::FAILURE;
624  }
625 
626  if (nData==bytecount){
627  verbose(itos(bytecount)+" bytes written on USB Interface "+name(),
628  "UsbFTMLInterface::usbWrite32");
629  }
630 
631  if (0==bytecount){
632  error(" O Byte written on USB interface "+name()+".","UsbFTMLInterface::usbWrite32");
633  return StatusCode::FAILURE;
634  }
635 
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");
639  return StatusCode::FAILURE;
640  }
641 
642  return StatusCode::SUCCESS;
643 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
#define USB_NoErr
Definition: LALUsbML.h:69
FT_STATUS USB_Error
Definition: LALUsbML.h:72
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
LALUSB_API int _cstmcall UsbWrtML(int id, int *target_path_array, char sub_addr, void *buffer, int count)
std::string name() const
Definition: Object.h:28
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344
LALUSB_API void _cstmcall PrintFrameInfo(void)

◆ usbWriteU8()

StatusCode UsbFTMLInterface::usbWriteU8 ( unsigned long int  address,
unsigned long int  nWords,
unsigned char *  data 
)

Write usb (U8 format)

Definition at line 519 of file UsbFTMLInterface.cpp.

References Object::error(), StatusCode::FAILURE, itos(), m_usbId, Object::name(), Hierarchy::path(), PrintFrameInfo(), StatusCode::SUCCESS, USB_GetLastError(), USB_INT_FRAME, USB_NoErr, UsbWrtML(), and Object::verbose().

Referenced by update(), usbWrite(), and write().

521  {
522  USB_Error wrErr=USB_NoErr;
523  long int bytecount=0;
524 
525  long int nData=(long int)(nWords);
526 
527  int path = -1;
528  bytecount=UsbWrtML(m_usbId, &path, address, data, nData);
529 
530  if (bytecount<0){
531  wrErr=USB_GetLastError();
532  error("USB error number "+itos(wrErr)+" - USB_INT_FRAME="+itos(USB_INT_FRAME),
533  "UsbFTMLInterface::usbWrite8");
534  if (wrErr==USB_INT_FRAME){
535  PrintFrameInfo();
536  }
537  return StatusCode::FAILURE;
538  }
539 
540  if (nData==bytecount){
541  verbose(itos(bytecount)+" bytes written on USB Interface "+name(),
542  "UsbFTMLInterface::usbWrite8");
543  }
544 
545  if (0==bytecount){
546  error(" O Byte written on USB interface "+name()+".","UsbFTMLInterface::usbWrite8");
547  return StatusCode::FAILURE;
548  }
549 
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");
553  return StatusCode::FAILURE;
554  }
555 
556  return StatusCode::SUCCESS;
557 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
#define USB_NoErr
Definition: LALUsbML.h:69
FT_STATUS USB_Error
Definition: LALUsbML.h:72
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
LALUSB_API int _cstmcall UsbWrtML(int id, int *target_path_array, char sub_addr, void *buffer, int count)
std::string name() const
Definition: Object.h:28
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344
LALUSB_API void _cstmcall PrintFrameInfo(void)

◆ wordCount()

unsigned long UsbFTMLInterface::wordCount ( )
inline

Get accessor to member m_wordCount

Returns
the current value of m_wordCount

Definition at line 378 of file UsbFTMLInterface.h.

References m_wordCount.

Referenced by setWordCount().

378  {
379  return m_wordCount;
380  }
unsigned long m_wordCount

◆ wordSize()

unsigned long UsbFTMLInterface::wordSize ( )
inline

Get accessor to member m_wordSize

Returns
the current value of m_wordSize

Definition at line 394 of file UsbFTMLInterface.h.

References m_wordSize.

Referenced by BOOST_PYTHON_MODULE(), and setWordSize().

394  {
395  return m_wordSize;
396  }
unsigned long m_wordSize

◆ wrBlockMax()

bool UsbFTMLInterface::wrBlockMax ( )
inline

Get accessor to member m_wrBlockMax

Returns
the current value of m_wrBlockMax

Definition at line 450 of file UsbFTMLInterface.h.

References m_wrBlockMax.

Referenced by setWrBlockMax().

450  {
451  return m_wrBlockMax;
452  }

◆ write() [1/2]

StatusCode UsbFTMLInterface::write ( IOdata io)
virtual

Implements Interface.

Definition at line 795 of file UsbFTMLInterface.cpp.

References IOdata::address(), IOdata::Byte, shell::data(), IOdata::dataU16(), IOdata::dataU32(), IOdata::dataU8(), IOdata::DWord, Object::error(), StatusCode::FAILURE, itos(), IOdata::length(), m_wrBlockMax, usbWriteU16(), usbWriteU32(), usbWriteU8(), Object::verbose(), IOdata::Word, and IOdata::wordSize().

Referenced by BOOST_PYTHON_MODULE(), and update().

795  {
796 
797  unsigned long int address = io->address();
798  unsigned long int nWords = io->length();
799  StatusCode status;
800  switch (io->wordSize())
801  {
802  case (IOdata::Byte):
803  if (nWords<m_wrBlockMax+1){
804  verbose("Writing a single block "+itos(nWords)+"/"+itos(m_wrBlockMax),
805  "UsbFTMLInterface::write");
806  status = usbWriteU8(address, nWords, io->dataU8());
807  }
808  else {
809  // int nwords=nWords;
810  U8* data=io->dataU8();
811  int nXfer=(int)ceil((float)(nWords)/(float)(m_wrBlockMax));
812  verbose("number of Xfer="+itos(nXfer)+
813  " "+itos(m_wrBlockMax)+
814  " "+itos(nWords),"");
815  for (int i=0; i<nXfer ; ++i){
816  if (i<nXfer-1){
817  verbose("Writing block "+itos(i)+
818  " of size "+itos(m_wrBlockMax),
819  "UsbFTMLInterface::write");
820  status = usbWriteU8( address,
821  m_wrBlockMax ,
822  data);
823  data+=sizeof(U8)*m_wrBlockMax;
824  }
825  else {
826  //nWords%m_wrBlockMax
827  unsigned int nwords=nWords-(nXfer-1)*m_wrBlockMax;
828  verbose("Writing last block "+itos(i)+
829  " of size "+itos(nwords),
830  "UsbFTMLInterface::write");
831  status = usbWriteU8( address,
832  nwords,
833  data);
834  data+=sizeof(U8)*(nwords);
835  }
836  }
837  }
838  break;
839  case (IOdata::Word):
840  status = usbWriteU16(address, nWords, io->dataU16());
841  break;
842  case (IOdata::DWord):
843  status = usbWriteU32(address, nWords, io->dataU32());
844  break;
845  default:
846  error("Wrong word size.","UsbFTMLInterface::read");
847  status=StatusCode::FAILURE;
848  }
849  return status;
850 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
U32 address()
Definition: IOdata.h:59
StatusCode usbWriteU32(unsigned long int, unsigned long int, unsigned long *)
U32 * dataU32()
Definition: IOdata.h:222
unsigned char U8
Definition: ICECALv3.h:55
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
unsigned char U8
U32 length()
Definition: IOdata.h:175
U16 * dataU16()
Definition: IOdata.h:218
StatusCode usbWriteU8(unsigned long int, unsigned long int, unsigned char *)
U8 * dataU8()
Definition: IOdata.h:214
StatusCode usbWriteU16(unsigned long int, unsigned long int, unsigned short *)
IOdata::WordSize wordSize()
Definition: IOdata.h:133

◆ write() [2/2]

StatusCode UsbFTMLInterface::write ( unsigned long int  address,
boost::python::list  obj 
)

Python interpreter wrapping for usb write

Definition at line 191 of file UsbFTMLInterface.cpp.

References shell::data(), Object::error(), StatusCode::FAILURE, itos(), m_wordSize, usbWriteU16(), usbWriteU32(), usbWriteU8(), Object::verbose(), WS_Byte, WS_DWord, and WS_Word.

193 {
194  unsigned long int nWords = len(obj);
195  StatusCode status;
196  verbose("USB Writing :");
197  switch (m_wordSize)
198  {
199  case WS_Byte:
200  {
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]));
204  verbose("Data format is "+itos(WS_Byte),"UsbFTMLInterface::write");
205  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::write");
206  };
207  status = usbWriteU8(address, nWords, data);
208  delete data;
209  }
210  break;
211  case WS_Word:
212  {
213  unsigned short *data=new unsigned short[nWords];
214  for(unsigned int i = 0; i < nWords; i++){
215  verbose("Data format is "+itos(WS_Word),"UsbFTMLInterface::write");
216  data[i]=(boost::python::extract<unsigned short>(obj[i]));
217  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::write");
218  };
219  status = usbWriteU16(address, nWords, data);
220  delete data;
221  }
222  break;
223  case WS_DWord:
224  {
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]));
228  verbose("Data format is "+itos(WS_DWord),"UsbFTMLInterface::write");
229  verbose("wd "+itos(i)+" "+itos(data[i]),"UsbFTMLInterface::write");
230  }
231  status = usbWriteU32(address, nWords, data);
232  delete data;
233  }
234  break;
235  default:
236  error("Wrong word size.","read");
237  status=StatusCode::FAILURE;
238  }
239  return status;
240 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
unsigned long m_wordSize
StatusCode usbWriteU32(unsigned long int, unsigned long int, unsigned long *)
void error(std::string mymsg)
Definition: Object.h:40
def data(object, stream=None)
Definition: shell.py:150
StatusCode usbWriteU8(unsigned long int, unsigned long int, unsigned char *)
StatusCode usbWriteU16(unsigned long int, unsigned long int, unsigned short *)
def obj()
Definition: shell.py:26

Member Data Documentation

◆ m_deviceDesc

std::string UsbFTMLInterface::m_deviceDesc
private

Definition at line 503 of file UsbFTMLInterface.h.

Referenced by deviceDesc(), init(), and setDeviceDesc().

◆ m_fakeErr

unsigned int UsbFTMLInterface::m_fakeErr
private

Definition at line 512 of file UsbFTMLInterface.h.

Referenced by fakeErr(), and setFakeErr().

◆ m_interrupts

bool UsbFTMLInterface::m_interrupts
private

Definition at line 513 of file UsbFTMLInterface.h.

Referenced by init(), interrupts(), and setInterrupts().

◆ m_latencyTimer

unsigned char UsbFTMLInterface::m_latencyTimer
private

Definition at line 504 of file UsbFTMLInterface.h.

Referenced by init(), latencyTimer(), and setLatencyTimer().

◆ m_nFrames

long int UsbFTMLInterface::m_nFrames
private

Definition at line 509 of file UsbFTMLInterface.h.

Referenced by nFrames(), and setNFrames().

◆ m_printout

bool UsbFTMLInterface::m_printout
private

Definition at line 515 of file UsbFTMLInterface.h.

Referenced by printout(), and setPrintout().

◆ m_rdBlockMax

int UsbFTMLInterface::m_rdBlockMax
private

Definition at line 516 of file UsbFTMLInterface.h.

Referenced by rdBlockMax(), read(), and setRdBlockMax().

◆ m_rxBuffer

int UsbFTMLInterface::m_rxBuffer
private

Definition at line 508 of file UsbFTMLInterface.h.

Referenced by init(), rxBuffer(), and setBuffer().

◆ m_rxTimeOut

int UsbFTMLInterface::m_rxTimeOut
private

Definition at line 506 of file UsbFTMLInterface.h.

Referenced by init(), rxTimeOut(), and setTimeOut().

◆ m_serialNum

std::string UsbFTMLInterface::m_serialNum
private

Definition at line 502 of file UsbFTMLInterface.h.

Referenced by init(), serialNum(), and setSerialNum().

◆ m_showEpromState

bool UsbFTMLInterface::m_showEpromState
private

Definition at line 514 of file UsbFTMLInterface.h.

Referenced by setShowEpromState(), and showEpromState().

◆ m_txBuffer

int UsbFTMLInterface::m_txBuffer
private

Definition at line 507 of file UsbFTMLInterface.h.

Referenced by init(), setBuffer(), and txBuffer().

◆ m_txTimeOut

int UsbFTMLInterface::m_txTimeOut
private

Definition at line 505 of file UsbFTMLInterface.h.

Referenced by init(), setTimeOut(), and txTimeOut().

◆ m_usbId

int UsbFTMLInterface::m_usbId
private

◆ m_wordCount

unsigned long UsbFTMLInterface::m_wordCount
private

Definition at line 510 of file UsbFTMLInterface.h.

Referenced by setWordCount(), and wordCount().

◆ m_wordSize

unsigned long UsbFTMLInterface::m_wordSize
private

Definition at line 511 of file UsbFTMLInterface.h.

Referenced by read(), setWordSize(), usbRead(), usbWrite(), wordSize(), and write().

◆ m_wrBlockMax

int UsbFTMLInterface::m_wrBlockMax
private

Definition at line 517 of file UsbFTMLInterface.h.

Referenced by setWrBlockMax(), wrBlockMax(), and write().


The documentation for this class was generated from the following files: