From a274f65a8aec7288f8e1d4110a4cec0a8c384055 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Mon, 11 Sep 2017 17:42:57 +0530 Subject: [PATCH 01/50] Added changeBaud functionality to Comm.h and Comm.cxx --- XSMU-2.4.0/code/app/app/Comm.h | 185 ++++++++++++++++++++----------- XSMU-2.4.0/code/app/src/Comm.cxx | 31 +++++- 2 files changed, 152 insertions(+), 64 deletions(-) diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index d73ba4d..0a1c924 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -64,6 +64,8 @@ enum Comm_Opcode COMM_OPCODE_VM2_LOAD_DEFAULT_CALIBRATION, //40 COMM_OPCODE_VM_SET_TERMINAL, //41 COMM_OPCODE_VM_GET_TERMINAL, //42 + + COMM_OPCODE_CHANGE_BAUD, //43 }; enum Comm_SourceMode @@ -1561,64 +1563,100 @@ class CommResponse_VM_GetTerminal : public CommPacket_VM_GetTerminal uint16_t reserve_; }; -/******************************************************************/ /******************************************************************/ -enum Comm_CallbackCode +class CommPacket_changeBaud : public CommPacket { - COMM_CBCODE_NOP, - COMM_CBCODE_IDN, - COMM_CBCODE_SYNC, - - COMM_CBCODE_SET_SOURCE_MODE, - - COMM_CBCODE_CS_SET_RANGE, - COMM_CBCODE_CS_GET_CALIBRATION, - COMM_CBCODE_CS_VERIFY_CALIBRATION, - COMM_CBCODE_CS_SET_CALIBRATION, - COMM_CBCODE_CS_SAVE_CALIBRATION, - COMM_CBCODE_CS_SET_CURRENT, - - COMM_CBCODE_VS_SET_RANGE, - COMM_CBCODE_VS_GET_CALIBRATION, - COMM_CBCODE_VS_VERIFY_CALIBRATION, - COMM_CBCODE_VS_SET_CALIBRATION, - COMM_CBCODE_VS_SAVE_CALIBRATION, - COMM_CBCODE_VS_SET_VOLTAGE, - - COMM_CBCODE_CM_SET_RANGE, - COMM_CBCODE_CM_GET_CALIBRATION, - COMM_CBCODE_CM_SET_CALIBRATION, - COMM_CBCODE_CM_SAVE_CALIBRATION, - COMM_CBCODE_CM_READ, +protected: + CommPacket_changeBaud (void) : + CommPacket (COMM_OPCODE_CHANGE_BAUD) + {} +}; - COMM_CBCODE_VM_SET_RANGE, - COMM_CBCODE_VM_GET_CALIBRATION, - COMM_CBCODE_VM_SET_CALIBRATION, - COMM_CBCODE_VM_SAVE_CALIBRATION, - COMM_CBCODE_VM_READ, +class CommRequest_changeBaud : public CommPacket_changeBaud +{ +public: + CommRequest_changeBaud (uint16_t baudRate) : + baudRate_(baudRate) + {} - COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION, - COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION, - COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION, - COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION, +private: + uint16_t baudRate_; + uint16_t reserve_; +}; - COMM_CBCODE_RM_READ_AUTOSCALE, +class CommResponse_changeBaud : public CommPacket_changeBaud +{ +private: + CommResponse_changeBaud (void); - COMM_CBCODE_SYSTEM_CONFIG_GET, - COMM_CBCODE_SYSTEM_CONFIG_SET, - COMM_CBCODE_SYSTEM_CONFIG_SAVE, - COMM_CBCODE_SYSTEM_CONFIG_LOAD_DEFAULT, +public: + uint16_t baudRate (void) const {return smu::ntoh(baudRate_);} - COMM_CBCODE_VM2_SET_RANGE, - COMM_CBCODE_VM2_GET_CALIBRATION, - COMM_CBCODE_VM2_SET_CALIBRATION, - COMM_CBCODE_VM2_SAVE_CALIBRATION, - COMM_CBCODE_VM2_READ, - COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION, +private: + uint16_t baudRate_; + uint16_t reserve_; +}; +/******************************************************************/ +/******************************************************************/ - COMM_CBCODE_VM_SET_TERMINAL, - COMM_CBCODE_VM_GET_TERMINAL, +enum Comm_CallbackCode +{ + COMM_CBCODE_NOP, //00 + COMM_CBCODE_IDN, //01 + COMM_CBCODE_SYNC, //02 + + COMM_CBCODE_SET_SOURCE_MODE, //03 + + COMM_CBCODE_CS_SET_RANGE, //04 + COMM_CBCODE_CS_GET_CALIBRATION, //05 + COMM_CBCODE_CS_VERIFY_CALIBRATION, //06 + COMM_CBCODE_CS_SET_CALIBRATION, //07 + COMM_CBCODE_CS_SAVE_CALIBRATION, //08 + COMM_CBCODE_CS_SET_CURRENT, //09 + + COMM_CBCODE_VS_SET_RANGE, //10 + COMM_CBCODE_VS_GET_CALIBRATION, //11 + COMM_CBCODE_VS_VERIFY_CALIBRATION, //12 + COMM_CBCODE_VS_SET_CALIBRATION, //13 + COMM_CBCODE_VS_SAVE_CALIBRATION, //14 + COMM_CBCODE_VS_SET_VOLTAGE, //15 + + COMM_CBCODE_CM_SET_RANGE, //16 + COMM_CBCODE_CM_GET_CALIBRATION, //17 + COMM_CBCODE_CM_SET_CALIBRATION, //18 + COMM_CBCODE_CM_SAVE_CALIBRATION, //19 + COMM_CBCODE_CM_READ, //20 + + COMM_CBCODE_VM_SET_RANGE, //21 + COMM_CBCODE_VM_GET_CALIBRATION, //22 + COMM_CBCODE_VM_SET_CALIBRATION, //23 + COMM_CBCODE_VM_SAVE_CALIBRATION, //24 + COMM_CBCODE_VM_READ, //25 + + COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION, //26 + COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION, //27 + COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION, //28 + COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION, //29 + + COMM_CBCODE_RM_READ_AUTOSCALE, //30 + + COMM_CBCODE_SYSTEM_CONFIG_GET, //31 + COMM_CBCODE_SYSTEM_CONFIG_SET, //32 + COMM_CBCODE_SYSTEM_CONFIG_SAVE, //33 + COMM_CBCODE_SYSTEM_CONFIG_LOAD_DEFAULT, //34 + + COMM_CBCODE_VM2_SET_RANGE, //35 + COMM_CBCODE_VM2_GET_CALIBRATION, //36 + COMM_CBCODE_VM2_SET_CALIBRATION, //37 + COMM_CBCODE_VM2_SAVE_CALIBRATION, //38 + COMM_CBCODE_VM2_READ, //39 + COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION, //40 + + COMM_CBCODE_VM_SET_TERMINAL, //41 + COMM_CBCODE_VM_GET_TERMINAL, //42 + + COMM_CBCODE_CHANGE_BAUD, //43 }; /******************************************************************/ @@ -2340,6 +2378,22 @@ class CommCB_VM_GetTerminal : public CommCB Comm_VM_Terminal terminal_; }; +/******************************************************************/ + +class CommCB_changeBaud : public CommCB +{ +public: + CommCB_changeBaud (uint16_t baudRate) : + CommCB (COMM_CBCODE_CHANGE_BAUD), + baudRate_ (baudRate) + {} + +public: + uint16_t baudRate (void) const {return baudRate_;} + +private: + uint16_t baudRate_; +}; /******************************************************************/ /******************************************************************/ @@ -2396,6 +2450,8 @@ union CommCB_Union char vm6[sizeof (CommCB_VM_SetTerminal)]; char vm7[sizeof (CommCB_VM_GetTerminal)]; + + char gen4[sizeof (CommCB_changeBaud)]; }; /******************************************************************/ @@ -2483,10 +2539,13 @@ class Comm : public Applet /********************************/ - void transmit_VM_setTerminal (Comm_VM_Terminal terminal); - void transmit_VM_getTerminal (void); + void transmit_VM_setTerminal (Comm_VM_Terminal terminal); + void transmit_VM_getTerminal (void); + + /********************************/ + + void transmit_changeBaud (uint16_t baudRate); - private: QP4* qp4_; FTDI* ftdi_; @@ -2537,20 +2596,22 @@ class Comm : public Applet void RM_readAutoscaleCB (const void* data, uint16_t size); - void SystemConfig_GetCB (const void* data, uint16_t size); - void SystemConfig_SetCB (const void* data, uint16_t size); - void SystemConfig_SaveCB (const void* data, uint16_t size); + void SystemConfig_GetCB (const void* data, uint16_t size); + void SystemConfig_SetCB (const void* data, uint16_t size); + void SystemConfig_SaveCB (const void* data, uint16_t size); void SystemConfig_LoadDefaultCB (const void* data, uint16_t size); - void VM2_setRangeCB (const void* data, uint16_t size); - void VM2_getCalibrationCB (const void* data, uint16_t size); - void VM2_setCalibrationCB (const void* data, uint16_t size); - void VM2_saveCalibrationCB (const void* data, uint16_t size); - void VM2_readCB (const void* data, uint16_t size); + void VM2_setRangeCB (const void* data, uint16_t size); + void VM2_getCalibrationCB (const void* data, uint16_t size); + void VM2_setCalibrationCB (const void* data, uint16_t size); + void VM2_saveCalibrationCB (const void* data, uint16_t size); + void VM2_readCB (const void* data, uint16_t size); void VM2_loadDefaultCalibrationCB (const void* data, uint16_t size); - void VM_setTerminalCB (const void* data, uint16_t size); - void VM_getTerminalCB (const void* data, uint16_t size); + void VM_setTerminalCB (const void* data, uint16_t size); + void VM_getTerminalCB (const void* data, uint16_t size); + + void changeBaudCB (const void* data, uint16_t size); private: void transmit (const QP4_Packet* packet); diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index eb08e17..5255542 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -230,6 +230,8 @@ void Comm::interpret (const void* data, uint16_t size) &Comm::VM_setTerminalCB, &Comm::VM_getTerminalCB, + + &Comm::changeBaudCB, }; if (size < sizeof (CommPacket)) @@ -722,8 +724,18 @@ void Comm::VM_getTerminalCB (const void* data, uint16_t size) const CommResponse_VM_GetTerminal* res = reinterpret_cast (data); - do_callback (new (&callbackObject_) - CommCB_VM_GetTerminal (res->terminal())); + do_callback (new (&callbackObject_) CommCB_VM_GetTerminal (res->terminal())); +} + +void Comm::changeBaudCB (const void* data, uint16_t size) +{ + if (size < sizeof (CommResponse_changeBaud)) + return; + + const CommResponse_changeBaud* res = + reinterpret_cast (data); + + do_callback (new (&callbackObject_) CommCB_changeBaud (res->baudRate())); } /******************************************************************/ @@ -1354,6 +1366,21 @@ void Comm::transmit_VM_getTerminal (void) qp4_->transmitter().free_packet (req); } +/******************************************************************/ + +void Comm::transmit_changeBaud (uint16_t baudRate) +{ + QP4_Packet* req = + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_changeBaud)); + + new (req->body()) + CommRequest_changeBaud (baudRate); + + req->seal(); + transmit (req); + qp4_->transmitter().free_packet (req); +} /******************************************************************/ /******************************************************************/ } // namespace smu From 109ffa8537ee264643931f0d359deafc43741c48 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Mon, 11 Sep 2017 22:18:30 +0530 Subject: [PATCH 02/50] Changed baudRate from uint16_t to uint32_t --- XSMU-2.4.0/ChangeLog | 34 ++++++++++++++++++++++++++++++++ XSMU-2.4.0/code/app/app/Comm.h | 18 ++++++++--------- XSMU-2.4.0/code/app/src/Comm.cxx | 2 +- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/XSMU-2.4.0/ChangeLog b/XSMU-2.4.0/ChangeLog index 4ef1fda..9676472 100644 --- a/XSMU-2.4.0/ChangeLog +++ b/XSMU-2.4.0/ChangeLog @@ -1,3 +1,37 @@ +#################################################### +# +# ^^ Means updated +# ++ Means added +# +#################################################### + +### 2.4.0 + +2017-09-11 Gitansh Kataria + +* Feature: A command to change baud-rate is added. + +* Comm.h/Comm.cxx: + + ^^ COMM_OPCODE + ++ COMM_OPCODE_CHANGE_BAUD + + ++ class CommPacket_ChangeBaud + ++ class CommRequest_ChangeBaud + ++ class CommResponse_ChangeBaud + + ^^ COMM_CBCODE + ++ COMM_CBCODE_CHANGE_BAUD + + ++ class CommCB_ChangeBaud + + ^^ union CommCB_Union + ++ char gen4 [sizeof (CommCB_ChangeBaud)] + + ^^ class Comm : public Applet + ++ void changeBaud_CB (void*, uint16_t) + ++ void transmit_changeBaud (uint32_t) + ------------------------------------------------------------------------ r6 | (no author) | 2013-08-30 12:51:38 +0530 (Fri, 30 Aug 2013) | 4 lines diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index 0a1c924..01823f6 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -1576,13 +1576,12 @@ class CommPacket_changeBaud : public CommPacket class CommRequest_changeBaud : public CommPacket_changeBaud { public: - CommRequest_changeBaud (uint16_t baudRate) : + CommRequest_changeBaud (uint32_t baudRate) : baudRate_(baudRate) {} private: - uint16_t baudRate_; - uint16_t reserve_; + uint32_t baudRate_; }; class CommResponse_changeBaud : public CommPacket_changeBaud @@ -1591,11 +1590,10 @@ class CommResponse_changeBaud : public CommPacket_changeBaud CommResponse_changeBaud (void); public: - uint16_t baudRate (void) const {return smu::ntoh(baudRate_);} + uint32_t baudRate (void) const {return smu::ntoh(baudRate_);} private: - uint16_t baudRate_; - uint16_t reserve_; + uint32_t baudRate_; }; /******************************************************************/ /******************************************************************/ @@ -2383,16 +2381,16 @@ class CommCB_VM_GetTerminal : public CommCB class CommCB_changeBaud : public CommCB { public: - CommCB_changeBaud (uint16_t baudRate) : + CommCB_changeBaud (uint32_t baudRate) : CommCB (COMM_CBCODE_CHANGE_BAUD), baudRate_ (baudRate) {} public: - uint16_t baudRate (void) const {return baudRate_;} + uint32_t baudRate (void) const {return baudRate_;} private: - uint16_t baudRate_; + uint32_t baudRate_; }; /******************************************************************/ /******************************************************************/ @@ -2544,7 +2542,7 @@ class Comm : public Applet /********************************/ - void transmit_changeBaud (uint16_t baudRate); + void transmit_changeBaud (uint32_t baudRate); private: QP4* qp4_; diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 5255542..1e2c44f 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -1368,7 +1368,7 @@ void Comm::transmit_VM_getTerminal (void) /******************************************************************/ -void Comm::transmit_changeBaud (uint16_t baudRate) +void Comm::transmit_changeBaud (uint32_t baudRate) { QP4_Packet* req = qp4_->transmitter().alloc_packet ( From fc02bd71caab18e07c6710ae3df361e73f31233c Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Tue, 12 Sep 2017 15:18:58 +0530 Subject: [PATCH 03/50] Added functionality to change Baud rate, updated changelog --- XSMU-2.4.0/ChangeLog | 27 +++++++++++++++++++++++++++ XSMU-2.4.0/code/app/app/virtuaSMU.h | 10 ++++++++-- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 23 +++++++++++++++++++++++ XSMU-2.4.0/wrapper/python/libxsmu.cxx | 21 +++++++++++++++++++++ XSMU-2.4.0/wrapper/python/libxsmu.h | 13 ++++++++++--- XSMU-2.4.0/wrapper/python/libxsmu.i | 13 +++++++++++-- 6 files changed, 100 insertions(+), 7 deletions(-) diff --git a/XSMU-2.4.0/ChangeLog b/XSMU-2.4.0/ChangeLog index 9676472..b2d995e 100644 --- a/XSMU-2.4.0/ChangeLog +++ b/XSMU-2.4.0/ChangeLog @@ -7,6 +7,33 @@ ### 2.4.0 +2017-09-12 Gitansh Kataria + +* Feature: A command to change baud-rate is added. + +* virtuaSMU.h/virtuaSMU.cxx: + + ^^ class Driver + ++ uint32_t baudRate_ + ++ void changeBaud (uint32_t*, float*); + ++ void changeBaudCB (CommCB*); + +* libxsmu.h/libxsmu.cxx: + + ++ void changeBaud (int, unsigned int, float, + unsigned int*, float*); + +* libxsmu.i: + + ++ void changeBaud (int, unsigned int, float, + unsigned int*, float*); + ++ void changeBaud (int, unsigned int, float, + unsigned int*, float*); + +------------------------------------------------------------------------ + +### 2.4.0 + 2017-09-11 Gitansh Kataria * Feature: A command to change baud-rate is added. diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index e2aaca4..464595e 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -165,7 +165,10 @@ class Driver { void VM_getTerminal (VM_Terminal* terminal, float* timeout); /***************************************************/ - + + void changeBaud (uint32_t* baudRate, float* timeout); + + /***************************************************/ public: bool goodID (void) const; const char* identity (void) const { @@ -232,6 +235,8 @@ class Driver { void VM_setTerminalCB (const CommCB* oCB); void VM_getTerminalCB (const CommCB* oCB); + + void changeBaudCB (const CommCB* oCB); private: Comm* comm_; @@ -245,12 +250,13 @@ class Driver { VersionInfo* versionInfo_; AckBits ackBits_; std::string identity_; + uint32_t baudRate_; }; /************************************************************************/ /************************************************************************/ -} // namespae smu +} // namespace smu typedef smu::Driver VirtuaSMU; diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index c46d307..ba778bc 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -567,6 +567,17 @@ void Driver::VM_getTerminalCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM_GET_TERMINAL); } +/***************************************************************************/ + +void Driver::changeBaudCB (const CommCB* oCB) +{ + const CommCB_changeBaud* o = + reinterpret_cast (oCB); + + baudRate_ = o->baudRate(); + ackBits_.set (COMM_CBCODE_CHANGE_BAUD); +} + /***************************************************************************/ /***************************************************************************/ @@ -1214,6 +1225,18 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) *terminal = (vm_->terminal()); } +/***************************************************************************/ +/***************************************************************************/ + +void Driver::changeBaud (uint32_t* baudRate, float* timeout) +{ + ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); + comm_->transmit_changeBaud (*baudRate); + + if (waitForResponse (COMM_CBCODE_CHANGE_BAUD, timeout)) + *baudRate = baudRate_; +} + /***************************************************************************/ /***************************************************************************/ } diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index 9d886bc..d764d93 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -812,6 +812,7 @@ void VM_setTerminal(int deviceID, int terminal, float timeout, virtuaSMU->VM_setTerminal(&terminal_, &timeout_); *ret_terminal = 0; + if ((*ret_timeout = timeout_) == 0) return; @@ -830,11 +831,31 @@ void VM_getTerminal(int deviceID, float timeout, virtuaSMU->VM_getTerminal(&terminal_, &timeout_); *ret_terminal = 0; + if ((*ret_timeout = timeout_) == 0) return; *ret_terminal = terminal_; } +/********************************************************************/ + +void changeBaud (int deviceID, unsigned int baudRate, float timeout, + unsigned int *ret_baudRate, float *ret_timeout) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + unsigned int baudRate_ = baudRate; + float timeout_ = timeout; + + virtuaSMU->changeBaud (&baudRate_, &timeout_); + + *ret_baudRate = 9600; + + if ((*ret_timeout = timeout_) == 0) + return; + + *ret_baudRate = baudRate_; +} /********************************************************************/ /********************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.h b/XSMU-2.4.0/wrapper/python/libxsmu.h index fbb41c3..9cd3348 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.h +++ b/XSMU-2.4.0/wrapper/python/libxsmu.h @@ -6,18 +6,20 @@ extern "C" { #endif /** - * \brief Scans USB bus for XPLORE lock-in amplifier. + * \brief Scans USB bus for XPLORE Source-Meter Unit. * - * \return Number of XPLORE lock-in amplifier found. + * \return Number of XPLORE Source-Meter Unit found. * * This function must be called first. It creates an internal - * list of XPLORE lock-in amplifier hardware, whose details, + * list of XPLORE Source-Meter Unit hardware, whose details, * e.g. serial number etc., can then be accessed by other functions, * e.g. \ref serialNo. * */ int scan(void); +/**************************************************************/ + /** * \brief Returns the serial number of a previously scanned device. * @@ -60,6 +62,8 @@ int open_device(const char *serialNo, float timeout, unsigned int *ret_goodID, float *ret_timeout); +/**************************************************************/ + /** * \brief Closes a previously opened device. * @@ -246,6 +250,9 @@ void VM_getTerminal(int deviceID, float timeout, /**************************************************************/ +void changeBaud (int deviceID, unsigned int baudRate, float timeout, + unsigned int *ret_baudRate, float *ret_timeout); + #ifdef __cplusplus } // extern "C" diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.i b/XSMU-2.4.0/wrapper/python/libxsmu.i index d6365ed..852d247 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.i +++ b/XSMU-2.4.0/wrapper/python/libxsmu.i @@ -205,9 +205,13 @@ extern void VM_getTerminal(int deviceID, /**************************************************************/ -%} +extern void changeBaud (int deviceID, unsigned int baudRate, float timeout, + unsigned int *ret_baudRate, float *ret_timeout); /**************************************************************/ + +%} + /**************************************************************/ /**************************************************************/ @@ -380,5 +384,10 @@ extern void VM_getTerminal(int deviceID, float timeout, unsigned int *OUTPUT, float *OUTPUT); /**************************************************************/ -/**************************************************************/ +extern void changeBaud (int deviceID, unsigned int baudRate, float timeout, + unsigned int *OUTPUT, float *OUTPUT); + + +/**************************************************************/ +/**************************************************************/ \ No newline at end of file From 255ba77d70bc126a2510d39e24295426a4326c20 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Tue, 12 Sep 2017 16:48:17 +0530 Subject: [PATCH 04/50] added readme --- Readme.md | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Readme.md diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..828f1f7 --- /dev/null +++ b/Readme.md @@ -0,0 +1,88 @@ +# ``XPLORE-Software`` + +### Introduction + +**How this project fits into the scheme of things** : +- The ``XPLORE`` system is a sophisticated research grade tool that allows for the measurement of electrical and magnetic transport properties of materials over a wide range of temperature. The system is divided into several modules (Fig.~\ref{fig:xplore_electronics}) described in the following sections, each of which allows the user to explore numerous important properties of their sample. + + + +- Each of XPLORE's modules has separate hardware/software + +- Each complete module is made up of the following inter-related layers : +*Hardware* -> *Firmware* -> **Driver -> Application** -> *GUI* + +**Functions of Software :** +- The software is C++ code that runs on the computer. The software can be categorized into : + 1. Driver : This is C++ code, that communicates with the firmware through an FTDI interface. + 2. Application Layer : This contains wrapper functions corresponding to each function in the Driver. `swig` is used to convert these C++ libraries into Python libraries, which further interface with the GUI layer. + +**Structure of Software :** +- The software's code resides in the folder `ModuleName/code`. `ModuleName/code` further contains the following directories : + + 1. `app` : Application code for XPLORE module + 2. `stl` : C++ standard template libraries + 3. `sys` : Libraries for the hardware interface + +`app` is further divided into `app` and `src`, where `app/app` contains all header (`.h`) files and `app/src` contains all `.cxx` files. + +- The libraries reside in the folder `ModuleName/wrapper/python`. The C++ libraries are of the form `libModuleName.h' and `libModuleName.cxx`. `libModuleName.i` is an interface file for `swig`. From these files, `swig` generates a corresponding python library for the module, `libModuleName.py`. The instructions to generate the python library are given in the **Installation** section. + +**Project Page :** + +**Known Issues :** https://github.com/QuazarTech/XPLORE-firmware/issues + +### Requirements + +- XPLORE Physical Quantites Measurement System (Modules on which you want to modify software) + +- Hardware requirements + - Processor : Intel i3 or above + - Storage : Atleast 10 GB + - RAM : Atleast 4 GB + +- OS requirements + The XPLORE system has been tested on the following Operating Systems : + - Ubuntu 16.04 + +- List of Dependencies: + - python 2.7x + - cmake + - swig + - avr-gcc toolchain + + Use the following command to get dependencies : + ``` + sudo apt-get install python cmake swig gcc-avr binutils-avr avr-libc gdb-avr avrdude + ``` +Found a missing dependency? Open an issue here : https://github.com/QuazarTech/XPLORE-software/issues + +### Installation + +1. Download the source code for this project using `git clone ` +2. Navigate to folder `XPLORE-software/ModuleName/` (eg. `XPLORE-software/XSMU-2.4.0/`) +3. Run `make clean` to remove old dependency (`.dep`) files +4. Run `make wrapper` to generate the python library (`libModuleName.py`) file using swig. +5. Run `make install` to install the code in system directories. You might need to run this as `sudo`. +6. The software libraries for the XPLORE module have now been installed on your system. Each module's libraries will need to be installed separately using the above steps. + +### Configuration + + +### Testing + +Tests are provided for each function inside `XPLORE-software/ModuleName/wrapper/python/tests/`. To run the test : + 1. Navigate to `XPLORE-software/ModuleName/wrapper/python/tests/` + 2. Type `python testName.py` and press Enter. + +### Troubleshooting and FAQ + + +### Maintainers + +- Active : + - Krishnendu Chatterjee (kc@quazartech.com) + - Nishant Gupta (nishant@quazartech.com) + - Gitansh Kataria (gitansh@quazartech.com) + +- Past \ No newline at end of file From ba2a1dc8d74d3dba5127b0be6ff88f0b1dfae20f Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Tue, 12 Sep 2017 17:14:44 +0530 Subject: [PATCH 05/50] Added test for changeBaud function --- XSMU-2.4.0/wrapper/python/test/changeBaud.py | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 XSMU-2.4.0/wrapper/python/test/changeBaud.py diff --git a/XSMU-2.4.0/wrapper/python/test/changeBaud.py b/XSMU-2.4.0/wrapper/python/test/changeBaud.py new file mode 100644 index 0000000..d3e14e8 --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/changeBaud.py @@ -0,0 +1,48 @@ +import libxsmu, time, math, sys + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +########################################################################## +# Set voltage source calibration table (for range selected above.) + +timeout = 1.0 +baudRate = 9600 +baudRate, timeout = libxsmu.changeBaud (deviceID, baudRate, timeout) +print \ + "Baud Rate: ", baudRate, "\n" \ + "Timeout: ", timeout + +if (timeout == 0.0): + print 'Communication timeout in changeBaud' + exit (-2) + +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) From baeaafbda8982b611e4d157faba748b18fdb8a7f Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Tue, 12 Sep 2017 19:27:56 +0530 Subject: [PATCH 06/50] added changeBaudTesting.md python test for changeBaud(), and updated Changelog --- XSMU-2.4.0/ChangeLog | 10 ++++ changeBaudTesting.md | 119 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 changeBaudTesting.md diff --git a/XSMU-2.4.0/ChangeLog b/XSMU-2.4.0/ChangeLog index b2d995e..9fd47f9 100644 --- a/XSMU-2.4.0/ChangeLog +++ b/XSMU-2.4.0/ChangeLog @@ -9,6 +9,16 @@ 2017-09-12 Gitansh Kataria +* Feature: Python test file for changeBaud() function + +++ changeBaud.py + +------------------------------------------------------------------------ + +### 2.4.0 + +2017-09-12 Gitansh Kataria + * Feature: A command to change baud-rate is added. * virtuaSMU.h/virtuaSMU.cxx: diff --git a/changeBaudTesting.md b/changeBaudTesting.md new file mode 100644 index 0000000..86516a4 --- /dev/null +++ b/changeBaudTesting.md @@ -0,0 +1,119 @@ +# ``XPLORE Streamer`` + +### Feature + +Version : 2.4.0 +================ + + Nature : Feature + Requested by : Quazar Research + + Status : Pending + Created on : 2017-09-09 by KC + Closed on : --- + +Description +----------- + +The SMU is to stream voltmeter data at a specified frequency. This requires following features to be implemented. + + 1) Dynamically change baudrate to suit data stream. + + -- CHANGE_BAUD + + 2) Start recording + + -- START_REC : Starts recording of timed data into internal buffer. + + 3) Transfer recorded data chunks to computer + + -- REC_SIZE : Queries number of available data points in buffer + + -- REC_DATA : Transfers requested number of data points to driver. + + 5) Stop recording + + -- STOP_REC : Stops recording gracefully. + + -- KEEP_ALIVE : Stops recording if keep alive packets are not received, i.e. driver is dead. + +### Modifications + +##### Firmware +-------------- + +* Comm.h/Comm.cxx: + + ^^ COMM_OPCODE + ++ COMM_OPCODE_CHANGE_BAUD + + ++ class CommPacket_ChangeBaud + ++ class CommRequest_ChangeBaud + ++ class CommResponse_ChangeBaud + + ^^ COMM_CBCODE + ++ COMM_CBCODE_CHANGE_BAUD + + ++ class CommCB_ChangeBaud + + ^^ union CommCB_Union + ++ char gen4 [sizeof (CommCB_ChangeBaud)] + + ^^ class Comm : public Applet + ++ void changeBaud_CB (void*, uint16_t) + ++ void transmit_changeBaud (uint16_t) +-------------- + +##### Software +-------------- + +* virtuaSMU.h/virtuaSMU.cxx: + + ^^ class Driver + ++ uint32_t baudRate_ + ++ void changeBaud (uint32_t*, float*); + ++ void changeBaudCB (CommCB*); +-------------- + +* libxsmu.h/libxsmu.cxx/libxsmu.i: + + ++ void changeBaud (int, unsigned int, float, + unsigned int*, float*); + +-------------- + +* Comm.h/Comm.cxx: + + ^^ COMM_OPCODE + ++ COMM_OPCODE_CHANGE_BAUD + + ++ class CommPacket_ChangeBaud + ++ class CommRequest_ChangeBaud + ++ class CommResponse_ChangeBaud + + ^^ COMM_CBCODE + ++ COMM_CBCODE_CHANGE_BAUD + + ++ class CommCB_ChangeBaud + + ^^ union CommCB_Union + ++ char gen4 [sizeof (CommCB_ChangeBaud)] + + ^^ class Comm : public Applet + ++ void changeBaud_CB (void*, uint16_t) + ++ void transmit_changeBaud (uint32_t) + +-------------- + +++ changeBaud.py + +### Testing + +- Burn modified Firmware onto the SMU microcontroller (Follow : `XPLORE-firmware` README ) +- Install modified software on computer (Follow : `XPLORE-software` README) + +- Testing `changeBaud(baudRate)` function + - Testing : Communication Channel + - Navigate to `XPLORE-software/XSMU-2.4.0/wrapper/python/tests/` + - Run `python changeBaud.py` + - Expected Result : Control should return back to python within specified timeout (1 second) From 926c955f98e9575ae172fd51c7b149932597d47f Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 13 Sep 2017 13:31:07 +0530 Subject: [PATCH 07/50] Added print statements for debugging --- XSMU-2.4.0/code/app/src/Comm.cxx | 7 +++++ XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 9 +++++++ changeBaudTesting.md | 38 ++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 1e2c44f..1d24d15 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -149,6 +149,7 @@ void Comm::checkReceiveQueue (void) uint32_t rxsize; while ((rxsize = ftdi_->read (rxbuf, sizeof (rxbuf)))) + std::cout << "Comm : Recieved Data Size : " << rxsize << std::endl; processReceivedData (rxbuf, rxsize); } @@ -730,12 +731,15 @@ void Comm::VM_getTerminalCB (const void* data, uint16_t size) void Comm::changeBaudCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_changeBaud)) + std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; return; + std::cout << "Comm : Packet Size Okay" << std::endl; const CommResponse_changeBaud* res = reinterpret_cast (data); do_callback (new (&callbackObject_) CommCB_changeBaud (res->baudRate())); + std::cout << "Comm : Callback Completed" << std::endl; } /******************************************************************/ @@ -1373,12 +1377,15 @@ void Comm::transmit_changeBaud (uint32_t baudRate) QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_changeBaud)); + std::cout << "Comm : QP4_Packet allocated" << std::endl; new (req->body()) CommRequest_changeBaud (baudRate); req->seal(); transmit (req); + std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; + qp4_->transmitter().free_packet (req); } /******************************************************************/ diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index ba778bc..993c7c1 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -571,11 +571,16 @@ void Driver::VM_getTerminalCB (const CommCB* oCB) void Driver::changeBaudCB (const CommCB* oCB) { + std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; + const CommCB_changeBaud* o = reinterpret_cast (oCB); baudRate_ = o->baudRate(); + std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; + ackBits_.set (COMM_CBCODE_CHANGE_BAUD); + std::cout << "virtuaSMU : AckBits Set" << std::endl; } /***************************************************************************/ @@ -1231,9 +1236,13 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) void Driver::changeBaud (uint32_t* baudRate, float* timeout) { ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); + std::cout << "virtuaSMU : AckBits Reset" << std::endl; + comm_->transmit_changeBaud (*baudRate); + std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; if (waitForResponse (COMM_CBCODE_CHANGE_BAUD, timeout)) + std::cout << "virtuaSMU : Recieved Response" << std::endl; *baudRate = baudRate_; } diff --git a/changeBaudTesting.md b/changeBaudTesting.md index 86516a4..ffa9df0 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -107,7 +107,7 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll ++ changeBaud.py -### Testing +### Test-1 - Burn modified Firmware onto the SMU microcontroller (Follow : `XPLORE-firmware` README ) - Install modified software on computer (Follow : `XPLORE-software` README) @@ -117,3 +117,39 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll - Navigate to `XPLORE-software/XSMU-2.4.0/wrapper/python/tests/` - Run `python changeBaud.py` - Expected Result : Control should return back to python within specified timeout (1 second) + +##### Result : Failed + +- Output : Communication Timeout in changeBaud + + +##### Debugging + +- Add print statements to XPLORE-software part and use LCD to print from the XPLORE-firmware part + +^^ virtuaSMU.cxx + ^^ void Driver::changeBaudCB (const CommCB*) + ++ std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; + ++ std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; + ++ std::cout << "virtuaSMU : AckBits Set" << std::endl; + + ^^ void Driver::changeBaud (uint32_t*, float*) + ++ std::cout << "virtuaSMU : AckBits Reset" << std::endl; + ++ std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; + ++ std::cout << "virtuaSMU : Recieved Response" << std::endl; + +^^ Comm.cxx + ^^ void Comm::changeBaudCB (const void* data, uint16_t size) + ++ std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; + ++ std::cout << "Comm : Packet Size Okay" << std::endl; + ++ std::cout << "Comm : Callback Completed" << std::endl; + + ^^ void Comm::transmit_changeBaud (uint32_t baudRate) + ++ std::cout << "Comm : QP4_Packet allocated" << std::endl; + ++ std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; + + ^^ checkRecieveQueue() + ++ std::cout << "Comm : Recieved Data Size : " << rxsize << std::endl; + +##### Result : + From d3a9207070fcf5add3fbd8011fc5fc81c8ad97ca Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 13 Sep 2017 14:02:52 +0530 Subject: [PATCH 08/50] Updated changeBaudTesting.md --- changeBaudTesting.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/changeBaudTesting.md b/changeBaudTesting.md index ffa9df0..dc3fc3c 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -151,5 +151,11 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll ^^ checkRecieveQueue() ++ std::cout << "Comm : Recieved Data Size : " << rxsize << std::endl; +- Looked at XPLORE-firmware Changelog, and realised that I haven't written functions to interface the firmware's (XPLORE-firmware) Comm.cxx to the driver (XPLORE-software). Adding the required functions in XPLORE-firmware, and updating its Changelog. + +- Also changing `timeout` to 5 seconds in `XPLORE-software/wrapper/python/test/changeBaud.py` + +- Redoing **Test-1** with the above mentioned modifications. + ##### Result : From 2269b98a137d7c310d256970aab726ef5dd4146e Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 13 Sep 2017 14:22:39 +0530 Subject: [PATCH 09/50] commented out all print statements added in prev commit --- XSMU-2.4.0/code/app/src/Comm.cxx | 12 ++++++------ XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 12 ++++++------ changeBaudTesting.md | 7 ++++++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 1d24d15..2d0e233 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -149,7 +149,7 @@ void Comm::checkReceiveQueue (void) uint32_t rxsize; while ((rxsize = ftdi_->read (rxbuf, sizeof (rxbuf)))) - std::cout << "Comm : Recieved Data Size : " << rxsize << std::endl; + //std::cout << "Comm : Recieved Data Size : " << rxsize << std::endl; processReceivedData (rxbuf, rxsize); } @@ -731,15 +731,15 @@ void Comm::VM_getTerminalCB (const void* data, uint16_t size) void Comm::changeBaudCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_changeBaud)) - std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; + //std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; return; - std::cout << "Comm : Packet Size Okay" << std::endl; + //std::cout << "Comm : Packet Size Okay" << std::endl; const CommResponse_changeBaud* res = reinterpret_cast (data); do_callback (new (&callbackObject_) CommCB_changeBaud (res->baudRate())); - std::cout << "Comm : Callback Completed" << std::endl; + //std::cout << "Comm : Callback Completed" << std::endl; } /******************************************************************/ @@ -1377,14 +1377,14 @@ void Comm::transmit_changeBaud (uint32_t baudRate) QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_changeBaud)); - std::cout << "Comm : QP4_Packet allocated" << std::endl; + //std::cout << "Comm : QP4_Packet allocated" << std::endl; new (req->body()) CommRequest_changeBaud (baudRate); req->seal(); transmit (req); - std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; + //std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; qp4_->transmitter().free_packet (req); } diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 993c7c1..597f751 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -571,16 +571,16 @@ void Driver::VM_getTerminalCB (const CommCB* oCB) void Driver::changeBaudCB (const CommCB* oCB) { - std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; + //std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; const CommCB_changeBaud* o = reinterpret_cast (oCB); baudRate_ = o->baudRate(); - std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; + //std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; ackBits_.set (COMM_CBCODE_CHANGE_BAUD); - std::cout << "virtuaSMU : AckBits Set" << std::endl; + //std::cout << "virtuaSMU : AckBits Set" << std::endl; } /***************************************************************************/ @@ -1236,13 +1236,13 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) void Driver::changeBaud (uint32_t* baudRate, float* timeout) { ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); - std::cout << "virtuaSMU : AckBits Reset" << std::endl; + //std::cout << "virtuaSMU : AckBits Reset" << std::endl; comm_->transmit_changeBaud (*baudRate); - std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; + //std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; if (waitForResponse (COMM_CBCODE_CHANGE_BAUD, timeout)) - std::cout << "virtuaSMU : Recieved Response" << std::endl; + //std::cout << "virtuaSMU : Recieved Response" << std::endl; *baudRate = baudRate_; } diff --git a/changeBaudTesting.md b/changeBaudTesting.md index dc3fc3c..3bdd958 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -157,5 +157,10 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll - Redoing **Test-1** with the above mentioned modifications. -##### Result : +##### Result : Communication Timeout + +- Adding print statements increased the execution time, and the default timeout of 1 second is not sufficient. Retrying with the all print statements commited out. + +##### Result : Communication Timeout + From 21bd98994e689279cf38f1dc30567c3e48aa6dee Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 13 Sep 2017 14:56:24 +0530 Subject: [PATCH 10/50] Uncommented all print lines except Recieved data size : rxsize --- XSMU-2.4.0/code/app/src/Comm.cxx | 10 +++++----- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 12 ++++++------ changeBaudTesting.md | 27 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 2d0e233..2daef4d 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -731,15 +731,15 @@ void Comm::VM_getTerminalCB (const void* data, uint16_t size) void Comm::changeBaudCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_changeBaud)) - //std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; + std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; return; - //std::cout << "Comm : Packet Size Okay" << std::endl; + std::cout << "Comm : Packet Size Okay" << std::endl; const CommResponse_changeBaud* res = reinterpret_cast (data); do_callback (new (&callbackObject_) CommCB_changeBaud (res->baudRate())); - //std::cout << "Comm : Callback Completed" << std::endl; + std::cout << "Comm : Callback Completed" << std::endl; } /******************************************************************/ @@ -1377,14 +1377,14 @@ void Comm::transmit_changeBaud (uint32_t baudRate) QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_changeBaud)); - //std::cout << "Comm : QP4_Packet allocated" << std::endl; + std::cout << "Comm : QP4_Packet allocated" << std::endl; new (req->body()) CommRequest_changeBaud (baudRate); req->seal(); transmit (req); - //std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; + std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; qp4_->transmitter().free_packet (req); } diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 597f751..993c7c1 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -571,16 +571,16 @@ void Driver::VM_getTerminalCB (const CommCB* oCB) void Driver::changeBaudCB (const CommCB* oCB) { - //std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; + std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; const CommCB_changeBaud* o = reinterpret_cast (oCB); baudRate_ = o->baudRate(); - //std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; + std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; ackBits_.set (COMM_CBCODE_CHANGE_BAUD); - //std::cout << "virtuaSMU : AckBits Set" << std::endl; + std::cout << "virtuaSMU : AckBits Set" << std::endl; } /***************************************************************************/ @@ -1236,13 +1236,13 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) void Driver::changeBaud (uint32_t* baudRate, float* timeout) { ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); - //std::cout << "virtuaSMU : AckBits Reset" << std::endl; + std::cout << "virtuaSMU : AckBits Reset" << std::endl; comm_->transmit_changeBaud (*baudRate); - //std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; + std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; if (waitForResponse (COMM_CBCODE_CHANGE_BAUD, timeout)) - //std::cout << "virtuaSMU : Recieved Response" << std::endl; + std::cout << "virtuaSMU : Recieved Response" << std::endl; *baudRate = baudRate_; } diff --git a/changeBaudTesting.md b/changeBaudTesting.md index 3bdd958..3ee8da0 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -163,4 +163,31 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll ##### Result : Communication Timeout +- Added LCD print statements to firmware (Application.cxx) inside Application::changeBaudCB() function + + ``` + freezeLocalDisplay(); + lcd.cursorAt (0, 0); + lcd << " Entering "; + + lcd.cursorAt (1, 0); + lcd << " changeBaudCB "; + + + const CommCB_changeBaud* o = + reinterpret_cast (oCB); + + baudRate = o->baudRate(); + appComm.transmit_changeBaud (baudRate); + + + freezeLocalDisplay(); + lcd.cursorAt (0, 0); + lcd << " Transmitted "; + + lcd.cursorAt (1, 0); + lcd << " changeBaud "; + ``` +} +##### Result : \ No newline at end of file From d0288f83db98f62e28e10bcb5e61a822a7001661 Mon Sep 17 00:00:00 2001 From: Shyam Date: Wed, 13 Sep 2017 15:33:33 +0530 Subject: [PATCH 11/50] updated results of test --- XSMU-2.4.0/wrapper/python/test/changeBaud.py | 2 +- changeBaudTesting.md | 27 +++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/XSMU-2.4.0/wrapper/python/test/changeBaud.py b/XSMU-2.4.0/wrapper/python/test/changeBaud.py index d3e14e8..80f76f7 100644 --- a/XSMU-2.4.0/wrapper/python/test/changeBaud.py +++ b/XSMU-2.4.0/wrapper/python/test/changeBaud.py @@ -31,7 +31,7 @@ ########################################################################## # Set voltage source calibration table (for range selected above.) -timeout = 1.0 +timeout = 5.0 baudRate = 9600 baudRate, timeout = libxsmu.changeBaud (deviceID, baudRate, timeout) print \ diff --git a/changeBaudTesting.md b/changeBaudTesting.md index 3ee8da0..a33463e 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -190,4 +190,29 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll ``` } -##### Result : \ No newline at end of file +##### Result : Failed + +##### Output : +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +Hardware version: 4.0.0 +Firmware version: 255.255.253 +Device ID : 0 +goodID : 1 +Remaining time: 0.887270927429 sec + +virtuaSMU : AckBits Reset +Comm : QP4_Packet allocated +Comm : Packet Sealed and Transmitted +virtuaSMU : Transmitted baudRate, Starting wait for response +``` +On LCD -> "Entering changeBaudCB" +On LCD -> "Transmitted changeBaud" +``` +Baud Rate: 9600 +Timeout: 0.0 +Communication timeout in changeBaud +``` From 6fe5ad416ee33dd77e0229783f0ea30cfd727b19 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 13 Sep 2017 16:22:47 +0530 Subject: [PATCH 12/50] format changes in changeBaudTesting.md --- changeBaudTesting.md | 60 ++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/changeBaudTesting.md b/changeBaudTesting.md index a33463e..cc72fe0 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -122,6 +122,7 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll - Output : Communication Timeout in changeBaud +--- ##### Debugging @@ -159,10 +160,18 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll ##### Result : Communication Timeout +- Output : Communication Timeout in changeBaud + +--- + - Adding print statements increased the execution time, and the default timeout of 1 second is not sufficient. Retrying with the all print statements commited out. ##### Result : Communication Timeout +- Output : Communication Timeout in changeBaud + +--- + - Added LCD print statements to firmware (Application.cxx) inside Application::changeBaudCB() function ``` @@ -192,27 +201,30 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll ##### Result : Failed -##### Output : -``` -libxsmu version: 2.1.2 -Total device: 1 -Seial number: XSMU012A -libxsmu version: 2.1.2 -Hardware version: 4.0.0 -Firmware version: 255.255.253 -Device ID : 0 -goodID : 1 -Remaining time: 0.887270927429 sec - -virtuaSMU : AckBits Reset -Comm : QP4_Packet allocated -Comm : Packet Sealed and Transmitted -virtuaSMU : Transmitted baudRate, Starting wait for response -``` -On LCD -> "Entering changeBaudCB" -On LCD -> "Transmitted changeBaud" -``` -Baud Rate: 9600 -Timeout: 0.0 -Communication timeout in changeBaud -``` +- Output : + + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + Device ID : 0 + goodID : 1 + Remaining time: 0.887270927429 sec + + virtuaSMU : AckBits Reset + Comm : QP4_Packet allocated + Comm : Packet Sealed and Transmitted + virtuaSMU : Transmitted baudRate, Starting wait for response + ``` + + On LCD -> "Entering changeBaudCB" + On LCD -> "Transmitted changeBaud" + + ``` + Baud Rate: 9600 + Timeout: 0.0 + Communication timeout in changeBaud + ``` From 6a0338b3f2ca6038623e63740e684f798cde2c50 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 13 Sep 2017 17:21:39 +0530 Subject: [PATCH 13/50] Added print statements for VS_setVoltage --- XSMU-2.4.0/code/app/src/Comm.cxx | 6 ++++++ XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 2daef4d..f7d13e8 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -412,13 +412,16 @@ void Comm::VS_saveCalibrationCB (const void* data, uint16_t size) void Comm::VS_setVoltageCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_VS_SetVoltage)) + std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; return; + std::cout << "Comm : Packet Size Okay" << std::endl; const CommResponse_VS_SetVoltage* res = reinterpret_cast (data); do_callback (new (&callbackObject_) CommCB_VS_SetVoltage (res->voltage())); + std::cout << "Comm : Callback Completed" << std::endl; } /******************************************************************/ @@ -960,12 +963,15 @@ void Comm::transmit_VS_setVoltage (float voltage) QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_VS_SetVoltage)); + std::cout << "Comm : QP4_Packet allocated" << std::endl; new (req->body()) CommRequest_VS_SetVoltage (voltage); req->seal(); transmit (req); + std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; + qp4_->transmitter().free_packet (req); } diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 993c7c1..bbb54f9 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -306,11 +306,15 @@ void Driver::VS_saveCalibrationCB (const CommCB* oCB) void Driver::VS_setVoltageCB (const CommCB* oCB) { + std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; const CommCB_VS_SetVoltage* o = reinterpret_cast (oCB); vs_->setVoltage (o->voltage()); + std::cout << "virtuaSMU : Retrieved Set Voltage" << std::endl; + ackBits_.set (COMM_CBCODE_VS_SET_VOLTAGE); + std::cout << "virtuaSMU : AckBits Set" << std::endl; } /***************************************************************************/ @@ -866,9 +870,13 @@ void Driver::VS_saveCalibration (float* timeout) void Driver::VS_setVoltage (float* voltage, float* timeout) { ackBits_.reset (COMM_CBCODE_VS_SET_VOLTAGE); + std::cout << "virtuaSMU : AckBits Reset" << std::endl; + comm_->transmit_VS_setVoltage (*voltage); + std::cout << "virtuaSMU : Transmitted setVoltage, Starting wait for response" << std::endl; if (waitForResponse (COMM_CBCODE_VS_SET_VOLTAGE, timeout)) + std::cout << "virtuaSMU : Recieved Response" << std::endl; *voltage = vs_->voltage(); } From 4f00089c223f6930fb5e8725261a81afb5b77456 Mon Sep 17 00:00:00 2001 From: Shyam Date: Wed, 13 Sep 2017 17:42:10 +0530 Subject: [PATCH 14/50] Commented out print statements, changed VS_setVoltage timeout to 5 seconds --- XSMU-2.4.0/code/app/src/Comm.cxx | 20 ++++++++-------- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 24 +++++++++---------- .../wrapper/python/test/VS_setVoltage.py | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index f7d13e8..10c76ee 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -412,16 +412,16 @@ void Comm::VS_saveCalibrationCB (const void* data, uint16_t size) void Comm::VS_setVoltageCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_VS_SetVoltage)) - std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; + //std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; return; - std::cout << "Comm : Packet Size Okay" << std::endl; + //std::cout << "Comm : Packet Size Okay" << std::endl; const CommResponse_VS_SetVoltage* res = reinterpret_cast (data); do_callback (new (&callbackObject_) CommCB_VS_SetVoltage (res->voltage())); - std::cout << "Comm : Callback Completed" << std::endl; + //std::cout << "Comm : Callback Completed" << std::endl; } /******************************************************************/ @@ -734,15 +734,15 @@ void Comm::VM_getTerminalCB (const void* data, uint16_t size) void Comm::changeBaudCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_changeBaud)) - std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; + //std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; return; - std::cout << "Comm : Packet Size Okay" << std::endl; + //std::cout << "Comm : Packet Size Okay" << std::endl; const CommResponse_changeBaud* res = reinterpret_cast (data); do_callback (new (&callbackObject_) CommCB_changeBaud (res->baudRate())); - std::cout << "Comm : Callback Completed" << std::endl; + //std::cout << "Comm : Callback Completed" << std::endl; } /******************************************************************/ @@ -963,14 +963,14 @@ void Comm::transmit_VS_setVoltage (float voltage) QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_VS_SetVoltage)); - std::cout << "Comm : QP4_Packet allocated" << std::endl; + //std::cout << "Comm : QP4_Packet allocated" << std::endl; new (req->body()) CommRequest_VS_SetVoltage (voltage); req->seal(); transmit (req); - std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; + //std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; qp4_->transmitter().free_packet (req); } @@ -1383,14 +1383,14 @@ void Comm::transmit_changeBaud (uint32_t baudRate) QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_changeBaud)); - std::cout << "Comm : QP4_Packet allocated" << std::endl; + //std::cout << "Comm : QP4_Packet allocated" << std::endl; new (req->body()) CommRequest_changeBaud (baudRate); req->seal(); transmit (req); - std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; + //std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; qp4_->transmitter().free_packet (req); } diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index bbb54f9..98eb43c 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -306,15 +306,15 @@ void Driver::VS_saveCalibrationCB (const CommCB* oCB) void Driver::VS_setVoltageCB (const CommCB* oCB) { - std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; + //std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; const CommCB_VS_SetVoltage* o = reinterpret_cast (oCB); vs_->setVoltage (o->voltage()); - std::cout << "virtuaSMU : Retrieved Set Voltage" << std::endl; + //std::cout << "virtuaSMU : Retrieved Set Voltage" << std::endl; ackBits_.set (COMM_CBCODE_VS_SET_VOLTAGE); - std::cout << "virtuaSMU : AckBits Set" << std::endl; + //std::cout << "virtuaSMU : AckBits Set" << std::endl; } /***************************************************************************/ @@ -575,16 +575,16 @@ void Driver::VM_getTerminalCB (const CommCB* oCB) void Driver::changeBaudCB (const CommCB* oCB) { - std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; + //std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; const CommCB_changeBaud* o = reinterpret_cast (oCB); baudRate_ = o->baudRate(); - std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; + //std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; ackBits_.set (COMM_CBCODE_CHANGE_BAUD); - std::cout << "virtuaSMU : AckBits Set" << std::endl; + //std::cout << "virtuaSMU : AckBits Set" << std::endl; } /***************************************************************************/ @@ -870,13 +870,13 @@ void Driver::VS_saveCalibration (float* timeout) void Driver::VS_setVoltage (float* voltage, float* timeout) { ackBits_.reset (COMM_CBCODE_VS_SET_VOLTAGE); - std::cout << "virtuaSMU : AckBits Reset" << std::endl; + //std::cout << "virtuaSMU : AckBits Reset" << std::endl; comm_->transmit_VS_setVoltage (*voltage); - std::cout << "virtuaSMU : Transmitted setVoltage, Starting wait for response" << std::endl; + //std::cout << "virtuaSMU : Transmitted setVoltage, Starting wait for response" << std::endl; if (waitForResponse (COMM_CBCODE_VS_SET_VOLTAGE, timeout)) - std::cout << "virtuaSMU : Recieved Response" << std::endl; + // std::cout << "virtuaSMU : Recieved Response" << std::endl; *voltage = vs_->voltage(); } @@ -1244,13 +1244,13 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) void Driver::changeBaud (uint32_t* baudRate, float* timeout) { ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); - std::cout << "virtuaSMU : AckBits Reset" << std::endl; + //std::cout << "virtuaSMU : AckBits Reset" << std::endl; comm_->transmit_changeBaud (*baudRate); - std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; + //std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; if (waitForResponse (COMM_CBCODE_CHANGE_BAUD, timeout)) - std::cout << "virtuaSMU : Recieved Response" << std::endl; + // std::cout << "virtuaSMU : Recieved Response" << std::endl; *baudRate = baudRate_; } diff --git a/XSMU-2.4.0/wrapper/python/test/VS_setVoltage.py b/XSMU-2.4.0/wrapper/python/test/VS_setVoltage.py index fadca4c..c89218f 100644 --- a/XSMU-2.4.0/wrapper/python/test/VS_setVoltage.py +++ b/XSMU-2.4.0/wrapper/python/test/VS_setVoltage.py @@ -31,7 +31,7 @@ ########################################################################## # Set voltage source calibration table (for range selected above.) -timeout = 1.0 +timeout = 5.0 voltage = float(sys.argv[1]) #-10.0 voltage, timeout = libxsmu.VS_setVoltage (deviceID, voltage, timeout) print \ From 5ff6934fd5ce19a9f8d689062349bd0f8264223c Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 13 Sep 2017 18:52:39 +0530 Subject: [PATCH 15/50] Added print statement for rxsize in Comm.cxx --- XSMU-2.4.0/code/app/app/Comm.h | 19 +++++++++---------- XSMU-2.4.0/code/app/src/Comm.cxx | 10 ++++++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index 01823f6..f7b3b4b 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -64,7 +64,7 @@ enum Comm_Opcode COMM_OPCODE_VM2_LOAD_DEFAULT_CALIBRATION, //40 COMM_OPCODE_VM_SET_TERMINAL, //41 COMM_OPCODE_VM_GET_TERMINAL, //42 - + COMM_OPCODE_CHANGE_BAUD, //43 }; @@ -1577,7 +1577,7 @@ class CommRequest_changeBaud : public CommPacket_changeBaud { public: CommRequest_changeBaud (uint32_t baudRate) : - baudRate_(baudRate) + baudRate_ (smu::hton (baudRate)) {} private: @@ -1653,7 +1653,7 @@ enum Comm_CallbackCode COMM_CBCODE_VM_SET_TERMINAL, //41 COMM_CBCODE_VM_GET_TERMINAL, //42 - + COMM_CBCODE_CHANGE_BAUD, //43 }; @@ -2401,6 +2401,7 @@ union CommCB_Union char gen1[sizeof (CommCB_Identity)]; char gen2[sizeof (CommCB_Sync)]; char gen3[sizeof (CommCB_SetSourceMode)]; + char gen4[sizeof (CommCB_changeBaud)]; char cs0[sizeof (CommCB_CS_SetRange)]; char cs1[sizeof (CommCB_CS_GetCalibration)]; @@ -2448,8 +2449,6 @@ union CommCB_Union char vm6[sizeof (CommCB_VM_SetTerminal)]; char vm7[sizeof (CommCB_VM_GetTerminal)]; - - char gen4[sizeof (CommCB_changeBaud)]; }; /******************************************************************/ @@ -2536,14 +2535,14 @@ class Comm : public Applet void transmit_VM2_loadDefaultCalibration (void); /********************************/ - + void transmit_VM_setTerminal (Comm_VM_Terminal terminal); void transmit_VM_getTerminal (void); - + /********************************/ - + void transmit_changeBaud (uint32_t baudRate); - + private: QP4* qp4_; FTDI* ftdi_; @@ -2608,7 +2607,7 @@ class Comm : public Applet void VM_setTerminalCB (const void* data, uint16_t size); void VM_getTerminalCB (const void* data, uint16_t size); - + void changeBaudCB (const void* data, uint16_t size); private: diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 10c76ee..12fa7ea 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -1,5 +1,6 @@ #include "../app/Comm.h" +#include #include #include #include @@ -159,6 +160,7 @@ void Comm::processReceivedData (const void* data, uint16_t size) if (size) do { + std::printf ("%X %c\n", static_cast (*src), *src); qp4_->receiver().push_back (*src++); if (qp4_->receiver().ready()) { @@ -231,7 +233,7 @@ void Comm::interpret (const void* data, uint16_t size) &Comm::VM_setTerminalCB, &Comm::VM_getTerminalCB, - + &Comm::changeBaudCB, }; @@ -740,7 +742,7 @@ void Comm::changeBaudCB (const void* data, uint16_t size) const CommResponse_changeBaud* res = reinterpret_cast (data); - + do_callback (new (&callbackObject_) CommCB_changeBaud (res->baudRate())); //std::cout << "Comm : Callback Completed" << std::endl; } @@ -1387,11 +1389,11 @@ void Comm::transmit_changeBaud (uint32_t baudRate) new (req->body()) CommRequest_changeBaud (baudRate); - + req->seal(); transmit (req); //std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; - + qp4_->transmitter().free_packet (req); } /******************************************************************/ From c4b820f33c179a7e9eca6d0db1179a14230bedea Mon Sep 17 00:00:00 2001 From: Shyam Date: Wed, 13 Sep 2017 19:07:34 +0530 Subject: [PATCH 16/50] Updated testing results --- changeBaudTesting.md | 99 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/changeBaudTesting.md b/changeBaudTesting.md index cc72fe0..9ef3b7e 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -228,3 +228,102 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll Timeout: 0.0 Communication timeout in changeBaud ``` +--- + +- Added print statements to VS_setVoltage functions to see internal working + +##### Result : Failed + +- Output : timeout error even in setVoltage functions, reason being printing these statements lead to execution time exceeding the timeout. +--- + +- Added print statement in virtuaSMU.cxx (software), to see the characters and corresponding hex numbers being transmitted. + +##### Result : Timeout + +- Output : + +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +51 Q +50 P +34 4 +31 1 +0 +2C , +F9 � +12  +0 +1  +0 +0 +58 X +50 P +4C L +4F O +52 R +45 E +20 +53 S +4D M +55 U +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +4  +0 +0 +FF � +FF � +FF � +FD � +Hardware version: 4.0.0 +Firmware version: 255.255.253 +Device ID : 0 +goodID : 1 +Remaining time: 0.889459848404 sec + +51 Q +50 P +34 4 +31 1 +0 +8 +FF � +30 0 +0 +2B + +0 +0 +0 +0 +25 % +80 � +Baud Rate: 9600 +Timeout: 0.0 +Communication timeout in changeBaud +``` + From c5d9a046fb4fa136a695da0a6f9b6ec5f13aff59 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 13 Sep 2017 19:40:17 +0530 Subject: [PATCH 17/50] Added PRINT_DEBUG statements to Comm.cxx --- XSMU-2.4.0/code/app/src/Comm.cxx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 12fa7ea..5ed8b6f 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -5,6 +5,9 @@ #include #include +#define PRINT_DEBUG(x) { \ +std::cerr << __PRETTY_FUNCTION__ << ":" << __LINE__ << ":" << x << std::endl; } + using namespace std; namespace smu { @@ -243,6 +246,8 @@ void Comm::interpret (const void* data, uint16_t size) const CommPacket *packet = reinterpret_cast (data); + PRINT_DEBUG ("Opcode: " << packet->opcode()); + if (packet->opcode() < sizeof (cbs) / sizeof (cbs[0])) (this->*cbs[packet->opcode()])(data, size); } @@ -414,16 +419,13 @@ void Comm::VS_saveCalibrationCB (const void* data, uint16_t size) void Comm::VS_setVoltageCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_VS_SetVoltage)) - //std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; return; - //std::cout << "Comm : Packet Size Okay" << std::endl; const CommResponse_VS_SetVoltage* res = reinterpret_cast (data); do_callback (new (&callbackObject_) CommCB_VS_SetVoltage (res->voltage())); - //std::cout << "Comm : Callback Completed" << std::endl; } /******************************************************************/ @@ -735,16 +737,19 @@ void Comm::VM_getTerminalCB (const void* data, uint16_t size) void Comm::changeBaudCB (const void* data, uint16_t size) { - if (size < sizeof (CommResponse_changeBaud)) - //std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; + if (size < sizeof (CommResponse_changeBaud)) { + + PRINT_DEBUG ("Comm : Packet Size Smaller than Expected") return; - //std::cout << "Comm : Packet Size Okay" << std::endl; + } + + PRINT_DEBUG ("Comm : Packet Size Okay"); const CommResponse_changeBaud* res = reinterpret_cast (data); do_callback (new (&callbackObject_) CommCB_changeBaud (res->baudRate())); - //std::cout << "Comm : Callback Completed" << std::endl; + PRINT_DEBUG ("Comm : Callback Completed"); } /******************************************************************/ @@ -1385,14 +1390,14 @@ void Comm::transmit_changeBaud (uint32_t baudRate) QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_changeBaud)); - //std::cout << "Comm : QP4_Packet allocated" << std::endl; + PRINT_DEBUG ("Comm : QP4_Packet allocated"); new (req->body()) CommRequest_changeBaud (baudRate); req->seal(); transmit (req); - //std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; + PRINT_DEBUG ("Comm : Packet Sealed and Transmitted"); qp4_->transmitter().free_packet (req); } From 0576e1c03317a5f9b4c4097fee36254f705bee43 Mon Sep 17 00:00:00 2001 From: Shyam Date: Wed, 13 Sep 2017 19:43:59 +0530 Subject: [PATCH 18/50] Added PRINT_DEBUG test results --- changeBaudTesting.md | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/changeBaudTesting.md b/changeBaudTesting.md index 9ef3b7e..c963aad 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -326,4 +326,94 @@ Baud Rate: 9600 Timeout: 0.0 Communication timeout in changeBaud ``` +--- +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +51 Q +50 P +34 4 +31 1 +0 +2C , +F9 � +12  +0 +1  +0 +0 +58 X +50 P +4C L +4F O +52 R +45 E +20 +53 S +4D M +55 U +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +4  +0 +0 +FF � +FF � +FF � +FD � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 1 +Hardware version: 4.0.0 +Firmware version: 255.255.253 +Device ID : 0 +goodID : 1 +Remaining time: 0.882127046585 sec + +void smu::Comm::transmit_changeBaud(uint32_t):1393:Comm : QP4_Packet allocated +void smu::Comm::transmit_changeBaud(uint32_t):1400:Comm : Packet Sealed and Transmitted +51 Q +50 P +34 4 +31 1 +0 +8 +FF � +30 0 +0 +2B + +0 +0 +0 +0 +25 % +80 � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 43 +void smu::Comm::changeBaudCB(const void*, uint16_t):746:Comm : Packet Size Okay +void smu::Comm::changeBaudCB(const void*, uint16_t):752:Comm : Callback Completed +Baud Rate: 9600 +Timeout: 0.0 +Communication timeout in changeBaud +``` From 29a6d3415e9c63387d11a3e9d2048b5dbefb0976 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 13 Sep 2017 22:07:14 +0530 Subject: [PATCH 19/50] added PRINT_DEBUG to virtuaSMU.cxx --- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 33 +++++++++++++-------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 98eb43c..cf79e66 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -1,9 +1,13 @@ #include "../app/virtuaSMU.h" #include "../../sys/sys/Timer.h" +#include #include #include +#define PRINT_DEBUG(x) { \ +std::cerr << __PRETTY_FUNCTION__ << ":" << __LINE__ << ":" << x << std::endl; } + namespace smu { SourceMode toSourceMode (unsigned int i) @@ -306,15 +310,12 @@ void Driver::VS_saveCalibrationCB (const CommCB* oCB) void Driver::VS_setVoltageCB (const CommCB* oCB) { - //std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; const CommCB_VS_SetVoltage* o = reinterpret_cast (oCB); vs_->setVoltage (o->voltage()); - //std::cout << "virtuaSMU : Retrieved Set Voltage" << std::endl; - ackBits_.set (COMM_CBCODE_VS_SET_VOLTAGE); - //std::cout << "virtuaSMU : AckBits Set" << std::endl; + } /***************************************************************************/ @@ -575,16 +576,16 @@ void Driver::VM_getTerminalCB (const CommCB* oCB) void Driver::changeBaudCB (const CommCB* oCB) { - //std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; - + PRINT_DEBUG ("virtuaSMU : Entering changeBaudCB"); + const CommCB_changeBaud* o = reinterpret_cast (oCB); baudRate_ = o->baudRate(); - //std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; - + PRINT_DEBUG ("virtuaSMU : Retrieved baudRate"); + ackBits_.set (COMM_CBCODE_CHANGE_BAUD); - //std::cout << "virtuaSMU : AckBits Set" << std::endl; + PRINT_DEBUG ("virtuaSMU : AckBits Set"); } /***************************************************************************/ @@ -870,13 +871,9 @@ void Driver::VS_saveCalibration (float* timeout) void Driver::VS_setVoltage (float* voltage, float* timeout) { ackBits_.reset (COMM_CBCODE_VS_SET_VOLTAGE); - //std::cout << "virtuaSMU : AckBits Reset" << std::endl; - comm_->transmit_VS_setVoltage (*voltage); - //std::cout << "virtuaSMU : Transmitted setVoltage, Starting wait for response" << std::endl; if (waitForResponse (COMM_CBCODE_VS_SET_VOLTAGE, timeout)) - // std::cout << "virtuaSMU : Recieved Response" << std::endl; *voltage = vs_->voltage(); } @@ -1244,14 +1241,16 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) void Driver::changeBaud (uint32_t* baudRate, float* timeout) { ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); - //std::cout << "virtuaSMU : AckBits Reset" << std::endl; - + PRINT_DEBUG ("virtuaSMU : AckBits Reset"); + comm_->transmit_changeBaud (*baudRate); - //std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; + PRINT_DEBUG("virtuaSMU : Transmitted baudRate, Starting wait for response"); if (waitForResponse (COMM_CBCODE_CHANGE_BAUD, timeout)) - // std::cout << "virtuaSMU : Recieved Response" << std::endl; + { + PRINT_DEBUG ("virtuaSMU : Recieved Response"); *baudRate = baudRate_; + } } /***************************************************************************/ From 42111cbea60f167aa4e05694e27c31bffad82653 Mon Sep 17 00:00:00 2001 From: Shyam Date: Thu, 14 Sep 2017 11:51:43 +0530 Subject: [PATCH 20/50] Added print statements to libxsmu.cxx --- XSMU-2.4.0/wrapper/python/libxsmu.cxx | 7 +- changeBaudTesting.md | 99 +++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index d764d93..19a49ac 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -847,15 +847,20 @@ void changeBaud (int deviceID, unsigned int baudRate, float timeout, unsigned int baudRate_ = baudRate; float timeout_ = timeout; + + std::cerr << "libxsmu changeBaud " << baudRate_ << " " << timeout_ << std::endl; virtuaSMU->changeBaud (&baudRate_, &timeout_); *ret_baudRate = 9600; if ((*ret_timeout = timeout_) == 0) + { std::cerr << "libxsmu timeout " << baudRate_ << " " << timeout_ << std::endl; return; - + } + *ret_baudRate = baudRate_; + std::cerr << "libxsmu success" << baudRate_ << " " << timeout_ << std::endl; } /********************************************************************/ /********************************************************************/ diff --git a/changeBaudTesting.md b/changeBaudTesting.md index c963aad..cbe156c 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -417,3 +417,102 @@ Baud Rate: 9600 Timeout: 0.0 Communication timeout in changeBaud ``` +--- + +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +51 Q +50 P +34 4 +31 1 +0 +2C , +F9 � +12  +0 +1  +0 +0 +58 X +50 P +4C L +4F O +52 R +45 E +20 +53 S +4D M +55 U +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +4  +0 +0 +FF � +FF � +FF � +FD � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 1 +Hardware version: 4.0.0 +Firmware version: 255.255.253 +Device ID : 0 +goodID : 1 +Remaining time: 0.884266853333 sec + +libxsmu changeBaud 9600 5 + +void smu::Driver::changeBaud(uint32_t*, float*):1244:virtuaSMU : AckBits Reset +void smu::Comm::transmit_changeBaud(uint32_t):1393:Comm : QP4_Packet allocated +void smu::Comm::transmit_changeBaud(uint32_t):1400:Comm : Packet Sealed and Transmitted +void smu::Driver::changeBaud(uint32_t*, float*):1247:virtuaSMU : Transmitted baudRate, Starting wait for response +51 Q +50 P +34 4 +31 1 +0 +8 +FF � +30 0 +0 +2B + +0 +0 +0 +0 +25 % +80 � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 43 +void smu::Comm::changeBaudCB(const void*, uint16_t):746:Comm : Packet Size Okay +void smu::Comm::changeBaudCB(const void*, uint16_t):752:Comm : Callback Completed + +*Waits here* + +libxsmu timeout 9600 0 +Baud Rate: 9600 +Timeout: 0.0 +Communication timeout in changeBaud +``` \ No newline at end of file From f6263cd3319f5645bce85be667e9e6e66db161a6 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Thu, 14 Sep 2017 12:07:35 +0530 Subject: [PATCH 21/50] Found bug - missing line in virtuaSMU.cxx --- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index cf79e66..b1dbc99 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -134,6 +134,8 @@ void Driver::comm_cb (const CommCB* oCB) &Driver::VM_setTerminalCB, &Driver::VM_getTerminalCB, + + &Driver::changeBaudCB, }; if (oCB->code() < sizeof (cbs) / sizeof (cbs[0])) From 4de7312335355fd5dc5237efd6114992c9cfa267 Mon Sep 17 00:00:00 2001 From: Shyam Date: Thu, 14 Sep 2017 12:13:17 +0530 Subject: [PATCH 22/50] updated changeBaudTesting.md --- changeBaudTesting.md | 105 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/changeBaudTesting.md b/changeBaudTesting.md index cbe156c..e07d2dd 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -509,10 +509,115 @@ void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 43 void smu::Comm::changeBaudCB(const void*, uint16_t):746:Comm : Packet Size Okay void smu::Comm::changeBaudCB(const void*, uint16_t):752:Comm : Callback Completed +*Did not print lines in virtuaSMU.cxx changeBaudCB()* +- conclusion : that function is not being executed +- bug found : in virtuaSMU.cxx,, changeBaudCB() not in Callback list + *Waits here* + libxsmu timeout 9600 0 Baud Rate: 9600 Timeout: 0.0 Communication timeout in changeBaud +``` +--- + + +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +51 Q +50 P +34 4 +31 1 +0 +2C , +F9 � +12  +0 +1  +0 +0 +58 X +50 P +4C L +4F O +52 R +45 E +20 +53 S +4D M +55 U +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +4  +0 +0 +FF � +FF � +FF � +FD � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 1 +Hardware version: 4.0.0 +Firmware version: 255.255.253 +Device ID : 0 +goodID : 1 +Remaining time: 0.884332180023 sec + +libxsmu changeBaud 9600 5 +void smu::Driver::changeBaud(uint32_t*, float*):1246:virtuaSMU : AckBits Reset +void smu::Comm::transmit_changeBaud(uint32_t):1393:Comm : QP4_Packet allocated +void smu::Comm::transmit_changeBaud(uint32_t):1400:Comm : Packet Sealed and Transmitted +void smu::Driver::changeBaud(uint32_t*, float*):1249:virtuaSMU : Transmitted baudRate, Starting wait for response +51 Q +50 P +34 4 +31 1 +0 +8 +FF � +30 0 +0 +2B + +0 +0 +0 +0 +25 % +80 � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 43 +void smu::Comm::changeBaudCB(const void*, uint16_t):746:Comm : Packet Size Okay +void smu::Driver::changeBaudCB(const smu::CommCB*):581:virtuaSMU : Entering changeBaudCB +void smu::Driver::changeBaudCB(const smu::CommCB*):587:virtuaSMU : Retrieved baudRate +void smu::Driver::changeBaudCB(const smu::CommCB*):590:virtuaSMU : AckBits Set +void smu::Comm::changeBaudCB(const void*, uint16_t):752:Comm : Callback Completed +void smu::Driver::changeBaud(uint32_t*, float*):1253:virtuaSMU : Recieved Response +libxsmu success9600 4.91463 +Baud Rate: 9600 +Timeout: 4.9146270752 + ``` \ No newline at end of file From 5f721f9b3a79ef63655784555c69563762e565ce Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Thu, 14 Sep 2017 12:27:27 +0530 Subject: [PATCH 23/50] removed PRINT_DEBUG statements --- XSMU-2.4.0/code/app/src/Comm.cxx | 12 ++++++------ XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 5ed8b6f..f765565 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -246,7 +246,7 @@ void Comm::interpret (const void* data, uint16_t size) const CommPacket *packet = reinterpret_cast (data); - PRINT_DEBUG ("Opcode: " << packet->opcode()); + //PRINT_DEBUG ("Opcode: " << packet->opcode()); if (packet->opcode() < sizeof (cbs) / sizeof (cbs[0])) (this->*cbs[packet->opcode()])(data, size); @@ -739,17 +739,17 @@ void Comm::changeBaudCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_changeBaud)) { - PRINT_DEBUG ("Comm : Packet Size Smaller than Expected") + //PRINT_DEBUG ("Comm : Packet Size Smaller than Expected") return; } - PRINT_DEBUG ("Comm : Packet Size Okay"); + //PRINT_DEBUG ("Comm : Packet Size Okay"); const CommResponse_changeBaud* res = reinterpret_cast (data); do_callback (new (&callbackObject_) CommCB_changeBaud (res->baudRate())); - PRINT_DEBUG ("Comm : Callback Completed"); + //PRINT_DEBUG ("Comm : Callback Completed"); } /******************************************************************/ @@ -1390,14 +1390,14 @@ void Comm::transmit_changeBaud (uint32_t baudRate) QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_changeBaud)); - PRINT_DEBUG ("Comm : QP4_Packet allocated"); + //PRINT_DEBUG ("Comm : QP4_Packet allocated"); new (req->body()) CommRequest_changeBaud (baudRate); req->seal(); transmit (req); - PRINT_DEBUG ("Comm : Packet Sealed and Transmitted"); + //PRINT_DEBUG ("Comm : Packet Sealed and Transmitted"); qp4_->transmitter().free_packet (req); } diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index b1dbc99..daacf9b 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -578,16 +578,16 @@ void Driver::VM_getTerminalCB (const CommCB* oCB) void Driver::changeBaudCB (const CommCB* oCB) { - PRINT_DEBUG ("virtuaSMU : Entering changeBaudCB"); + //PRINT_DEBUG ("virtuaSMU : Entering changeBaudCB"); const CommCB_changeBaud* o = reinterpret_cast (oCB); baudRate_ = o->baudRate(); - PRINT_DEBUG ("virtuaSMU : Retrieved baudRate"); + //PRINT_DEBUG ("virtuaSMU : Retrieved baudRate"); ackBits_.set (COMM_CBCODE_CHANGE_BAUD); - PRINT_DEBUG ("virtuaSMU : AckBits Set"); + //PRINT_DEBUG ("virtuaSMU : AckBits Set"); } /***************************************************************************/ @@ -1243,14 +1243,14 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) void Driver::changeBaud (uint32_t* baudRate, float* timeout) { ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); - PRINT_DEBUG ("virtuaSMU : AckBits Reset"); + //PRINT_DEBUG ("virtuaSMU : AckBits Reset"); comm_->transmit_changeBaud (*baudRate); - PRINT_DEBUG("virtuaSMU : Transmitted baudRate, Starting wait for response"); + //PRINT_DEBUG("virtuaSMU : Transmitted baudRate, Starting wait for response"); if (waitForResponse (COMM_CBCODE_CHANGE_BAUD, timeout)) { - PRINT_DEBUG ("virtuaSMU : Recieved Response"); + //PRINT_DEBUG ("virtuaSMU : Recieved Response"); *baudRate = baudRate_; } } From ce7bd92e7690f7f1f019e3d0c3c7231b70524c67 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Thu, 14 Sep 2017 13:22:42 +0530 Subject: [PATCH 24/50] removed print statements from libxsmu.cxx --- XSMU-2.4.0/wrapper/python/libxsmu.cxx | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index 19a49ac..69f5512 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -812,7 +812,7 @@ void VM_setTerminal(int deviceID, int terminal, float timeout, virtuaSMU->VM_setTerminal(&terminal_, &timeout_); *ret_terminal = 0; - + if ((*ret_timeout = timeout_) == 0) return; @@ -831,7 +831,7 @@ void VM_getTerminal(int deviceID, float timeout, virtuaSMU->VM_getTerminal(&terminal_, &timeout_); *ret_terminal = 0; - + if ((*ret_timeout = timeout_) == 0) return; @@ -844,23 +844,18 @@ void changeBaud (int deviceID, unsigned int baudRate, float timeout, unsigned int *ret_baudRate, float *ret_timeout) { VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; - + unsigned int baudRate_ = baudRate; float timeout_ = timeout; - - std::cerr << "libxsmu changeBaud " << baudRate_ << " " << timeout_ << std::endl; - + virtuaSMU->changeBaud (&baudRate_, &timeout_); - + *ret_baudRate = 9600; - + if ((*ret_timeout = timeout_) == 0) - { std::cerr << "libxsmu timeout " << baudRate_ << " " << timeout_ << std::endl; - return; - } - + return; + *ret_baudRate = baudRate_; - std::cerr << "libxsmu success" << baudRate_ << " " << timeout_ << std::endl; } /********************************************************************/ /********************************************************************/ From c3bcf0b7e8ad24e5b32bcbb6b034f98d2615b904 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Sat, 16 Sep 2017 11:46:42 +0530 Subject: [PATCH 25/50] Added function to change FTDI baudrate, implemented keepAlive functionality, and added test for keepAlive --- XSMU-2.4.0/code/app/app/Comm.h | 265 ++++++++++--------- XSMU-2.4.0/code/app/app/virtuaSMU.h | 13 +- XSMU-2.4.0/code/app/src/Comm.cxx | 145 +++++----- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 231 ++++++++-------- XSMU-2.4.0/code/sys/src/FTDI.cxx | 71 ++++- XSMU-2.4.0/code/sys/sys/FTDI.h | 21 +- XSMU-2.4.0/wrapper/python/libxsmu.cxx | 124 +++++---- XSMU-2.4.0/wrapper/python/libxsmu.h | 29 +- XSMU-2.4.0/wrapper/python/libxsmu.i | 6 +- XSMU-2.4.0/wrapper/python/test/changeBaud.py | 3 +- XSMU-2.4.0/wrapper/python/test/keepAlive.py | 49 ++++ 11 files changed, 588 insertions(+), 369 deletions(-) create mode 100644 XSMU-2.4.0/wrapper/python/test/keepAlive.py diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index f7b3b4b..d34f018 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -13,13 +13,13 @@ namespace smu{ -/******************************************************************/ +/************************************************************************/ enum Comm_Opcode { COMM_OPCODE_NOP, //00 COMM_OPCODE_IDN, //01 - COMM_OPCODE_SYNC, //02 + COMM_OPCODE_KEEP_ALIVE, //02 COMM_OPCODE_SET_SOURCE_MODE, //03 COMM_OPCODE_CS_SET_RANGE, //04 COMM_OPCODE_CS_GET_CALIBRATION, //05 @@ -134,7 +134,7 @@ enum Comm_VM_Terminal Comm_VM_Terminal toComm_VM_Terminal (uint16_t i); -/******************************************************************/ +/************************************************************************/ class CommPacket { @@ -152,7 +152,7 @@ class CommPacket uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_Identity : public CommPacket { @@ -199,29 +199,40 @@ class CommResponse_Identity : public CommPacket_Identity CommResponse_Identity (void); }; -/******************************************************************/ +/************************************************************************/ -class CommPacket_Synchronize : public CommPacket +class CommPacket_keepAlive : public CommPacket { protected: - CommPacket_Synchronize (void) : - CommPacket (COMM_OPCODE_SYNC) + CommPacket_keepAlive (void) : + CommPacket (COMM_OPCODE_KEEP_ALIVE) {} }; -class CommRequest_Synchronize : public CommPacket_Synchronize +class CommRequest_keepAlive : public CommPacket_keepAlive { public: - CommRequest_Synchronize (void) {} + CommRequest_keepAlive (uint32_t lease_time_ms) : + lease_time_ms_ (smu::hton (lease_time_ms)) + {} + +private: + uint32_t lease_time_ms_; }; -class CommResponse_Synchronize : public CommPacket_Synchronize +class CommResponse_keepAlive : public CommPacket_keepAlive { private: - CommResponse_Synchronize (void); + CommResponse_keepAlive (void); + +public: + uint32_t lease_time_ms (void) const {return smu::ntoh(lease_time_ms_);} + +private: + uint32_t lease_time_ms_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_SetSourceMode : public CommPacket { @@ -259,8 +270,8 @@ class CommResponse_SetSourceMode : public CommPacket_SetSourceMode CommResponse_SetSourceMode (void); }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_CS_SetRange : public CommPacket { @@ -298,7 +309,7 @@ class CommResponse_CS_SetRange : public CommPacket_CS_SetRange uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_GetCalibration : public CommPacket { @@ -336,7 +347,7 @@ class CommResponse_CS_GetCalibration : public CommPacket_CS_GetCalibration float current_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_VerifyCalibration : public CommPacket { @@ -376,7 +387,7 @@ class CommResponse_CS_VerifyCalibration : float current_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_SetCalibration : public CommPacket { @@ -417,7 +428,7 @@ class CommResponse_CS_SetCalibration : public CommPacket_CS_SetCalibration float current_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_SaveCalibration : public CommPacket { @@ -439,7 +450,7 @@ class CommResponse_CS_SaveCalibration : public CommPacket_CS_SaveCalibration CommResponse_CS_SaveCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_SetCurrent : public CommPacket { @@ -472,8 +483,8 @@ class CommResponse_CS_SetCurrent : public CommPacket_CS_SetCurrent float current_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_VS_SetRange : public CommPacket { @@ -511,7 +522,7 @@ class CommResponse_VS_SetRange : public CommPacket_VS_SetRange uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_GetCalibration : public CommPacket { @@ -549,7 +560,7 @@ class CommResponse_VS_GetCalibration : public CommPacket_VS_GetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_VerifyCalibration : public CommPacket { @@ -589,7 +600,7 @@ class CommResponse_VS_VerifyCalibration : float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_SetCalibration : public CommPacket { @@ -630,7 +641,7 @@ class CommResponse_VS_SetCalibration : public CommPacket_VS_SetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_SaveCalibration : public CommPacket { @@ -652,7 +663,7 @@ class CommResponse_VS_SaveCalibration : public CommPacket_VS_SaveCalibration CommResponse_VS_SaveCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_SetVoltage : public CommPacket { @@ -685,8 +696,8 @@ class CommResponse_VS_SetVoltage : public CommPacket_VS_SetVoltage float voltage_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_CM_SetRange : public CommPacket { @@ -724,7 +735,7 @@ class CommResponse_CM_SetRange : public CommPacket_CM_SetRange uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CM_GetCalibration : public CommPacket { @@ -764,7 +775,7 @@ class CommResponse_CM_GetCalibration : public CommPacket_CM_GetCalibration float current_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CM_SetCalibration : public CommPacket { @@ -806,7 +817,7 @@ class CommResponse_CM_SetCalibration : public CommPacket_CM_SetCalibration float current_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CM_SaveCalibration : public CommPacket { @@ -828,7 +839,7 @@ class CommResponse_CM_SaveCalibration : public CommPacket_CM_SaveCalibration CommResponse_CM_SaveCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CM_Read : public CommPacket { @@ -863,8 +874,8 @@ class CommResponse_CM_Read : public CommPacket_CM_Read float current_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_VM_SetRange : public CommPacket { @@ -902,7 +913,7 @@ class CommResponse_VM_SetRange : public CommPacket_VM_SetRange uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_GetCalibration : public CommPacket { @@ -942,7 +953,7 @@ class CommResponse_VM_GetCalibration : public CommPacket_VM_GetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_SetCalibration : public CommPacket { @@ -984,7 +995,7 @@ class CommResponse_VM_SetCalibration : public CommPacket_VM_SetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_SaveCalibration : public CommPacket { @@ -1006,7 +1017,7 @@ class CommResponse_VM_SaveCalibration : public CommPacket_VM_SaveCalibration CommResponse_VM_SaveCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_Read : public CommPacket { @@ -1041,7 +1052,7 @@ class CommResponse_VM_Read : public CommPacket_VM_Read float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_LoadDefaultCalibration : public CommPacket { @@ -1063,7 +1074,7 @@ class CommResponse_CS_LoadDefaultCalibration : public CommPacket_CS_LoadDefaultC CommResponse_CS_LoadDefaultCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_LoadDefaultCalibration : public CommPacket { @@ -1085,7 +1096,7 @@ class CommResponse_VS_LoadDefaultCalibration : public CommPacket_VS_LoadDefaultC CommResponse_VS_LoadDefaultCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CM_LoadDefaultCalibration : public CommPacket { @@ -1107,7 +1118,7 @@ class CommResponse_CM_LoadDefaultCalibration : public CommPacket_CM_LoadDefaultC CommResponse_CM_LoadDefaultCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_LoadDefaultCalibration : public CommPacket { @@ -1129,8 +1140,8 @@ class CommResponse_VM_LoadDefaultCalibration : public CommPacket_VM_LoadDefaultC CommResponse_VM_LoadDefaultCalibration (void); }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_RM_ReadAutoscale : public CommPacket { @@ -1165,8 +1176,8 @@ class CommResponse_RM_ReadAutoscale : public CommPacket_RM_ReadAutoscale float resistance_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ enum SystemConfigParamID { @@ -1210,7 +1221,7 @@ class CommResponse_SystemConfig_Get : public CommPacket_SystemConfig_Get CommResponse_SystemConfig_Get (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_SystemConfig_Set : public CommPacket { @@ -1247,7 +1258,7 @@ class CommResponse_SystemConfig_Set : public CommPacket_SystemConfig_Set CommResponse_SystemConfig_Set (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_SystemConfig_Save : public CommPacket { @@ -1269,7 +1280,7 @@ class CommResponse_SystemConfig_Save : public CommPacket_SystemConfig_Save CommResponse_SystemConfig_Save (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_SystemConfig_LoadDefault : public CommPacket { @@ -1293,8 +1304,8 @@ class CommResponse_SystemConfig_LoadDefault : CommResponse_SystemConfig_LoadDefault (void); }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_VM2_SetRange : public CommPacket { @@ -1332,7 +1343,7 @@ class CommResponse_VM2_SetRange : public CommPacket_VM2_SetRange uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM2_GetCalibration : public CommPacket { @@ -1372,7 +1383,7 @@ class CommResponse_VM2_GetCalibration : public CommPacket_VM2_GetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM2_SetCalibration : public CommPacket { @@ -1414,7 +1425,7 @@ class CommResponse_VM2_SetCalibration : public CommPacket_VM2_SetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM2_SaveCalibration : public CommPacket { @@ -1436,7 +1447,7 @@ class CommResponse_VM2_SaveCalibration : public CommPacket_VM2_SaveCalibration CommResponse_VM2_SaveCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM2_Read : public CommPacket { @@ -1471,7 +1482,7 @@ class CommResponse_VM2_Read : public CommPacket_VM2_Read float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM2_LoadDefaultCalibration : public CommPacket { @@ -1493,7 +1504,7 @@ class CommResponse_VM2_LoadDefaultCalibration : public CommPacket_VM2_LoadDefaul CommResponse_VM2_LoadDefaultCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_SetTerminal : public CommPacket { @@ -1531,7 +1542,7 @@ class CommResponse_VM_SetTerminal : public CommPacket_VM_SetTerminal uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_GetTerminal : public CommPacket { @@ -1563,7 +1574,7 @@ class CommResponse_VM_GetTerminal : public CommPacket_VM_GetTerminal uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_changeBaud : public CommPacket { @@ -1595,14 +1606,14 @@ class CommResponse_changeBaud : public CommPacket_changeBaud private: uint32_t baudRate_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ enum Comm_CallbackCode { COMM_CBCODE_NOP, //00 COMM_CBCODE_IDN, //01 - COMM_CBCODE_SYNC, //02 + COMM_CBCODE_KEEP_ALIVE, //02 COMM_CBCODE_SET_SOURCE_MODE, //03 @@ -1657,7 +1668,8 @@ enum Comm_CallbackCode COMM_CBCODE_CHANGE_BAUD, //43 }; -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB { @@ -1673,7 +1685,7 @@ class CommCB Comm_CallbackCode code_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_Identity : public CommCB { @@ -1698,14 +1710,25 @@ class CommCB_Identity : public CommCB uint32_t firmware_version_; }; -class CommCB_Sync : public CommCB +/************************************************************************/ + +class CommCB_keepAlive : public CommCB { public: - CommCB_Sync (void) : - CommCB (COMM_CBCODE_SYNC) + CommCB_keepAlive (uint32_t lease_time_ms) : + CommCB (COMM_CBCODE_KEEP_ALIVE), + lease_time_ms_ (lease_time_ms) {} + +public: + uint32_t lease_time_ms (void) const {return lease_time_ms_;} + +private: + uint32_t lease_time_ms_; }; +/************************************************************************/ + class CommCB_SetSourceMode : public CommCB { public: @@ -1721,8 +1744,8 @@ class CommCB_SetSourceMode : public CommCB Comm_SourceMode mode_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_CS_SetRange : public CommCB { @@ -1739,7 +1762,7 @@ class CommCB_CS_SetRange : public CommCB Comm_CS_Range range_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CS_GetCalibration : public CommCB { @@ -1762,7 +1785,7 @@ class CommCB_CS_GetCalibration : public CommCB float current_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CS_VerifyCalibration : public CommCB { @@ -1785,7 +1808,7 @@ class CommCB_CS_VerifyCalibration : public CommCB float current_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CS_SetCalibration : public CommCB { @@ -1808,7 +1831,7 @@ class CommCB_CS_SetCalibration : public CommCB float current_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CS_SaveCalibration : public CommCB { @@ -1833,8 +1856,8 @@ class CommCB_CS_SetCurrent : public CommCB float current_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_VS_SetRange : public CommCB { @@ -1851,7 +1874,7 @@ class CommCB_VS_SetRange : public CommCB Comm_VS_Range range_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VS_GetCalibration : public CommCB { @@ -1874,7 +1897,7 @@ class CommCB_VS_GetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VS_VerifyCalibration : public CommCB { @@ -1897,7 +1920,7 @@ class CommCB_VS_VerifyCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VS_SetCalibration : public CommCB { @@ -1920,7 +1943,7 @@ class CommCB_VS_SetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VS_SaveCalibration : public CommCB { @@ -1945,8 +1968,8 @@ class CommCB_VS_SetVoltage : public CommCB float voltage_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_CM_SetRange : public CommCB { @@ -1963,7 +1986,7 @@ class CommCB_CM_SetRange : public CommCB Comm_CM_Range range_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CM_GetCalibration : public CommCB { @@ -1986,7 +2009,7 @@ class CommCB_CM_GetCalibration : public CommCB float current_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CM_SetCalibration : public CommCB { @@ -2009,7 +2032,7 @@ class CommCB_CM_SetCalibration : public CommCB float current_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CM_SaveCalibration : public CommCB { @@ -2019,7 +2042,7 @@ class CommCB_CM_SaveCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_CM_Read : public CommCB { @@ -2036,8 +2059,8 @@ class CommCB_CM_Read : public CommCB float current_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_VM_SetRange : public CommCB { @@ -2054,7 +2077,7 @@ class CommCB_VM_SetRange : public CommCB Comm_VM_Range range_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_GetCalibration : public CommCB { @@ -2077,7 +2100,7 @@ class CommCB_VM_GetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_SetCalibration : public CommCB { @@ -2100,7 +2123,7 @@ class CommCB_VM_SetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_SaveCalibration : public CommCB { @@ -2110,7 +2133,7 @@ class CommCB_VM_SaveCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_Read : public CommCB { @@ -2127,8 +2150,8 @@ class CommCB_VM_Read : public CommCB float voltage_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_CS_LoadDefaultCalibration : public CommCB { @@ -2138,7 +2161,7 @@ class CommCB_CS_LoadDefaultCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_VS_LoadDefaultCalibration : public CommCB { @@ -2148,7 +2171,7 @@ class CommCB_VS_LoadDefaultCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_CM_LoadDefaultCalibration : public CommCB { @@ -2158,7 +2181,7 @@ class CommCB_CM_LoadDefaultCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_LoadDefaultCalibration : public CommCB { @@ -2168,8 +2191,8 @@ class CommCB_VM_LoadDefaultCalibration : public CommCB {} }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_RM_ReadAutoscale : public CommCB { @@ -2186,8 +2209,8 @@ class CommCB_RM_ReadAutoscale : public CommCB float resistance_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_SystemConfig_Get : public CommCB { @@ -2241,8 +2264,8 @@ class CommCB_SystemConfig_LoadDefault : public CommCB {} }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_VM2_SetRange : public CommCB { @@ -2259,7 +2282,7 @@ class CommCB_VM2_SetRange : public CommCB Comm_VM2_Range range_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM2_GetCalibration : public CommCB { @@ -2282,7 +2305,7 @@ class CommCB_VM2_GetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM2_SetCalibration : public CommCB { @@ -2305,7 +2328,7 @@ class CommCB_VM2_SetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM2_SaveCalibration : public CommCB { @@ -2315,7 +2338,7 @@ class CommCB_VM2_SaveCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM2_Read : public CommCB { @@ -2332,7 +2355,7 @@ class CommCB_VM2_Read : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM2_LoadDefaultCalibration : public CommCB { @@ -2342,7 +2365,7 @@ class CommCB_VM2_LoadDefaultCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_SetTerminal : public CommCB { @@ -2359,7 +2382,7 @@ class CommCB_VM_SetTerminal : public CommCB Comm_VM_Terminal terminal_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_GetTerminal : public CommCB { @@ -2376,7 +2399,7 @@ class CommCB_VM_GetTerminal : public CommCB Comm_VM_Terminal terminal_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_changeBaud : public CommCB { @@ -2392,14 +2415,14 @@ class CommCB_changeBaud : public CommCB private: uint32_t baudRate_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ union CommCB_Union { char gen0[sizeof (CommCB)]; char gen1[sizeof (CommCB_Identity)]; - char gen2[sizeof (CommCB_Sync)]; + char gen2[sizeof (CommCB_keepAlive)]; char gen3[sizeof (CommCB_SetSourceMode)]; char gen4[sizeof (CommCB_changeBaud)]; @@ -2451,8 +2474,8 @@ union CommCB_Union char vm7[sizeof (CommCB_VM_GetTerminal)]; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class Comm : public Applet { @@ -2470,7 +2493,7 @@ class Comm : public Applet public: void check (void); void transmitIdentify (void); - void transmitSync (void); + void transmit_keepAlive (uint32_t lease_time_ms); void transmitSourceMode (Comm_SourceMode mode); /********************************/ @@ -2556,7 +2579,7 @@ class Comm : public Applet void nopCB (const void* data, uint16_t size); void identityCB (const void* data, uint16_t size); - void syncCB (const void* data, uint16_t size); + void keepAliveCB (const void* data, uint16_t size); void setSourceModeCB (const void* data, uint16_t size); @@ -2612,9 +2635,13 @@ class Comm : public Applet private: void transmit (const QP4_Packet* packet); + +public: + bool isBaudValid (uint32_t baudRate); + void setBaudRate (uint32_t baudRate); }; -/******************************************************************/ +/************************************************************************/ } // namespace smu #endif diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index 464595e..b47b454 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -58,7 +58,7 @@ class Driver { /***************************************************/ void identify (float* timeout); - void sync (float* timeout); + void keepAlive (uint32_t* lease_time_ms, float* timeout); void setSourceMode (SourceMode* mode, float* timeout); @@ -165,9 +165,9 @@ class Driver { void VM_getTerminal (VM_Terminal* terminal, float* timeout); /***************************************************/ - + void changeBaud (uint32_t* baudRate, float* timeout); - + /***************************************************/ public: bool goodID (void) const; @@ -184,7 +184,7 @@ class Driver { void nopCB (const CommCB* oCB); void identityCB (const CommCB* oCB); - void syncCB (const CommCB* oCB); + void keepAliveCB (const CommCB* oCB); void setSourceModeCB (const CommCB* oCB); @@ -235,7 +235,7 @@ class Driver { void VM_setTerminalCB (const CommCB* oCB); void VM_getTerminalCB (const CommCB* oCB); - + void changeBaudCB (const CommCB* oCB); private: @@ -250,7 +250,10 @@ class Driver { VersionInfo* versionInfo_; AckBits ackBits_; std::string identity_; + +private: uint32_t baudRate_; + }; /************************************************************************/ diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index f765565..c4594b1 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -105,8 +105,8 @@ Comm_VM_Terminal toComm_VM_Terminal (uint16_t i) values[i] : values[0]; } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ Comm::Comm (void) { @@ -136,16 +136,27 @@ void Comm::check (void) checkReceiveQueue(); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ void Comm::transmit (const QP4_Packet* packet) { ftdi_->write (packet, packet->size()); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ + +bool Comm::isBaudValid (uint32_t baudRate) +{ + return ftdi_->isBaudValid (baudRate); +} + +void Comm::setBaudRate (uint32_t baudRate) +{ + ftdi_->setBaudRate (baudRate); +} + +/************************************************************************/ +/************************************************************************/ void Comm::checkReceiveQueue (void) { @@ -153,7 +164,6 @@ void Comm::checkReceiveQueue (void) uint32_t rxsize; while ((rxsize = ftdi_->read (rxbuf, sizeof (rxbuf)))) - //std::cout << "Comm : Recieved Data Size : " << rxsize << std::endl; processReceivedData (rxbuf, rxsize); } @@ -186,7 +196,7 @@ void Comm::interpret (const void* data, uint16_t size) { &Comm::nopCB, &Comm::identityCB, - &Comm::syncCB, + &Comm::keepAliveCB, &Comm::setSourceModeCB, &Comm::CS_setRangeCB, @@ -252,11 +262,14 @@ void Comm::interpret (const void* data, uint16_t size) (this->*cbs[packet->opcode()])(data, size); } -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::nopCB (const void* data, uint16_t size) {} +/************************************************************************/ + void Comm::identityCB (const void* data, uint16_t size) { const CommResponse_Identity* res = @@ -268,11 +281,21 @@ void Comm::identityCB (const void* data, uint16_t size) res->containsVersionInfo (size) ? res->firmware_version() : 0)); } -void Comm::syncCB (const void* data, uint16_t size) +/************************************************************************/ + +void Comm::keepAliveCB (const void* data, uint16_t size) { - do_callback (new (&callbackObject_) CommCB_Sync); + if (size < sizeof (CommResponse_keepAlive)) + return; + + const CommResponse_keepAlive* res = + reinterpret_cast (data); + + do_callback (new (&callbackObject_) CommCB_keepAlive (res->lease_time_ms())); } +/************************************************************************/ + void Comm::setSourceModeCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_SetSourceMode)) @@ -284,7 +307,8 @@ void Comm::setSourceModeCB (const void* data, uint16_t size) do_callback (new (&callbackObject_) CommCB_SetSourceMode (res->mode())); } -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::CS_setRangeCB (const void* data, uint16_t size) { @@ -356,7 +380,7 @@ void Comm::CS_setCurrentCB (const void* data, uint16_t size) CommCB_CS_SetCurrent (res->current())); } -/******************************************************************/ +/************************************************************************/ void Comm::VS_setRangeCB (const void* data, uint16_t size) { @@ -428,7 +452,7 @@ void Comm::VS_setVoltageCB (const void* data, uint16_t size) CommCB_VS_SetVoltage (res->voltage())); } -/******************************************************************/ +/************************************************************************/ void Comm::CM_setRangeCB (const void* data, uint16_t size) { @@ -488,7 +512,7 @@ void Comm::CM_readCB (const void* data, uint16_t size) CommCB_CM_Read (res->current())); } -/******************************************************************/ +/************************************************************************/ void Comm::VM_setRangeCB (const void* data, uint16_t size) { @@ -548,7 +572,7 @@ void Comm::VM_readCB (const void* data, uint16_t size) CommCB_VM_Read (res->voltage())); } -/******************************************************************/ +/************************************************************************/ void Comm::CS_loadDefaultCalibrationCB (const void* data, uint16_t size) { @@ -582,8 +606,8 @@ void Comm::VM_loadDefaultCalibrationCB (const void* data, uint16_t size) do_callback (new (&callbackObject_) CommCB_VM_LoadDefaultCalibration); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::RM_readAutoscaleCB (const void* data, uint16_t size) { @@ -597,8 +621,8 @@ void Comm::RM_readAutoscaleCB (const void* data, uint16_t size) CommCB_RM_ReadAutoscale (res->resistance())); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::SystemConfig_GetCB (const void* data, uint16_t size) { @@ -640,8 +664,8 @@ void Comm::SystemConfig_LoadDefaultCB (const void* data, uint16_t size) do_callback (new (&callbackObject_) CommCB_SystemConfig_LoadDefault); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::VM2_setRangeCB (const void* data, uint16_t size) { @@ -709,7 +733,7 @@ void Comm::VM2_loadDefaultCalibrationCB (const void* data, uint16_t size) do_callback (new (&callbackObject_) CommCB_VM2_LoadDefaultCalibration); } -/******************************************************************/ +/************************************************************************/ void Comm::VM_setTerminalCB (const void* data, uint16_t size) { @@ -732,28 +756,24 @@ void Comm::VM_getTerminalCB (const void* data, uint16_t size) const CommResponse_VM_GetTerminal* res = reinterpret_cast (data); - do_callback (new (&callbackObject_) CommCB_VM_GetTerminal (res->terminal())); + do_callback (new (&callbackObject_) + CommCB_VM_GetTerminal (res->terminal())); } void Comm::changeBaudCB (const void* data, uint16_t size) { - if (size < sizeof (CommResponse_changeBaud)) { - - //PRINT_DEBUG ("Comm : Packet Size Smaller than Expected") + if (size < sizeof (CommResponse_changeBaud)) return; - } - - //PRINT_DEBUG ("Comm : Packet Size Okay"); const CommResponse_changeBaud* res = reinterpret_cast (data); - do_callback (new (&callbackObject_) CommCB_changeBaud (res->baudRate())); - //PRINT_DEBUG ("Comm : Callback Completed"); + do_callback (new (&callbackObject_) + CommCB_changeBaud (res->baudRate())); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::open (const char* serialNo) { @@ -765,8 +785,8 @@ void Comm::close (void) ftdi_->close(); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmitIdentify (void) { @@ -780,17 +800,23 @@ void Comm::transmitIdentify (void) qp4_->transmitter().free_packet (req); } -void Comm::transmitSync (void) +/************************************************************************/ + +void Comm::transmit_keepAlive (uint32_t lease_time_ms) { QP4_Packet* req = - qp4_->transmitter().alloc_packet (sizeof (CommRequest_Synchronize)); + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_keepAlive)); - new (req->body()) CommRequest_Synchronize; + new (req->body()) + CommRequest_keepAlive (lease_time_ms); req->seal(); transmit (req); + qp4_->transmitter().free_packet (req); } +/************************************************************************/ void Comm::transmitSourceMode (Comm_SourceMode mode) { @@ -806,7 +832,8 @@ void Comm::transmitSourceMode (Comm_SourceMode mode) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmit_CS_setRange (Comm_CS_Range range) { @@ -892,7 +919,7 @@ void Comm::transmit_CS_setCurrent (float current) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_VS_setRange (Comm_VS_Range range) { @@ -982,7 +1009,7 @@ void Comm::transmit_VS_setVoltage (float voltage) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_CM_setRange (Comm_CM_Range range) { @@ -1055,8 +1082,8 @@ void Comm::transmit_CM_read (uint16_t filterLength) qp4_->transmitter().free_packet (req); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmit_VM_setRange (Comm_VM_Range range) { @@ -1129,8 +1156,8 @@ void Comm::transmit_VM_read (uint16_t filterLength) qp4_->transmitter().free_packet (req); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmit_CS_loadDefaultCalibration (void) { @@ -1146,7 +1173,7 @@ void Comm::transmit_CS_loadDefaultCalibration (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_VS_loadDefaultCalibration (void) { @@ -1162,7 +1189,7 @@ void Comm::transmit_VS_loadDefaultCalibration (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_CM_loadDefaultCalibration (void) { @@ -1178,7 +1205,7 @@ void Comm::transmit_CM_loadDefaultCalibration (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_VM_loadDefaultCalibration (void) { @@ -1194,8 +1221,8 @@ void Comm::transmit_VM_loadDefaultCalibration (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmit_RM_readAutoscale (uint16_t filterLength) { @@ -1211,8 +1238,8 @@ void Comm::transmit_RM_readAutoscale (uint16_t filterLength) qp4_->transmitter().free_packet (req); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmit_SystemConfig_Get (uint16_t paramID) { @@ -1266,7 +1293,7 @@ void Comm::transmit_SystemConfig_LoadDefault (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_VM2_setRange (Comm_VM2_Range range) { @@ -1353,7 +1380,7 @@ void Comm::transmit_VM2_loadDefaultCalibration (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_VM_setTerminal (Comm_VM_Terminal terminal) { @@ -1383,24 +1410,22 @@ void Comm::transmit_VM_getTerminal (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_changeBaud (uint32_t baudRate) { QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_changeBaud)); - //PRINT_DEBUG ("Comm : QP4_Packet allocated"); new (req->body()) CommRequest_changeBaud (baudRate); req->seal(); transmit (req); - //PRINT_DEBUG ("Comm : Packet Sealed and Transmitted"); qp4_->transmitter().free_packet (req); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ } // namespace smu diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index daacf9b..61ced00 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -84,7 +84,7 @@ void Driver::comm_cb (const CommCB* oCB) static const cb_t cbs[] = { &Driver::nopCB, &Driver::identityCB, - &Driver::syncCB, + &Driver::keepAliveCB, &Driver::setSourceModeCB, &Driver::CS_setRangeCB, @@ -142,15 +142,15 @@ void Driver::comm_cb (const CommCB* oCB) (this->*cbs[oCB->code()]) (oCB); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::nopCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_NOP); } -/***************************************************************************/ +/************************************************************************/ void Driver::identityCB (const CommCB* oCB) { @@ -164,14 +164,14 @@ void Driver::identityCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_IDN); } -/***************************************************************************/ +/************************************************************************/ -void Driver::syncCB (const CommCB* oCB) +void Driver::keepAliveCB (const CommCB* oCB) { - ackBits_.set (COMM_CBCODE_SYNC); + ackBits_.set (COMM_CBCODE_KEEP_ALIVE); } -/***************************************************************************/ +/************************************************************************/ void Driver::setSourceModeCB (const CommCB* oCB) { @@ -193,8 +193,8 @@ void Driver::setSourceModeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_SET_SOURCE_MODE); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CS_setRangeCB (const CommCB* oCB) { @@ -205,7 +205,7 @@ void Driver::CS_setRangeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CS_SET_RANGE); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_getCalibrationCB (const CommCB* oCB) { @@ -216,7 +216,7 @@ void Driver::CS_getCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CS_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_verifyCalibrationCB (const CommCB* oCB) { @@ -227,7 +227,7 @@ void Driver::CS_verifyCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CS_VERIFY_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_setCalibrationCB (const CommCB* oCB) { @@ -238,14 +238,14 @@ void Driver::CS_setCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CS_SET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_saveCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_CS_SAVE_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_setCurrentCB (const CommCB* oCB) { @@ -256,8 +256,8 @@ void Driver::CS_setCurrentCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CS_SET_CURRENT); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VS_setRangeCB (const CommCB* oCB) { @@ -268,7 +268,7 @@ void Driver::VS_setRangeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VS_SET_RANGE); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_getCalibrationCB (const CommCB* oCB) { @@ -279,7 +279,7 @@ void Driver::VS_getCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VS_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_verifyCalibrationCB (const CommCB* oCB) { @@ -290,7 +290,7 @@ void Driver::VS_verifyCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VS_VERIFY_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_setCalibrationCB (const CommCB* oCB) { @@ -301,14 +301,14 @@ void Driver::VS_setCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VS_SET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_saveCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_VS_SAVE_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_setVoltageCB (const CommCB* oCB) { @@ -320,8 +320,8 @@ void Driver::VS_setVoltageCB (const CommCB* oCB) } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CM_setRangeCB (const CommCB* oCB) { @@ -332,7 +332,7 @@ void Driver::CM_setRangeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CM_SET_RANGE); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_getCalibrationCB (const CommCB* oCB) { @@ -343,7 +343,7 @@ void Driver::CM_getCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CM_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_setCalibrationCB (const CommCB* oCB) { @@ -354,14 +354,14 @@ void Driver::CM_setCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CM_SET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_saveCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_CM_SAVE_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_readCB (const CommCB* oCB) { @@ -372,8 +372,8 @@ void Driver::CM_readCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CM_READ); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VM_setRangeCB (const CommCB* oCB) { @@ -384,7 +384,7 @@ void Driver::VM_setRangeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM_SET_RANGE); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_getCalibrationCB (const CommCB* oCB) { @@ -395,7 +395,7 @@ void Driver::VM_getCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_setCalibrationCB (const CommCB* oCB) { @@ -406,14 +406,14 @@ void Driver::VM_setCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM_SET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_saveCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_VM_SAVE_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_readCB (const CommCB* oCB) { @@ -424,37 +424,37 @@ void Driver::VM_readCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM_READ); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CS_loadDefaultCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_loadDefaultCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_loadDefaultCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_loadDefaultCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::RM_readAutoscaleCB (const CommCB* oCB) { @@ -465,8 +465,8 @@ void Driver::RM_readAutoscaleCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_RM_READ_AUTOSCALE); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::SystemConfig_GetCB (const CommCB* oCB) { @@ -496,8 +496,8 @@ void Driver::SystemConfig_LoadDefaultCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_SYSTEM_CONFIG_LOAD_DEFAULT); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VM2_setRangeCB (const CommCB* oCB) { @@ -508,7 +508,7 @@ void Driver::VM2_setRangeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM2_SET_RANGE); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_getCalibrationCB (const CommCB* oCB) { @@ -519,7 +519,7 @@ void Driver::VM2_getCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM2_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_setCalibrationCB (const CommCB* oCB) { @@ -530,14 +530,14 @@ void Driver::VM2_setCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM2_SET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_saveCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_VM2_SAVE_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_readCB (const CommCB* oCB) { @@ -553,7 +553,7 @@ void Driver::VM2_loadDefaultCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_setTerminalCB (const CommCB* oCB) { @@ -574,24 +574,23 @@ void Driver::VM_getTerminalCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM_GET_TERMINAL); } -/***************************************************************************/ +/************************************************************************/ void Driver::changeBaudCB (const CommCB* oCB) { - //PRINT_DEBUG ("virtuaSMU : Entering changeBaudCB"); - const CommCB_changeBaud* o = reinterpret_cast (oCB); baudRate_ = o->baudRate(); - //PRINT_DEBUG ("virtuaSMU : Retrieved baudRate"); - ackBits_.set (COMM_CBCODE_CHANGE_BAUD); - //PRINT_DEBUG ("virtuaSMU : AckBits Set"); + if (comm_->isBaudValid (baudRate_)) + ackBits_.set (COMM_CBCODE_CHANGE_BAUD); + + comm_->setBaudRate (baudRate_); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::open (const char* serialNo, float* timeout) { @@ -680,8 +679,8 @@ bool Driver::waitForResponse (uint16_t checkBit, float* timeout) return ackBits_[checkBit]; } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ bool Driver::goodID (void) const { @@ -698,17 +697,18 @@ void Driver::identify (float* timeout) waitForResponse (COMM_CBCODE_IDN, timeout); } -/***************************************************************************/ +/************************************************************************/ -void Driver::sync (float* timeout) +void Driver::keepAlive (uint32_t* lease_time_ms, float* timeout) { - ackBits_.reset (COMM_CBCODE_SYNC); + ackBits_.reset (COMM_CBCODE_KEEP_ALIVE); - comm_->transmitSync(); - waitForResponse (COMM_CBCODE_SYNC, timeout); + comm_->transmit_keepAlive (*lease_time_ms); + + waitForResponse (COMM_CBCODE_KEEP_ALIVE, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::setSourceMode (SourceMode* mode, float* timeout) { @@ -724,8 +724,8 @@ void Driver::setSourceMode (SourceMode* mode, float* timeout) } } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CS_setRange (CS_Range* range, float* timeout) { @@ -737,7 +737,7 @@ void Driver::CS_setRange (CS_Range* range, float* timeout) *range = (cs_->range()); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_getCalibration (uint16_t* index, int16_t* dac, float* current, float* timeout) @@ -752,7 +752,7 @@ void Driver::CS_getCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_verifyCalibration (uint16_t* index, int16_t* dac, float* current, float* timeout) @@ -767,7 +767,7 @@ void Driver::CS_verifyCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_setCalibration (uint16_t* index, int16_t* dac, float* current, float* timeout) @@ -782,7 +782,7 @@ void Driver::CS_setCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_saveCalibration (float* timeout) { @@ -791,7 +791,7 @@ void Driver::CS_saveCalibration (float* timeout) waitForResponse (COMM_CBCODE_CS_SAVE_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_setCurrent (float* current, float* timeout) { @@ -802,8 +802,8 @@ void Driver::CS_setCurrent (float* current, float* timeout) *current = cs_->current(); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VS_setRange (VS_Range* range, float* timeout) { @@ -814,7 +814,7 @@ void Driver::VS_setRange (VS_Range* range, float* timeout) *range = (vs_->range()); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_getCalibration (uint16_t* index, int16_t* dac, float* voltage, float* timeout) @@ -829,7 +829,7 @@ void Driver::VS_getCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_verifyCalibration (uint16_t* index, int16_t* dac, float* voltage, float* timeout) @@ -844,7 +844,7 @@ void Driver::VS_verifyCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_setCalibration (uint16_t* index, int16_t* dac, float* voltage, float* timeout) @@ -859,7 +859,7 @@ void Driver::VS_setCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_saveCalibration (float* timeout) { @@ -868,7 +868,7 @@ void Driver::VS_saveCalibration (float* timeout) waitForResponse (COMM_CBCODE_VS_SAVE_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_setVoltage (float* voltage, float* timeout) { @@ -879,8 +879,8 @@ void Driver::VS_setVoltage (float* voltage, float* timeout) *voltage = vs_->voltage(); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CM_setRange (CM_Range* range, float* timeout) { @@ -891,7 +891,7 @@ void Driver::CM_setRange (CM_Range* range, float* timeout) *range = (cm_->range()); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_getCalibration (uint16_t* index, int32_t* adc, float* current, float* timeout) @@ -906,7 +906,7 @@ void Driver::CM_getCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_setCalibration (uint16_t* index, int32_t* adc, float* current, float* timeout) @@ -921,7 +921,7 @@ void Driver::CM_setCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_saveCalibration (float* timeout) { @@ -930,7 +930,7 @@ void Driver::CM_saveCalibration (float* timeout) waitForResponse (COMM_CBCODE_CM_SAVE_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_read (uint16_t* filterLength, float* current, float* timeout) @@ -943,8 +943,8 @@ void Driver::CM_read (uint16_t* filterLength, float* current, } } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VM_setRange (VM_Range* range, float* timeout) { @@ -955,7 +955,7 @@ void Driver::VM_setRange (VM_Range* range, float* timeout) *range = (vm_->range()); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_getCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) @@ -970,7 +970,7 @@ void Driver::VM_getCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_setCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) @@ -985,7 +985,7 @@ void Driver::VM_setCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_saveCalibration (float* timeout) { @@ -994,7 +994,7 @@ void Driver::VM_saveCalibration (float* timeout) waitForResponse (COMM_CBCODE_VM_SAVE_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_read (uint16_t* filterLength, float* voltage, float* timeout) @@ -1007,8 +1007,8 @@ void Driver::VM_read (uint16_t* filterLength, float* voltage, } } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CS_loadDefaultCalibration (float* timeout) { @@ -1017,7 +1017,7 @@ void Driver::CS_loadDefaultCalibration (float* timeout) waitForResponse (COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_loadDefaultCalibration (float* timeout) { @@ -1026,7 +1026,7 @@ void Driver::VS_loadDefaultCalibration (float* timeout) waitForResponse (COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_loadDefaultCalibration (float* timeout) { @@ -1035,7 +1035,7 @@ void Driver::CM_loadDefaultCalibration (float* timeout) waitForResponse (COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_loadDefaultCalibration (float* timeout) { @@ -1044,8 +1044,8 @@ void Driver::VM_loadDefaultCalibration (float* timeout) waitForResponse (COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION, timeout); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::RM_readAutoscale (uint16_t* filterLength, float* resistance,float* timeout) @@ -1057,8 +1057,8 @@ void Driver::RM_readAutoscale (uint16_t* filterLength, } } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::SystemConfig_Save (float* timeout) { @@ -1145,8 +1145,8 @@ SystemConfig_Set_hardwareVersion (uint32_t* version, float* timeout) sysconf_->hwBugfixNo()); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VM2_setRange (VM2_Range* range, float* timeout) { @@ -1157,7 +1157,7 @@ void Driver::VM2_setRange (VM2_Range* range, float* timeout) *range = (vm2_->range()); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_getCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) @@ -1172,7 +1172,7 @@ void Driver::VM2_getCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_setCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) @@ -1187,7 +1187,7 @@ void Driver::VM2_setCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_saveCalibration (float* timeout) { @@ -1196,7 +1196,7 @@ void Driver::VM2_saveCalibration (float* timeout) waitForResponse (COMM_CBCODE_VM2_SAVE_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_read (uint16_t* filterLength, float* voltage, float* timeout) @@ -1208,7 +1208,7 @@ void Driver::VM2_read (uint16_t* filterLength, float* voltage, *voltage = vm2_->voltage(); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_loadDefaultCalibration (float* timeout) { @@ -1217,7 +1217,7 @@ void Driver::VM2_loadDefaultCalibration (float* timeout) waitForResponse (COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_setTerminal (VM_Terminal* terminal, float* timeout) { @@ -1237,24 +1237,19 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) *terminal = (vm_->terminal()); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::changeBaud (uint32_t* baudRate, float* timeout) { ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); - //PRINT_DEBUG ("virtuaSMU : AckBits Reset"); comm_->transmit_changeBaud (*baudRate); - //PRINT_DEBUG("virtuaSMU : Transmitted baudRate, Starting wait for response"); if (waitForResponse (COMM_CBCODE_CHANGE_BAUD, timeout)) - { - //PRINT_DEBUG ("virtuaSMU : Recieved Response"); *baudRate = baudRate_; - } } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ } diff --git a/XSMU-2.4.0/code/sys/src/FTDI.cxx b/XSMU-2.4.0/code/sys/src/FTDI.cxx index 6dc5c9a..b176dcd 100644 --- a/XSMU-2.4.0/code/sys/src/FTDI.cxx +++ b/XSMU-2.4.0/code/sys/src/FTDI.cxx @@ -11,7 +11,7 @@ #endif namespace smu { - + /************************************************************************/ /************************************************************************/ @@ -239,6 +239,75 @@ bool FTDI::good (void) const return handle_; } +bool FTDI::isBaudValid (uint32_t bd) +{ + switch (bd) + { + case 9600: + return true; + + + case 19200: + return true; + + + case 38400: + return true; + + + case 57600: + return true; + + + case 115200: + return true; + + default: + return false; + } +} + +void FTDI::setBaudRate (uint32_t bd) +{ + switch (bd) + { + case 9600: + return _setBaudrate (9600); + + + case 19200: + return _setBaudrate (19200); + + + case 38400: + return _setBaudrate (38400); + + + case 57600: + return _setBaudrate (57600); + + + case 115200: + return _setBaudrate (115200); + } +} + +void FTDI::_setBaudrate (uint32_t baudrate) +{ + if (ftdi_set_baudrate (handle_, baudrate) != FTDI_OK) { + + close(); + return; + } + + if (ftdi_set_line_property2 (handle_, BITS_8, + STOP_BIT_1, NONE, BREAK_OFF) != FTDI_OK) { + + close(); + return; + } +} + /************************************************************************/ /************************************************************************/ diff --git a/XSMU-2.4.0/code/sys/sys/FTDI.h b/XSMU-2.4.0/code/sys/sys/FTDI.h index d1fcc75..54cf3e3 100644 --- a/XSMU-2.4.0/code/sys/sys/FTDI.h +++ b/XSMU-2.4.0/code/sys/sys/FTDI.h @@ -1,4 +1,4 @@ -#ifndef __SMU_FTDI__ + #ifndef __SMU_FTDI__ #define __SMU_FTDI__ #include @@ -30,25 +30,34 @@ namespace smu { class FTDI { - public: +public: FTDI (void); - public: +public: static std::vector scan (void); - public: +public: void open (const char* serialNo); void open (const char* serialNo, int baudrate); uint32_t read (void* data, uint32_t size); uint32_t write (const void* data, uint32_t size); void close (void); - public: +public: bool good (void) const; - private: +private: ftdi_context* handle_; static std::vector scan (int vid, int pid); + +public: + bool isBaudValid (uint32_t bd); + void setBaudRate (uint32_t bd); + +private: + void _setBaudrate (uint32_t baudrate); + + }; } // end of namespace smu diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index 69f5512..fb4638a 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -50,7 +50,7 @@ int open_device(const char *serialNo, return it - virtuaSMUs.begin(); } -/********************************************************************/ +/************************************************************************/ void close_device(int deviceID) { @@ -58,8 +58,8 @@ void close_device(int deviceID) virtuaSMUs[deviceID] = 0; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void setSourceMode(int deviceID, int mode, float timeout, unsigned int *ret_mode, float *ret_timeout) @@ -81,8 +81,8 @@ void setSourceMode(int deviceID, int mode, float timeout, *ret_mode = (int) mode_; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void CS_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout) @@ -101,7 +101,7 @@ void CS_setRange(int deviceID, int range, float timeout, *ret_range = range_; } -/********************************************************************/ +/************************************************************************/ void CS_getCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, int *ret_dac, @@ -127,7 +127,7 @@ void CS_getCalibration(int deviceID, unsigned int index, float timeout, *ret_current = current_; } -/********************************************************************/ +/************************************************************************/ void CS_verifyCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, int *ret_dac, @@ -153,7 +153,7 @@ void CS_verifyCalibration(int deviceID, unsigned int index, float timeout, *ret_current = current_; } -/********************************************************************/ +/************************************************************************/ void CS_setCalibration(int deviceID, unsigned int index, float current, float timeout, unsigned int *ret_index, int *ret_dac, @@ -179,7 +179,7 @@ void CS_setCalibration(int deviceID, unsigned int index, float current, *ret_current = current_; } -/********************************************************************/ +/************************************************************************/ void CS_saveCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -188,7 +188,7 @@ void CS_saveCalibration(int deviceID, float timeout, float *ret_timeout) *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ void CS_setCurrent(int deviceID, float current, float timeout, float *ret_current, float *ret_timeout) @@ -216,8 +216,8 @@ void CS_loadDefaultCalibration(int deviceID, float timeout, *ret_timeout = timeout; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void VS_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout) @@ -236,7 +236,7 @@ void VS_setRange(int deviceID, int range, float timeout, *ret_range = range_; } -/********************************************************************/ +/************************************************************************/ void VS_getCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, int *ret_dac, @@ -262,7 +262,7 @@ void VS_getCalibration(int deviceID, unsigned int index, float timeout, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VS_verifyCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, int *ret_dac, @@ -288,7 +288,7 @@ void VS_verifyCalibration(int deviceID, unsigned int index, float timeout, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VS_setCalibration(int deviceID, unsigned int index, float voltage, float timeout, unsigned int *ret_index, int *ret_dac, @@ -314,7 +314,7 @@ void VS_setCalibration(int deviceID, unsigned int index, float voltage, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VS_saveCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -323,7 +323,7 @@ void VS_saveCalibration(int deviceID, float timeout, float *ret_timeout) *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ void VS_setVoltage(int deviceID, float voltage, float timeout, float *ret_voltage, float *ret_timeout) @@ -351,8 +351,8 @@ void VS_loadDefaultCalibration(int deviceID, float timeout, *ret_timeout = timeout; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void CM_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout) @@ -371,7 +371,7 @@ void CM_setRange(int deviceID, int range, float timeout, *ret_range = range_; } -/********************************************************************/ +/************************************************************************/ void CM_getCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, int *ret_adc, @@ -397,7 +397,7 @@ void CM_getCalibration(int deviceID, unsigned int index, float timeout, *ret_current = current_; } -/********************************************************************/ +/************************************************************************/ void CM_setCalibration(int deviceID, unsigned int index, float current, float timeout, unsigned int *ret_index, int *ret_adc, @@ -423,7 +423,7 @@ void CM_setCalibration(int deviceID, unsigned int index, float current, *ret_current = current_; } -/********************************************************************/ +/************************************************************************/ void CM_saveCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -432,7 +432,7 @@ void CM_saveCalibration(int deviceID, float timeout, float *ret_timeout) *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ void CM_getReading(int deviceID, unsigned int filterLength, float timeout, float *ret_current, float *ret_timeout) @@ -461,8 +461,8 @@ void CM_loadDefaultCalibration(int deviceID, float timeout, *ret_timeout = timeout; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void VM_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout) @@ -481,7 +481,7 @@ void VM_setRange(int deviceID, int range, float timeout, *ret_range = range_; } -/********************************************************************/ +/************************************************************************/ void VM_getCalibration(int deviceID, unsigned int index, float timeout,unsigned int *ret_index, @@ -507,7 +507,7 @@ void VM_getCalibration(int deviceID, unsigned int index, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VM_setCalibration(int deviceID, unsigned int index, float voltage, float timeout, unsigned int *ret_index, int *ret_adc, @@ -533,7 +533,7 @@ void VM_setCalibration(int deviceID, unsigned int index, float voltage, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VM_saveCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -542,7 +542,7 @@ void VM_saveCalibration(int deviceID, float timeout, float *ret_timeout) *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ void VM_getReading(int deviceID, unsigned int filterLength, float timeout, float *ret_voltage, float *ret_timeout) @@ -563,6 +563,8 @@ void VM_getReading(int deviceID, unsigned int filterLength, float timeout, *ret_voltage = voltage_; } +/************************************************************************/ + void VM_loadDefaultCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -571,8 +573,8 @@ void VM_loadDefaultCalibration(int deviceID, float timeout, *ret_timeout = timeout; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void RM_getReadingAutoscale (int deviceID, unsigned int filterLength, float timeout, float *ret_resistance, @@ -594,8 +596,8 @@ void RM_getReadingAutoscale (int deviceID, unsigned int filterLength, *ret_resistance = resistance_; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void SystemConfig_Save (int deviceID, float timeout, float* ret_timeout) { @@ -604,6 +606,8 @@ void SystemConfig_Save (int deviceID, float timeout, float* ret_timeout) *ret_timeout = timeout; } +/************************************************************************/ + void SystemConfig_LoadDefault (int deviceID, float timeout, float* ret_timeout) { VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; @@ -611,6 +615,8 @@ void SystemConfig_LoadDefault (int deviceID, float timeout, float* ret_timeout) *ret_timeout = timeout; } +/************************************************************************/ + void SystemConfig_Get_hardwareVersion (int deviceID, float timeout, unsigned int* ret_hardwareVersion, float* ret_timeout) { @@ -628,6 +634,8 @@ void SystemConfig_Get_hardwareVersion (int deviceID, *ret_hardwareVersion = hardwareVersion_; } +/************************************************************************/ + void SystemConfig_Set_hardwareVersion (int deviceID, unsigned int hardwareVersion, float timeout, unsigned int* ret_hardwareVersion, float* ret_timeout) @@ -646,8 +654,8 @@ void SystemConfig_Set_hardwareVersion (int deviceID, *ret_hardwareVersion = hardwareVersion_; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void library_version (int deviceID, unsigned int* version) { @@ -689,8 +697,8 @@ unsigned int bugfix_version_no (unsigned int version) return smu::BUGFIX_VERSION_NO (version); } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void VM2_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout) @@ -709,7 +717,7 @@ void VM2_setRange(int deviceID, int range, float timeout, *ret_range = range_; } -/********************************************************************/ +/************************************************************************/ void VM2_getCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, @@ -735,7 +743,7 @@ void VM2_getCalibration(int deviceID, unsigned int index, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VM2_setCalibration(int deviceID, unsigned int index, float voltage, float timeout, unsigned int *ret_index, int *ret_adc, @@ -761,7 +769,7 @@ void VM2_setCalibration(int deviceID, unsigned int index, float voltage, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VM2_saveCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -770,7 +778,7 @@ void VM2_saveCalibration(int deviceID, float timeout, float *ret_timeout) *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ void VM2_getReading(int deviceID, unsigned int filterLength, float timeout, float *ret_voltage, float *ret_timeout) @@ -791,6 +799,8 @@ void VM2_getReading(int deviceID, unsigned int filterLength, float timeout, *ret_voltage = voltage_; } +/************************************************************************/ + void VM2_loadDefaultCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -799,7 +809,8 @@ void VM2_loadDefaultCalibration(int deviceID, float timeout, *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void VM_setTerminal(int deviceID, int terminal, float timeout, unsigned int *ret_terminal, float *ret_timeout) @@ -819,6 +830,7 @@ void VM_setTerminal(int deviceID, int terminal, float timeout, *ret_terminal = terminal_; } +/************************************************************************/ void VM_getTerminal(int deviceID, float timeout, unsigned int *ret_terminal, float *ret_timeout) @@ -838,7 +850,8 @@ void VM_getTerminal(int deviceID, float timeout, *ret_terminal = terminal_; } -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void changeBaud (int deviceID, unsigned int baudRate, float timeout, unsigned int *ret_baudRate, float *ret_timeout) @@ -857,5 +870,26 @@ void changeBaud (int deviceID, unsigned int baudRate, float timeout, *ret_baudRate = baudRate_; } -/********************************************************************/ -/********************************************************************/ + +/************************************************************************/ + +void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, + unsigned int *ret_lease_time_ms, float *ret_timeout) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + unsigned int lease_time_ms_ = lease_time_ms; + float timeout_ = timeout; + + virtuaSMU->keepAlive (&lease_time_ms_, &timeout_); + + *ret_lease_time_ms = 0; + + if ((*ret_timeout = timeout_) == 0) + return; + + *ret_lease_time_ms = lease_time_ms_; +} + +/************************************************************************/ +/************************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.h b/XSMU-2.4.0/wrapper/python/libxsmu.h index 9cd3348..fced588 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.h +++ b/XSMU-2.4.0/wrapper/python/libxsmu.h @@ -18,7 +18,7 @@ extern "C" { */ int scan(void); -/**************************************************************/ +/************************************************************************/ /** * \brief Returns the serial number of a previously scanned device. @@ -37,7 +37,7 @@ int scan(void); */ const char *serialNo(int i); -/**************************************************************/ +/************************************************************************/ /** * \brief Opens a previously scanned device for communication, @@ -62,7 +62,7 @@ int open_device(const char *serialNo, float timeout, unsigned int *ret_goodID, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ /** * \brief Closes a previously opened device. @@ -71,14 +71,14 @@ int open_device(const char *serialNo, */ void close_device(int deviceID); -/**************************************************************/ +/************************************************************************/ void setSourceMode(int deviceID, int mode, float timeout, unsigned int *ret_mode, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void CS_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout); @@ -106,7 +106,7 @@ void CS_setCurrent(int deviceID, float current, float timeout, void CS_loadDefaultCalibration (int deviceID, float timeout, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void VS_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout); @@ -134,7 +134,7 @@ void VS_setVoltage(int deviceID, float voltage, float timeout, void VS_loadDefaultCalibration (int deviceID, float timeout, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void CM_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout); @@ -158,7 +158,7 @@ void CM_getReading(int deviceID, unsigned int filterLength, void CM_loadDefaultCalibration (int deviceID, float timeout, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void VM_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout); @@ -182,13 +182,13 @@ void VM_getReading(int deviceID, unsigned int filterLength, void VM_loadDefaultCalibration (int deviceID, float timeout, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void RM_getReadingAutoscale (int deviceID, unsigned int filterLength, float timeout, float *ret_resistance, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void SystemConfig_Save (int deviceID, float timeout, @@ -205,7 +205,7 @@ void SystemConfig_Set_hardwareVersion (int deviceID, unsigned int hardwareVersion, float timeout, unsigned int* ret_hardwareVersion, float* ret_timeout); -/**************************************************************/ +/************************************************************************/ void library_version (int deviceID, unsigned int* version); void hardware_version (int deviceID, unsigned int* version); @@ -218,7 +218,7 @@ unsigned int major_version_no (unsigned int version); unsigned int minor_version_no (unsigned int version); unsigned int bugfix_version_no (unsigned int version); -/**************************************************************/ +/************************************************************************/ void VM2_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout); @@ -248,11 +248,14 @@ void VM_setTerminal(int deviceID, int terminal, float timeout, void VM_getTerminal(int deviceID, float timeout, unsigned int *ret_terminal, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void changeBaud (int deviceID, unsigned int baudRate, float timeout, unsigned int *ret_baudRate, float *ret_timeout); +void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, unsigned int *ret_lease_time_ms, float *ret_timeout); + + #ifdef __cplusplus } // extern "C" diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.i b/XSMU-2.4.0/wrapper/python/libxsmu.i index 852d247..7338b87 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.i +++ b/XSMU-2.4.0/wrapper/python/libxsmu.i @@ -206,7 +206,11 @@ extern void VM_getTerminal(int deviceID, /**************************************************************/ extern void changeBaud (int deviceID, unsigned int baudRate, float timeout, - unsigned int *ret_baudRate, float *ret_timeout); + unsigned int *ret_baudRate, float *ret_timeout); + +extern void keepAlive (int deviceID, unsigned int lease_time_ms, + float timeout, unsigned int *ret_lease_time_ms, + float *ret_timeout); /**************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/test/changeBaud.py b/XSMU-2.4.0/wrapper/python/test/changeBaud.py index 80f76f7..207ae0b 100644 --- a/XSMU-2.4.0/wrapper/python/test/changeBaud.py +++ b/XSMU-2.4.0/wrapper/python/test/changeBaud.py @@ -29,10 +29,11 @@ exit (-2) ########################################################################## -# Set voltage source calibration table (for range selected above.) +# Set Baud Rate of communication timeout = 5.0 baudRate = 9600 + baudRate, timeout = libxsmu.changeBaud (deviceID, baudRate, timeout) print \ "Baud Rate: ", baudRate, "\n" \ diff --git a/XSMU-2.4.0/wrapper/python/test/keepAlive.py b/XSMU-2.4.0/wrapper/python/test/keepAlive.py new file mode 100644 index 0000000..a08af64 --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/keepAlive.py @@ -0,0 +1,49 @@ +import libxsmu, time, math, sys + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +########################################################################## +# Sends Keep_Alive Packet to device + +timeout = 5.0 +lease_time_ms = 10000 + +lease_time_ms, timeout = libxsmu.keepAlive (deviceID, lease_time_ms, timeout) +print \ + "Lease Time: ", lease_time_ms, "\n" \ + "Timeout: ", timeout + +if (timeout == 0.0): + print 'Communication timeout in keepAlive' + exit (-2) + +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) From 6c4fa01f23ada094485d114135635e392f5eabde Mon Sep 17 00:00:00 2001 From: Shyam Date: Sat, 16 Sep 2017 12:23:00 +0530 Subject: [PATCH 26/50] Added keepAlive missing fn to libxsmu.i, updated changeBaudTesting.md --- XSMU-2.4.0/wrapper/python/libxsmu.i | 2 + changeBaudTesting.md | 89 ++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.i b/XSMU-2.4.0/wrapper/python/libxsmu.i index 7338b87..3ac1a1a 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.i +++ b/XSMU-2.4.0/wrapper/python/libxsmu.i @@ -392,6 +392,8 @@ extern void VM_getTerminal(int deviceID, float timeout, extern void changeBaud (int deviceID, unsigned int baudRate, float timeout, unsigned int *OUTPUT, float *OUTPUT); +extern void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, + unsigned int *OUTPUT, float *OUTPUT); /**************************************************************/ /**************************************************************/ \ No newline at end of file diff --git a/changeBaudTesting.md b/changeBaudTesting.md index e07d2dd..b426d4d 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -620,4 +620,91 @@ libxsmu success9600 4.91463 Baud Rate: 9600 Timeout: 4.9146270752 -``` \ No newline at end of file +``` + +### Testng for keepAlive (wrapper/python/test/keepAlive.py) + +- Result : Passed +-Output : + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + 51 Q + 50 P + 34 4 + 31 1 + 0 + 2C , + F9 � + 12  + 0 + 1  + 0 + 0 + 58 X + 50 P + 4C L + 4F O + 52 R + 45 E + 20 + 53 S + 4D M + 55 U + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4  + 0 + 0 + FF � + FF � + FF � + FD � + Hardware version: 4.0.0 + Firmware version: 255.255.253 + Device ID : 0 + goodID : 1 + Remaining time: 0.849823951721 sec + + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + Lease Time: 10000 + Timeout: 4.91435289383 + ``` \ No newline at end of file From 217357d2fe7ee6cc28e2592f16f27959b90399ba Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Sat, 16 Sep 2017 14:13:27 +0530 Subject: [PATCH 27/50] removed isBaudValid from software --- XSMU-2.4.0/ChangeLog | 74 ++++++++++++++++++++++++--- XSMU-2.4.0/code/app/app/Comm.h | 1 - XSMU-2.4.0/code/app/src/Comm.cxx | 5 -- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 4 +- XSMU-2.4.0/code/sys/src/FTDI.cxx | 28 ---------- XSMU-2.4.0/code/sys/sys/FTDI.h | 1 - 6 files changed, 67 insertions(+), 46 deletions(-) diff --git a/XSMU-2.4.0/ChangeLog b/XSMU-2.4.0/ChangeLog index 9fd47f9..c4b0b49 100644 --- a/XSMU-2.4.0/ChangeLog +++ b/XSMU-2.4.0/ChangeLog @@ -9,6 +9,65 @@ 2017-09-12 Gitansh Kataria +* Feature: A command keepAlive is added to tell the Firmware to keep streaming data. + + +* Comm.h/Comm/cxx: + + ^^ COMM_OPCODE + -- COMM_OPCODE_SYNC + ++ COMM_OPCODE_KEEP_ALIVE + + -- class CommPacket_Synchronize + -- class CommRequest_Synchronize + -- class CommResponse_Synchronize + + ++ class CommPacket_keepAlive + ++ class CommRequest_keepAlive + ++ class CommResponse_keepAlive + + ^^ COMM_CBCODE + -- COMM_CBCODE_SYNC + ++ COMM_CBCODE_KEEP_ALIVE + + -- class CommCB_Sync + ++ class CommCB_keepAlive + + ^^ union CommCB_Union + -- char gen2 [sizeof (CommCB_Sync)] + ++ char gen2 [sizeof (CommCB_keepAlive)] + + ^^ class Comm : public Applet + -- void SyncCB (void* uint16_t) + ++ void keepAlive_CB (void*, uint16_t) + + ++ void transmit_keepAlive (uint32_t) + +* virtuaSMU.h/virtuaSMU.cxx: + + ++ void keepAlive (uint32_t*, float*) + + -- void syncCB (const CommCB* oCB); + ++ void keepAliveCB (const CommCB* oCB); + +* libxsmu.h/libxsmu.cxx: + + ++ void keepAlive (int, unsigned int, float, + unsigned int*, float*); + +* libxsmu.i: + + ++ void keepAlive (int, unsigned int, float, + unsigned int*, float*); + ++ void keepAlive (int, unsigned int, float, + unsigned int*, float*); + +------------------------------------------------------------------------ + +### 2.4.0 + +2017-09-12 Gitansh Kataria + * Feature: Python test file for changeBaud() function ++ changeBaud.py @@ -21,6 +80,11 @@ * Feature: A command to change baud-rate is added. +* FTDI.h/FTDI.cxx: + + ++ void setBaudRate (uint32_t bd); + ++ void _setBaudrate (uint32_t baudrate) + * virtuaSMU.h/virtuaSMU.cxx: ^^ class Driver @@ -40,14 +104,6 @@ ++ void changeBaud (int, unsigned int, float, unsigned int*, float*); ------------------------------------------------------------------------- - -### 2.4.0 - -2017-09-11 Gitansh Kataria - -* Feature: A command to change baud-rate is added. - * Comm.h/Comm.cxx: ^^ COMM_OPCODE @@ -69,6 +125,8 @@ ++ void changeBaud_CB (void*, uint16_t) ++ void transmit_changeBaud (uint32_t) + ++ void setBaudRate (uint32_t) + ------------------------------------------------------------------------ r6 | (no author) | 2013-08-30 12:51:38 +0530 (Fri, 30 Aug 2013) | 4 lines diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index d34f018..c6098d7 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -2637,7 +2637,6 @@ class Comm : public Applet void transmit (const QP4_Packet* packet); public: - bool isBaudValid (uint32_t baudRate); void setBaudRate (uint32_t baudRate); }; diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index c4594b1..9dd9a2c 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -145,11 +145,6 @@ void Comm::transmit (const QP4_Packet* packet) /************************************************************************/ -bool Comm::isBaudValid (uint32_t baudRate) -{ - return ftdi_->isBaudValid (baudRate); -} - void Comm::setBaudRate (uint32_t baudRate) { ftdi_->setBaudRate (baudRate); diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 61ced00..8d29675 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -583,10 +583,8 @@ void Driver::changeBaudCB (const CommCB* oCB) baudRate_ = o->baudRate(); - if (comm_->isBaudValid (baudRate_)) - ackBits_.set (COMM_CBCODE_CHANGE_BAUD); - comm_->setBaudRate (baudRate_); + ackBits_.set (COMM_CBCODE_CHANGE_BAUD); } /************************************************************************/ diff --git a/XSMU-2.4.0/code/sys/src/FTDI.cxx b/XSMU-2.4.0/code/sys/src/FTDI.cxx index b176dcd..76b1cb9 100644 --- a/XSMU-2.4.0/code/sys/src/FTDI.cxx +++ b/XSMU-2.4.0/code/sys/src/FTDI.cxx @@ -239,34 +239,6 @@ bool FTDI::good (void) const return handle_; } -bool FTDI::isBaudValid (uint32_t bd) -{ - switch (bd) - { - case 9600: - return true; - - - case 19200: - return true; - - - case 38400: - return true; - - - case 57600: - return true; - - - case 115200: - return true; - - default: - return false; - } -} - void FTDI::setBaudRate (uint32_t bd) { switch (bd) diff --git a/XSMU-2.4.0/code/sys/sys/FTDI.h b/XSMU-2.4.0/code/sys/sys/FTDI.h index 54cf3e3..3f60aca 100644 --- a/XSMU-2.4.0/code/sys/sys/FTDI.h +++ b/XSMU-2.4.0/code/sys/sys/FTDI.h @@ -51,7 +51,6 @@ class FTDI static std::vector scan (int vid, int pid); public: - bool isBaudValid (uint32_t bd); void setBaudRate (uint32_t bd); private: From d62ce320ba3672181fa304fcb4085cdbdc2ae7b7 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Mon, 18 Sep 2017 12:20:25 +0530 Subject: [PATCH 28/50] Added a async thread running in the background, and lock object in the Comm --- XSMU-2.4.0/code/app/app/Comm.h | 10 ++ XSMU-2.4.0/code/app/app/Exception.h | 25 +++++ XSMU-2.4.0/code/app/src/Exception.cxx | 1 + XSMU-2.4.0/code/app/src/Makefile | 3 +- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 130 +++++++++++++++++++++++++- 5 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 XSMU-2.4.0/code/app/app/Exception.h create mode 100644 XSMU-2.4.0/code/app/src/Exception.cxx diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index c6098d7..c610f52 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace smu{ @@ -2638,6 +2639,15 @@ class Comm : public Applet public: void setBaudRate (uint32_t baudRate); + +public: + std::unique_lock lock (void) + { + return std::unique_lock (_lock); + } + +private: + std::mutex _lock; }; /************************************************************************/ diff --git a/XSMU-2.4.0/code/app/app/Exception.h b/XSMU-2.4.0/code/app/app/Exception.h new file mode 100644 index 0000000..4e0c7d3 --- /dev/null +++ b/XSMU-2.4.0/code/app/app/Exception.h @@ -0,0 +1,25 @@ +#ifndef __SMU_EXCEPTION__ +#define __SMU_EXCEPTION__ + +#include + +// class XSMU_Error : public std::runtime_error +// { +// +// protected: +// XSMU_Error ((std::string) error_msg) : +// runtime_error (error_msg) +// {} +// }; + + +class NoOperation : public std::runtime_error +{ + +public: + NoOperation (void) : + std::runtime_error ("XSMU Error : No Operation") + {} +}; + +#endif \ No newline at end of file diff --git a/XSMU-2.4.0/code/app/src/Exception.cxx b/XSMU-2.4.0/code/app/src/Exception.cxx new file mode 100644 index 0000000..c5ed370 --- /dev/null +++ b/XSMU-2.4.0/code/app/src/Exception.cxx @@ -0,0 +1 @@ +#include "../app/Exception.h" \ No newline at end of file diff --git a/XSMU-2.4.0/code/app/src/Makefile b/XSMU-2.4.0/code/app/src/Makefile index cab2bbd..0e6df38 100644 --- a/XSMU-2.4.0/code/app/src/Makefile +++ b/XSMU-2.4.0/code/app/src/Makefile @@ -10,7 +10,8 @@ CPP_SRC = \ VM2.cxx \ virtuaSMU.cxx \ SystemConfig.cxx \ - version.cxx + version.cxx \ + Exception.cxx \ DEP = ${CPP_SRC:%.cxx=%.dep} OBJ = ${CPP_SRC:%.cxx=%.o} diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 8d29675..4b992c6 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -1,5 +1,6 @@ #include "../app/virtuaSMU.h" #include "../../sys/sys/Timer.h" +#include "../../app/app/Exception.h" #include #include @@ -60,6 +61,8 @@ Driver::Driver (void) Driver::~Driver (void) { + close(); + delete comm_; delete vm_; delete cm_; @@ -614,10 +617,19 @@ void Driver::open (const char* serialNo, float* timeout) << MINOR_VERSION_NO (versionInfo_->firmware_version()) << '.' << BUGFIX_VERSION_NO (versionInfo_->firmware_version()) << std::endl; + + _thread_future = std::async (&Driver::thread, this); } void Driver::close (void) { + try { + _alive = false; + _thread_future.get(); + } + catch (...) + {} + comm_->close(); } @@ -670,6 +682,8 @@ bool Driver::waitForResponse (uint16_t checkBit, float* timeout) if (elapsed > 100e-3) timer.sleep (10e-3); + if (ackBits_[COMM_CBCODE_NOP]) + throw NoOperation(); } while (!ackBits_[checkBit]); @@ -689,9 +703,10 @@ void Driver::identify (float* timeout) { identity_.clear(); versionInfo_->clear(); - ackBits_.reset (COMM_CBCODE_IDN); + ackBits_.reset (COMM_CBCODE_IDN); comm_->transmitIdentify(); + waitForResponse (COMM_CBCODE_IDN, timeout); } @@ -699,17 +714,49 @@ void Driver::identify (float* timeout) void Driver::keepAlive (uint32_t* lease_time_ms, float* timeout) { - ackBits_.reset (COMM_CBCODE_KEEP_ALIVE); + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_KEEP_ALIVE); comm_->transmit_keepAlive (*lease_time_ms); waitForResponse (COMM_CBCODE_KEEP_ALIVE, timeout); } +void Driver::thread (void) +{ + Timer timer; + + uint32_t lease_time_ms = 10000; + float timeout = 1; + + keepAlive (&lease_time_ms, &timeout); + double last_sent_at = timer.get(); + double elapsed = 0; + + while (_alive) + { + elapsed = timer.get() - last_sent_at; + if (elapsed > lease_time_ms/3) + { + timeout = 1; + keepAlive (&lease_time_ms, &timeout); + last_sent_at = timer.get(); + } + + /******************************************************** + * Prevents 100% CPU utilization, + * in case the operation is taking longer than 100ms. + * *******************************************************/ + timer.sleep (10e-3); + } +} + /************************************************************************/ void Driver::setSourceMode (SourceMode* mode, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_SET_SOURCE_MODE); comm_->transmitSourceMode (toComm_SourceMode ((uint16_t)*mode)); if (waitForResponse (COMM_CBCODE_SET_SOURCE_MODE, timeout)) { @@ -727,9 +774,10 @@ void Driver::setSourceMode (SourceMode* mode, float* timeout) void Driver::CS_setRange (CS_Range* range, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_SET_RANGE); comm_->transmit_CS_setRange (toComm_CS_Range (*range)); - comm_->transmit_CS_setRange (toComm_CS_Range (*range)); if (waitForResponse (COMM_CBCODE_CS_SET_RANGE, timeout)) *range = (cs_->range()); @@ -755,6 +803,8 @@ void Driver::CS_getCalibration (uint16_t* index, int16_t* dac, void Driver::CS_verifyCalibration (uint16_t* index, int16_t* dac, float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_VERIFY_CALIBRATION); comm_->transmit_CS_verifyCalibration (*index); @@ -770,6 +820,8 @@ void Driver::CS_verifyCalibration (uint16_t* index, int16_t* dac, void Driver::CS_setCalibration (uint16_t* index, int16_t* dac, float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_SET_CALIBRATION); comm_->transmit_CS_setCalibration (*index,* current); @@ -784,6 +836,8 @@ void Driver::CS_setCalibration (uint16_t* index, int16_t* dac, void Driver::CS_saveCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_SAVE_CALIBRATION); comm_->transmit_CS_saveCalibration(); waitForResponse (COMM_CBCODE_CS_SAVE_CALIBRATION, timeout); @@ -793,6 +847,8 @@ void Driver::CS_saveCalibration (float* timeout) void Driver::CS_setCurrent (float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_SET_CURRENT); comm_->transmit_CS_setCurrent (*current); @@ -805,6 +861,8 @@ void Driver::CS_setCurrent (float* current, float* timeout) void Driver::VS_setRange (VS_Range* range, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_SET_RANGE); comm_->transmit_VS_setRange (toComm_VS_Range (*range)); @@ -817,6 +875,8 @@ void Driver::VS_setRange (VS_Range* range, float* timeout) void Driver::VS_getCalibration (uint16_t* index, int16_t* dac, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_GET_CALIBRATION); comm_->transmit_VS_getCalibration (*index); @@ -832,6 +892,8 @@ void Driver::VS_getCalibration (uint16_t* index, int16_t* dac, void Driver::VS_verifyCalibration (uint16_t* index, int16_t* dac, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_VERIFY_CALIBRATION); comm_->transmit_VS_verifyCalibration (*index); @@ -847,6 +909,8 @@ void Driver::VS_verifyCalibration (uint16_t* index, int16_t* dac, void Driver::VS_setCalibration (uint16_t* index, int16_t* dac, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_SET_CALIBRATION); comm_->transmit_VS_setCalibration (*index,* voltage); @@ -861,6 +925,8 @@ void Driver::VS_setCalibration (uint16_t* index, int16_t* dac, void Driver::VS_saveCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_SAVE_CALIBRATION); comm_->transmit_VS_saveCalibration(); waitForResponse (COMM_CBCODE_VS_SAVE_CALIBRATION, timeout); @@ -870,6 +936,8 @@ void Driver::VS_saveCalibration (float* timeout) void Driver::VS_setVoltage (float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_SET_VOLTAGE); comm_->transmit_VS_setVoltage (*voltage); @@ -882,6 +950,8 @@ void Driver::VS_setVoltage (float* voltage, float* timeout) void Driver::CM_setRange (CM_Range* range, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_SET_RANGE); comm_->transmit_CM_setRange (toComm_CM_Range (*range)); @@ -894,6 +964,8 @@ void Driver::CM_setRange (CM_Range* range, float* timeout) void Driver::CM_getCalibration (uint16_t* index, int32_t* adc, float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_GET_CALIBRATION); comm_->transmit_CM_getCalibration (*index); @@ -909,6 +981,8 @@ void Driver::CM_getCalibration (uint16_t* index, int32_t* adc, void Driver::CM_setCalibration (uint16_t* index, int32_t* adc, float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_SET_CALIBRATION); comm_->transmit_CM_setCalibration (*index,* current); @@ -923,6 +997,8 @@ void Driver::CM_setCalibration (uint16_t* index, int32_t* adc, void Driver::CM_saveCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_SAVE_CALIBRATION); comm_->transmit_CM_saveCalibration(); waitForResponse (COMM_CBCODE_CM_SAVE_CALIBRATION, timeout); @@ -933,6 +1009,8 @@ void Driver::CM_saveCalibration (float* timeout) void Driver::CM_read (uint16_t* filterLength, float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_READ); comm_->transmit_CM_read (*filterLength); if (waitForResponse (COMM_CBCODE_CM_READ, timeout)) { @@ -946,6 +1024,8 @@ void Driver::CM_read (uint16_t* filterLength, float* current, void Driver::VM_setRange (VM_Range* range, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_SET_RANGE); comm_->transmit_VM_setRange (toComm_VM_Range (*range)); @@ -958,6 +1038,8 @@ void Driver::VM_setRange (VM_Range* range, float* timeout) void Driver::VM_getCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_GET_CALIBRATION); comm_->transmit_VM_getCalibration (*index); @@ -973,6 +1055,8 @@ void Driver::VM_getCalibration (uint16_t* index, int32_t* adc, void Driver::VM_setCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_SET_CALIBRATION); comm_->transmit_VM_setCalibration (*index,* voltage); @@ -987,6 +1071,8 @@ void Driver::VM_setCalibration (uint16_t* index, int32_t* adc, void Driver::VM_saveCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_SAVE_CALIBRATION); comm_->transmit_VM_saveCalibration(); waitForResponse (COMM_CBCODE_VM_SAVE_CALIBRATION, timeout); @@ -997,6 +1083,8 @@ void Driver::VM_saveCalibration (float* timeout) void Driver::VM_read (uint16_t* filterLength, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_READ); comm_->transmit_VM_read (*filterLength); if (waitForResponse (COMM_CBCODE_VM_READ, timeout)) { @@ -1010,6 +1098,8 @@ void Driver::VM_read (uint16_t* filterLength, float* voltage, void Driver::CS_loadDefaultCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION); comm_->transmit_CS_loadDefaultCalibration(); waitForResponse (COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION, timeout); @@ -1019,6 +1109,8 @@ void Driver::CS_loadDefaultCalibration (float* timeout) void Driver::VS_loadDefaultCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION); comm_->transmit_VS_loadDefaultCalibration(); waitForResponse (COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION, timeout); @@ -1028,6 +1120,8 @@ void Driver::VS_loadDefaultCalibration (float* timeout) void Driver::CM_loadDefaultCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION); comm_->transmit_CM_loadDefaultCalibration(); waitForResponse (COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION, timeout); @@ -1037,6 +1131,8 @@ void Driver::CM_loadDefaultCalibration (float* timeout) void Driver::VM_loadDefaultCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION); comm_->transmit_VM_loadDefaultCalibration(); waitForResponse (COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION, timeout); @@ -1048,6 +1144,8 @@ void Driver::VM_loadDefaultCalibration (float* timeout) void Driver::RM_readAutoscale (uint16_t* filterLength, float* resistance,float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_RM_READ_AUTOSCALE); comm_->transmit_RM_readAutoscale (*filterLength); if (waitForResponse (COMM_CBCODE_RM_READ_AUTOSCALE, timeout)) { @@ -1060,6 +1158,8 @@ void Driver::RM_readAutoscale (uint16_t* filterLength, void Driver::SystemConfig_Save (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_SYSTEM_CONFIG_SAVE); comm_->transmit_SystemConfig_Save(); waitForResponse (COMM_CBCODE_SYSTEM_CONFIG_SAVE, timeout); @@ -1067,6 +1167,8 @@ void Driver::SystemConfig_Save (float* timeout) void Driver::SystemConfig_LoadDefault (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_SYSTEM_CONFIG_LOAD_DEFAULT); comm_->transmit_SystemConfig_LoadDefault(); waitForResponse (COMM_CBCODE_SYSTEM_CONFIG_LOAD_DEFAULT, timeout); @@ -1075,6 +1177,8 @@ void Driver::SystemConfig_LoadDefault (float* timeout) void Driver:: SystemConfig_Get_hardwareVersion (uint32_t* version, float* timeout) { + auto unique_lock = comm_->lock(); + /**** Getting PCB information ****/ ackBits_.reset (COMM_CBCODE_SYSTEM_CONFIG_GET); comm_->transmit_SystemConfig_Get ( @@ -1109,6 +1213,8 @@ SystemConfig_Get_hardwareVersion (uint32_t* version, float* timeout) void Driver:: SystemConfig_Set_hardwareVersion (uint32_t* version, float* timeout) { + auto unique_lock = comm_->lock(); + /**** Setting PCB information ****/ ackBits_.reset (COMM_CBCODE_SYSTEM_CONFIG_SET); comm_->transmit_SystemConfig_Set ( @@ -1148,6 +1254,8 @@ SystemConfig_Set_hardwareVersion (uint32_t* version, float* timeout) void Driver::VM2_setRange (VM2_Range* range, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_SET_RANGE); comm_->transmit_VM2_setRange (toComm_VM2_Range (*range)); @@ -1160,6 +1268,8 @@ void Driver::VM2_setRange (VM2_Range* range, float* timeout) void Driver::VM2_getCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_GET_CALIBRATION); comm_->transmit_VM2_getCalibration (*index); @@ -1175,6 +1285,8 @@ void Driver::VM2_getCalibration (uint16_t* index, int32_t* adc, void Driver::VM2_setCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_SET_CALIBRATION); comm_->transmit_VM2_setCalibration (*index,* voltage); @@ -1189,6 +1301,8 @@ void Driver::VM2_setCalibration (uint16_t* index, int32_t* adc, void Driver::VM2_saveCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_SAVE_CALIBRATION); comm_->transmit_VM2_saveCalibration(); waitForResponse (COMM_CBCODE_VM2_SAVE_CALIBRATION, timeout); @@ -1199,6 +1313,8 @@ void Driver::VM2_saveCalibration (float* timeout) void Driver::VM2_read (uint16_t* filterLength, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_READ); comm_->transmit_VM2_read (*filterLength); @@ -1210,6 +1326,8 @@ void Driver::VM2_read (uint16_t* filterLength, float* voltage, void Driver::VM2_loadDefaultCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION); comm_->transmit_VM2_loadDefaultCalibration(); waitForResponse (COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION, timeout); @@ -1219,6 +1337,8 @@ void Driver::VM2_loadDefaultCalibration (float* timeout) void Driver::VM_setTerminal (VM_Terminal* terminal, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_SET_TERMINAL); comm_->transmit_VM_setTerminal (toComm_VM_Terminal (*terminal)); @@ -1228,6 +1348,8 @@ void Driver::VM_setTerminal (VM_Terminal* terminal, float* timeout) void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_GET_TERMINAL); comm_->transmit_VM_getTerminal (); @@ -1240,6 +1362,8 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) void Driver::changeBaud (uint32_t* baudRate, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); comm_->transmit_changeBaud (*baudRate); From 2957817e2607cdc835d14e07d3d202556b35ddcc Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Mon, 18 Sep 2017 12:31:15 +0530 Subject: [PATCH 29/50] Added virtuaSMU.h --- XSMU-2.4.0/code/app/app/virtuaSMU.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index b47b454..7e1d2e4 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -13,6 +13,7 @@ #include #include +#include namespace smu { @@ -58,7 +59,9 @@ class Driver { /***************************************************/ void identify (float* timeout); + void keepAlive (uint32_t* lease_time_ms, float* timeout); + void thread (void); void setSourceMode (SourceMode* mode, float* timeout); @@ -253,6 +256,8 @@ class Driver { private: uint32_t baudRate_; + bool _alive; + std::future _thread_future; }; From 2bb411668ff11a3672c7e566668d8d33e5645adb Mon Sep 17 00:00:00 2001 From: Shyam Date: Mon, 18 Sep 2017 13:06:51 +0530 Subject: [PATCH 30/50] Added test results for keep alive thread and lock mechanism --- XSMU-2.4.0/code/app/src/Comm.cxx | 2 +- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 8 + changeBaudTesting.md | 256 +++++++++++++++++++++++++- 3 files changed, 264 insertions(+), 2 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 9dd9a2c..f2711e2 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -168,7 +168,7 @@ void Comm::processReceivedData (const void* data, uint16_t size) if (size) do { - std::printf ("%X %c\n", static_cast (*src), *src); + //std::printf ("%X %c\n", static_cast (*src), *src); qp4_->receiver().push_back (*src++); if (qp4_->receiver().ready()) { diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 4b992c6..ca476b0 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -619,6 +619,7 @@ void Driver::open (const char* serialNo, float* timeout) << std::endl; _thread_future = std::async (&Driver::thread, this); + PRINT_DEBUG ("Asynch thread launched") } void Driver::close (void) @@ -715,6 +716,7 @@ void Driver::identify (float* timeout) void Driver::keepAlive (uint32_t* lease_time_ms, float* timeout) { auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_KEEP_ALIVE); comm_->transmit_keepAlive (*lease_time_ms); @@ -730,6 +732,7 @@ void Driver::thread (void) float timeout = 1; keepAlive (&lease_time_ms, &timeout); + PRINT_DEBUG ("Inside thread : Keep Alive sent") double last_sent_at = timer.get(); double elapsed = 0; @@ -740,6 +743,7 @@ void Driver::thread (void) { timeout = 1; keepAlive (&lease_time_ms, &timeout); + PRINT_DEBUG ("Inside thread : Keep Alive sent") last_sent_at = timer.get(); } @@ -937,6 +941,7 @@ void Driver::VS_saveCalibration (float* timeout) void Driver::VS_setVoltage (float* voltage, float* timeout) { auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_VS_SET_VOLTAGE); comm_->transmit_VS_setVoltage (*voltage); @@ -1084,6 +1089,8 @@ void Driver::VM_read (uint16_t* filterLength, float* voltage, float* timeout) { auto unique_lock = comm_->lock(); + + PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_VM_READ); comm_->transmit_VM_read (*filterLength); @@ -1363,6 +1370,7 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) void Driver::changeBaud (uint32_t* baudRate, float* timeout) { auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); diff --git a/changeBaudTesting.md b/changeBaudTesting.md index b426d4d..1fb502c 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -707,4 +707,258 @@ Timeout: 4.9146270752 10  Lease Time: 10000 Timeout: 4.91435289383 - ``` \ No newline at end of file + ``` + + +--- + +### Testing for async thread calling keepAlive() and locking mechanism in Comm +Added : +- PRINT_DEBUG ("Asynch thread launched") in open() +- PRINT_DEBUG ("Inside thread : Keep Alive sent") inside thread() +- PRINT_DEBUG ("Lock Acquired") in keepAlive, changeBaud, VS_setVoltage and VM_Read functions +- Output for `python keepAlive.py` + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):622:Asynch thread launched + Device ID : 0 + goodID : 1 + Remaining time: 0.869105100632 sec + + void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired + Lease Time: 10000 + Timeout: 4.89869022369 + void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired + void smu::Driver::thread():735:Inside thread : Keep Alive sent + ``` + +- Output for `python changeBaud.py` + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):622:Asynch thread launched + Device ID : 0 + goodID : 1 + Remaining time: 0.869477987289 sec + + void smu::Driver::changeBaud(uint32_t*, float*):1373:Lock Acquired + Baud Rate: 9600 + Timeout: 4.9146399498 + void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired + void smu::Driver::thread():735:Inside thread : Keep Alive sent + ``` +- Output for `python VS_setVoltage.py 1` + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):622:Asynch thread launched + Device ID : 0 + goodID : 1 + Remaining time: 0.850958108902 sec + + void smu::Driver::VS_setVoltage(float*, float*):944:Lock Acquired + Voltage: 0.999929249287 + Timeout: 4.91469097137 + void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired + void smu::Driver::thread():735:Inside thread : Keep Alive sent + ``` +- Output for `python VM_Read.py` (Ended with `Ctrl+c`) + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):622:Asynch thread launched + Device ID : 0 + goodID : 1 + Remaining time: 0.870882987976 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.13914418221 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15525889397 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17055797577 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.1550321579 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17103505135 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20280408859 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15487217903 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17105913162 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20312213898 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20294713974 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15506291389 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.1709561348 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20299291611 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15482211113 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17106795311 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20310091972 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20291304588 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15489888191 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17089796066 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20286202431 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15500307083 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17052602768 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20300483704 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20285892487 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15503001213 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17059803009 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20324611664 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15489792824 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17091703415 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20329713821 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20329809189 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15476918221 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17097902298 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20291399956 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15500283241 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17109894753 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20278191566 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20280718803 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15464901924 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17091703415 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20296692848 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15501594543 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + ^CTraceback (most recent call last): + File "VM_getReading.py", line 40, in + voltage, timeout = libxsmu.VM_getReading (deviceID, filter_length, timeout) + KeyboardInterrupt + ``` From 09a18432e56034dde2ecde35eddf437c7fde0852 Mon Sep 17 00:00:00 2001 From: Shyam Date: Mon, 18 Sep 2017 16:09:20 +0530 Subject: [PATCH 31/50] Updated Test Results, Implemented possible bug fixes --- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 15 +- .../wrapper/python/test/VM_getReading.py | 6 +- XSMU-2.4.0/wrapper/python/test/changeBaud.py | 3 + changeBaudTesting.md | 139 ++++++++++++++++++ 4 files changed, 155 insertions(+), 8 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index ca476b0..858d534 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -595,6 +595,8 @@ void Driver::changeBaudCB (const CommCB* oCB) void Driver::open (const char* serialNo, float* timeout) { + PRINT_DEBUG ("Opening Device") + std::cout << "libxsmu version: " << MAJOR_VERSION_NO (versionInfo_->libxsmu_version()) << "." << MINOR_VERSION_NO (versionInfo_->libxsmu_version()) << "." @@ -618,13 +620,14 @@ void Driver::open (const char* serialNo, float* timeout) << BUGFIX_VERSION_NO (versionInfo_->firmware_version()) << std::endl; - _thread_future = std::async (&Driver::thread, this); - PRINT_DEBUG ("Asynch thread launched") + _thread_future = std::async (std::launch::async, &Driver::thread, this); + PRINT_DEBUG ("Async thread launched") } void Driver::close (void) { try { + PRINT_DEBUG ("Closing Device") _alive = false; _thread_future.get(); } @@ -715,6 +718,7 @@ void Driver::identify (float* timeout) void Driver::keepAlive (uint32_t* lease_time_ms, float* timeout) { + PRINT_DEBUG ("Trying to Acquire Lock") auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") @@ -735,11 +739,12 @@ void Driver::thread (void) PRINT_DEBUG ("Inside thread : Keep Alive sent") double last_sent_at = timer.get(); double elapsed = 0; - + + PRINT_DEBUG ("Inside thread : Alive " << _alive) while (_alive) { elapsed = timer.get() - last_sent_at; - if (elapsed > lease_time_ms/3) + if (elapsed > lease_time_ms/3000) { timeout = 1; keepAlive (&lease_time_ms, &timeout); @@ -1088,8 +1093,8 @@ void Driver::VM_saveCalibration (float* timeout) void Driver::VM_read (uint16_t* filterLength, float* voltage, float* timeout) { + PRINT_DEBUG ("Trying to Acquire Lock") auto unique_lock = comm_->lock(); - PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_VM_READ); diff --git a/XSMU-2.4.0/wrapper/python/test/VM_getReading.py b/XSMU-2.4.0/wrapper/python/test/VM_getReading.py index a68b2dd..1ae1419 100644 --- a/XSMU-2.4.0/wrapper/python/test/VM_getReading.py +++ b/XSMU-2.4.0/wrapper/python/test/VM_getReading.py @@ -34,7 +34,7 @@ logfile = open ('log.txt', 'w') -for n in range (0, 200): +for n in range (0, 100): filter_length = 32 timeout = 1 + 0.03 * filter_length voltage, timeout = libxsmu.VM_getReading (deviceID, filter_length, timeout) @@ -44,10 +44,10 @@ logfile.write (str (voltage) + '\n') logfile.flush() - # sleep (1) + #sleep (1) if (timeout == 0.0): - print 'Communication timeout in CM_getReading.' + print 'Communication timeout in VM_getReading.' exit (-2) ########################################################################## diff --git a/XSMU-2.4.0/wrapper/python/test/changeBaud.py b/XSMU-2.4.0/wrapper/python/test/changeBaud.py index 207ae0b..4d55490 100644 --- a/XSMU-2.4.0/wrapper/python/test/changeBaud.py +++ b/XSMU-2.4.0/wrapper/python/test/changeBaud.py @@ -1,4 +1,5 @@ import libxsmu, time, math, sys +from time import sleep ########################################################################## # Scans USB bus for Xplore SMU. @@ -28,6 +29,8 @@ print 'Communication timeout in open_device.' exit (-2) +sleep (5) + ########################################################################## # Set Baud Rate of communication diff --git a/changeBaudTesting.md b/changeBaudTesting.md index 1fb502c..e5e1837 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -962,3 +962,142 @@ Added : voltage, timeout = libxsmu.VM_getReading (deviceID, filter_length, timeout) KeyboardInterrupt ``` +The output of this last test is not as expected. Since the keepAlive function is being called in a parallel thread, it should the Lock Acquired for keeAlive should show up in between the Lock Acquired for VM_read. + + +But if the range is changed from (0, 200) to (0, 1) in `VM_getReading.py`, the output is : + +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +Hardware version: 4.0.0 +Firmware version: 255.255.253 +void smu::Driver::open(const char*, float*):622:Async thread launched +Device ID : 0 +goodID : 1 +Remaining time: 0.832612991333 sec + +void smu::Driver::VM_read(uint16_t*, float*, float*):1094:Lock Acquired +voltage : -2.67028808594e-05 +Remaining time : 1.18702793121 sec + +void smu::Driver::keepAlive(uint32_t*, float*):718:Trying to Acquire Lock +void smu::Driver::keepAlive(uint32_t*, float*):720:Lock Acquired +void smu::Driver::thread():736:Inside thread : Keep Alive sent +``` +- Added std::launch::async as argument to std::async to always set asynchronous operation of thread. +- Fixed bug in `Driver::thread()` to convert ms into seconds for comparison inside while look +- Output : + + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):598:Opening Device + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):624:Async thread launched + Device ID : 0 + goodID : 1 + Remaining time: void smu::Driver::keepAlive(uint32_t*, float*)0.88267493248 sec : + + 721:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):723:Lock Acquired + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::thread():void smu::Driver::VM_read(uint16_t*, float*, float*):739:1098:Lock Acquired + Inside thread : Keep Alive sent + void smu::Driver::thread():743:Inside thread : Alive 139 + voltage : -2.47955322266e-05 + Remaining time : 1.17120504379 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.86102294922e-05 + Remaining time : 1.17108106613 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.86102294922e-05 + Remaining time : 1.15503096581 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + void smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock + voltage : -2.67028808594e-05 + Remaining time : void smu::Driver::keepAlive(uint32_t*, float*)1.17121624947 sec + + :723:Lock Acquired + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::thread():751:Inside thread : Keep Alive sent + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.16077613831 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.95639038086e-05 + Remaining time : 1.17108201981 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.1545920372 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + void smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock + voltage : void smu::Driver::keepAlive(uint32_t*, float*):-2.86102294922e-05723 + Remaining time ::Lock Acquired + 1.17104387283 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::thread():751:Inside thread : Keep Alive sentvoid smu::Driver::VM_read(uint16_t*, float*, float*):1098: + Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.16069293022 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.67028808594e-05 + Remaining time : 1.17099499702 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.67028808594e-05 + Remaining time : 1.15505194664 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + void smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock + voltage : -2.47955322266e-05 + Remaining time : 1.1710100174 secvoid smu::Driver::keepAlive(uint32_t*, float*) + + :723:Lock Acquired + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::thread():751:Inside thread : Keep Alive sent + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.16075015068 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.1713449955 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.15498399734 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + ^Cvoid smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):723:Lock Acquired + Traceback (most recent call last): + File "VM_getReading.py", line 40, in + voltage, timeout = libxsmu.VM_getReading (deviceID, filter_length, timeout) + KeyboardInterrupt + ``` \ No newline at end of file From 499b760d3753b01e0b77c410ef808b9138b89d03 Mon Sep 17 00:00:00 2001 From: Shyam Date: Mon, 18 Sep 2017 18:40:34 +0530 Subject: [PATCH 32/50] Added REC_SIZE and REC_DATA interface. Incomplete. Do not clone/run this commit. [WIP] --- XSMU-2.4.0/TODO | 47 +++++++++++ XSMU-2.4.0/code/app/app/Comm.h | 113 ++++++++++++++++++++++++++ XSMU-2.4.0/code/app/app/virtuaSMU.h | 4 + XSMU-2.4.0/code/app/src/Comm.cxx | 25 ++++++ XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 63 ++++++++++++-- 5 files changed, 247 insertions(+), 5 deletions(-) create mode 100644 XSMU-2.4.0/TODO diff --git a/XSMU-2.4.0/TODO b/XSMU-2.4.0/TODO new file mode 100644 index 0000000..626649d --- /dev/null +++ b/XSMU-2.4.0/TODO @@ -0,0 +1,47 @@ +2.4.0 (Streamer) +================ + + Nature : Feature + Requested by : Quazar Research + + Status : Pending + Created on : 2017-09-09 by KC + Closed on : --- + +Description +----------- + +The SMU is to stream voltmeter data at a specified frequency. This requires following features to be implemented. + + 1) Dynamically change baudrate to suit data stream. + + -- CHANGE_BAUD + + 2) Start recording + + -- START_REC : Starts recording of timed data into internal buffer. + + 3) Transfer recorded data chunks to computer + + -- Two queues active and standby in firmware. + + -- REC_SIZE : Queries number of available data points in buffer + + -- Data from ADC keeps getting stored into the Active queue (interrupt driven) + -- Software asks for REC_SIZE, firmware returns size of Standby queue + + -- REC_DATA : Transfers requested number of data points to driver + + -- Firmware transfers data from Standby queue to software (may be in multiple packets; \ + depends on size of stored data and size of comm packet) + -- This transfer is uint32_t (ADC value) and not float. Conversion to float is to be done in software now. + -- This requires the functions XX_setCalibration() to also save the calibration table in software. + -- When no data remaining data in Standby queue (switch Active and Standby queues) + + 5) Stop recording + + -- STOP_REC : Stops recording gracefully. + + 6) + + -- KEEP_ALIVE : Stops recording if keep alive packets are not received, i.e. if driver is dead. diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index c610f52..d189b83 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -67,6 +67,8 @@ enum Comm_Opcode COMM_OPCODE_VM_GET_TERMINAL, //42 COMM_OPCODE_CHANGE_BAUD, //43 + COMM_OPCODE_REC_SIZE, //44 + COMM_OPCODE_REC_DATA, //45 }; enum Comm_SourceMode @@ -1607,6 +1609,73 @@ class CommResponse_changeBaud : public CommPacket_changeBaud private: uint32_t baudRate_; }; + +/************************************************************************/ + +class CommPacket_recSize : public CommPacket +{ +protected: + CommPacket_recSize (void) : + CommPacket (COMM_OPCODE_REC_SIZE) + {} +}; + +class CommRequest_recSize : public CommPacket_recSize +{ +public: + CommRequest_recSize (uint32_t recSize) : + recSize_ (smu::hton (recSize)) + {} + +private: + uint32_t recSize_; +}; + +class CommResponse_recSize : public CommPacket_recSize +{ +private: + CommResponse_recSize (void); + +public: + uint32_t recSize (void) const {return smu::ntoh(recSize_);} + +private: + uint32_t recSize_; +}; + +/************************************************************************/ + +class CommPacket_recData : public CommPacket +{ +protected: + CommPacket_recData (void) : + CommPacket (COMM_OPCODE_REC_DATA) + {} +}; + +class CommRequest_recData : public CommPacket_recData +{ +public: + CommRequest_recData (int32_t *recData) : + recData_ (smu::hton (recData)) + {} + +private: + int32_t *recData_; +}; + +class CommResponse_recData : public CommPacket_recData +{ +private: + CommResponse_recData (void); + +public: + int32_t *recData (void) const {return smu::ntoh(recData_);} + +private: + int32_t *recData_; +}; + /************************************************************************/ /************************************************************************/ @@ -1667,6 +1736,8 @@ enum Comm_CallbackCode COMM_CBCODE_VM_GET_TERMINAL, //42 COMM_CBCODE_CHANGE_BAUD, //43 + COMM_CBCODE_REC_SIZE, //44 + COMM_CBCODE_REC_DATA, //45 }; /************************************************************************/ @@ -2416,6 +2487,41 @@ class CommCB_changeBaud : public CommCB private: uint32_t baudRate_; }; + +/************************************************************************/ + +class CommCB_recSize : public CommCB +{ +public: + CommCB_recSize (uint32_t recSize) : + CommCB (COMM_CBCODE_REC_SIZE), + recSize_ (recSize) + {} + +public: + uint32_t recSize (void) const {return recSize_;} + +private: + uint32_t recSize_; +}; + +/************************************************************************/ + +class CommCB_recData : public CommCB +{ +public: + CommCB_recData (int32_t *recData) : + CommCB (COMM_CBCODE_REC_DATA), + recData_ (recData) + {} + +public: + int32_t *recData (void) const {return recData_;} + +private: + int32_t *recData_; +}; + /************************************************************************/ /************************************************************************/ @@ -2426,6 +2532,8 @@ union CommCB_Union char gen2[sizeof (CommCB_keepAlive)]; char gen3[sizeof (CommCB_SetSourceMode)]; char gen4[sizeof (CommCB_changeBaud)]; + char gen5[sizeof (CommCB_recSize)]; + char gen6[sizeof (CommCB_recData)]; char cs0[sizeof (CommCB_CS_SetRange)]; char cs1[sizeof (CommCB_CS_GetCalibration)]; @@ -2566,6 +2674,8 @@ class Comm : public Applet /********************************/ void transmit_changeBaud (uint32_t baudRate); + void transmit_recSize (uint32_t recSize); + void transmit_recData (int32_t *recData); private: QP4* qp4_; @@ -2634,6 +2744,9 @@ class Comm : public Applet void changeBaudCB (const void* data, uint16_t size); + void recSizeCB (const void* data, uint16_t size); + void recDataCB (const void* data, uint16_t size); + private: void transmit (const QP4_Packet* packet); diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index 7e1d2e4..8b9486b 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -170,6 +170,8 @@ class Driver { /***************************************************/ void changeBaud (uint32_t* baudRate, float* timeout); + void recSize (uint32_t* recSize, float* timeout); + void recData (int32_t* recData, float* timeout); /***************************************************/ public: @@ -240,6 +242,8 @@ class Driver { void VM_getTerminalCB (const CommCB* oCB); void changeBaudCB (const CommCB* oCB); + void recSizeCB (const CommCB* oCB); + void recDataCB (const CommCB* oCB); private: Comm* comm_; diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index f2711e2..0acdf8e 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -243,6 +243,8 @@ void Comm::interpret (const void* data, uint16_t size) &Comm::VM_getTerminalCB, &Comm::changeBaudCB, + &Comm::recSizeCB, + &Comm::recDataCB, }; if (size < sizeof (CommPacket)) @@ -767,6 +769,29 @@ void Comm::changeBaudCB (const void* data, uint16_t size) CommCB_changeBaud (res->baudRate())); } +void Comm::recSizeCB (const void* data, uint16_t size) +{ + if (size < sizeof (CommResponse_recSize)) + return; + + const CommResponse_recSize* res = + reinterpret_cast (data); + + do_callback (new (&callbackObject_) + CommCB_recSize (res->recSize())); +} + +void Comm::recDataCB (const void* data, uint16_t size) +{ + if (size < sizeof (CommResponse_recData)) + return; + + const CommResponse_recData* res = + reinterpret_cast (data); + + do_callback (new (&callbackObject_) + CommCB_recData (res->recData())); +} /************************************************************************/ /************************************************************************/ diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 858d534..a162d73 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -139,6 +139,8 @@ void Driver::comm_cb (const CommCB* oCB) &Driver::VM_getTerminalCB, &Driver::changeBaudCB, + &Driver::recSizeCB, + &Driver::recDataCB, }; if (oCB->code() < sizeof (cbs) / sizeof (cbs[0])) @@ -590,13 +592,38 @@ void Driver::changeBaudCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CHANGE_BAUD); } +/************************************************************************/ + +void Driver::recSizeCB (const CommCB* oCB) +{ + const CommCB_recSize* o = + reinterpret_cast (oCB); + + recSize_ = o->recSize(); + + comm_->setBaudRate (recSize_); + ackBits_.set (COMM_CBCODE_REC_SIZE); +} + +/************************************************************************/ + +void Driver::recDataCB (const CommCB* oCB) +{ + const CommCB_recData* o = + reinterpret_cast (oCB); + + recData_ = o->recData(); + + comm_->setBaudRate (recData_); + ackBits_.set (COMM_CBCODE_REC_DATA); +} /************************************************************************/ /************************************************************************/ void Driver::open (const char* serialNo, float* timeout) { PRINT_DEBUG ("Opening Device") - + std::cout << "libxsmu version: " << MAJOR_VERSION_NO (versionInfo_->libxsmu_version()) << "." << MINOR_VERSION_NO (versionInfo_->libxsmu_version()) << "." @@ -736,11 +763,9 @@ void Driver::thread (void) float timeout = 1; keepAlive (&lease_time_ms, &timeout); - PRINT_DEBUG ("Inside thread : Keep Alive sent") double last_sent_at = timer.get(); double elapsed = 0; - - PRINT_DEBUG ("Inside thread : Alive " << _alive) + while (_alive) { elapsed = timer.get() - last_sent_at; @@ -748,7 +773,6 @@ void Driver::thread (void) { timeout = 1; keepAlive (&lease_time_ms, &timeout); - PRINT_DEBUG ("Inside thread : Keep Alive sent") last_sent_at = timer.get(); } @@ -1385,6 +1409,35 @@ void Driver::changeBaud (uint32_t* baudRate, float* timeout) *baudRate = baudRate_; } +/************************************************************************/ + +void Driver::recSize (uint32_t* recSize, float* timeout) +{ + auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") + + ackBits_.reset (COMM_CBCODE_REC_SIZE); + + comm_->transmit_recSize (*recSize); + + if (waitForResponse (COMM_CBCODE_REC_SIZE, timeout)) + *recSize = recSize_; +} + +/************************************************************************/ + +void Driver::recData (int32_t* recData, float* timeout) +{ + auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") + + ackBits_.reset (COMM_CBCODE_REC_DATA); + + comm_->transmit_recData (**recData); + + if (waitForResponse (COMM_CBCODE_REC_DATA, timeout)) + *recData = recData_; +} /************************************************************************/ /************************************************************************/ } From 82c7236931d77d8170080054d29967dc094ad101 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Tue, 19 Sep 2017 17:13:26 +0530 Subject: [PATCH 33/50] Added recSize() and recData() functions --- XSMU-2.4.0/code/app/app/Comm.h | 42 +++++++++++++++--------- XSMU-2.4.0/code/app/app/virtuaSMU.h | 17 ++++++++-- XSMU-2.4.0/code/app/src/Comm.cxx | 37 ++++++++++++++++++++- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 46 ++++++++++++++++++++------- XSMU-2.4.0/wrapper/python/libxsmu.h | 4 +-- 5 files changed, 115 insertions(+), 31 deletions(-) diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index d189b83..0554751 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -1623,12 +1623,8 @@ class CommPacket_recSize : public CommPacket class CommRequest_recSize : public CommPacket_recSize { public: - CommRequest_recSize (uint32_t recSize) : - recSize_ (smu::hton (recSize)) + CommRequest_recSize (void) {} - -private: - uint32_t recSize_; }; class CommResponse_recSize : public CommPacket_recSize @@ -1637,10 +1633,10 @@ class CommResponse_recSize : public CommPacket_recSize CommResponse_recSize (void); public: - uint32_t recSize (void) const {return smu::ntoh(recSize_);} + uint16_t recSize (void) const {return smu::ntoh(recSize_);} private: - uint32_t recSize_; + uint16_t recSize_; }; /************************************************************************/ @@ -1656,12 +1652,12 @@ class CommPacket_recData : public CommPacket class CommRequest_recData : public CommPacket_recData { public: - CommRequest_recData (int32_t *recData) : - recData_ (smu::hton (recData)) + CommRequest_recData (uint16_t recSize) : + recSize_ (smu::hton (recSize)) {} private: - int32_t *recData_; + uint16_t recSize_; }; class CommResponse_recData : public CommPacket_recData @@ -1670,10 +1666,22 @@ class CommResponse_recData : public CommPacket_recData CommResponse_recData (void); public: - int32_t *recData (void) const {return smu::ntoh(recData_);} + uint16_t dataSize (void) const {return smu::ntoh(size_);} + + int32_t * recData (void) const + { + for (uint16_t i = 0; i < sizeof(recData_)/sizeof(recData_[0]); ++i) + { + hostData_[i] = smu::ntoh(recData_[i]); + } + + return (hostData_); + } private: - int32_t *recData_; + uint16_t size_; + int32_t recData_[]; + mutable int32_t hostData_ [sizeof(recData_) / sizeof(recData_[0])]; }; /************************************************************************/ @@ -2510,15 +2518,19 @@ class CommCB_recSize : public CommCB class CommCB_recData : public CommCB { public: - CommCB_recData (int32_t *recData) : + CommCB_recData (uint16_t size, int32_t *recData) : CommCB (COMM_CBCODE_REC_DATA), + size_ (size), recData_ (recData) + {} public: + uint16_t dataSize (void) const {return size_;} int32_t *recData (void) const {return recData_;} private: + uint16_t size_; int32_t *recData_; }; @@ -2674,8 +2686,8 @@ class Comm : public Applet /********************************/ void transmit_changeBaud (uint32_t baudRate); - void transmit_recSize (uint32_t recSize); - void transmit_recData (int32_t *recData); + void transmit_recSize (void); + void transmit_recData (uint16_t recSize); private: QP4* qp4_; diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index 8b9486b..ad58f70 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -14,6 +14,8 @@ #include #include #include +#include +#include namespace smu { @@ -170,8 +172,9 @@ class Driver { /***************************************************/ void changeBaud (uint32_t* baudRate, float* timeout); - void recSize (uint32_t* recSize, float* timeout); - void recData (int32_t* recData, float* timeout); + + void recSize (float* timeout); + void recData (float* timeout); /***************************************************/ public: @@ -263,6 +266,16 @@ class Driver { bool _alive; std::future _thread_future; +private: + + uint16_t recSize_; //Stores size of available data with FW + std::queue _dataq; //Stores data obtained from FW + std::mutex _dataq_lock; + +public: + std::vector getData (void); + + }; /************************************************************************/ diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 0acdf8e..1f53f4f 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -790,7 +790,7 @@ void Comm::recDataCB (const void* data, uint16_t size) reinterpret_cast (data); do_callback (new (&callbackObject_) - CommCB_recData (res->recData())); + CommCB_recData (res->dataSize(), res->recData())); } /************************************************************************/ /************************************************************************/ @@ -1446,6 +1446,41 @@ void Comm::transmit_changeBaud (uint32_t baudRate) qp4_->transmitter().free_packet (req); } + +/************************************************************************/ + +void Comm::transmit_recSize (void) +{ + QP4_Packet* req = + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_recSize)); + + new (req->body()) + CommRequest_recSize(); + + req->seal(); + transmit (req); + + qp4_->transmitter().free_packet (req); +} + +/************************************************************************/ + +void Comm::transmit_recData (uint16_t recSize) +{ + QP4_Packet* req = + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_recData)); + + new (req->body()) + CommRequest_recData (recSize); + + req->seal(); + transmit (req); + + qp4_->transmitter().free_packet (req); +} + /************************************************************************/ /************************************************************************/ } // namespace smu diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index a162d73..0a91f59 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -601,7 +601,6 @@ void Driver::recSizeCB (const CommCB* oCB) recSize_ = o->recSize(); - comm_->setBaudRate (recSize_); ackBits_.set (COMM_CBCODE_REC_SIZE); } @@ -612,11 +611,20 @@ void Driver::recDataCB (const CommCB* oCB) const CommCB_recData* o = reinterpret_cast (oCB); - recData_ = o->recData(); + uint16_t size = o->dataSize(); //Size of data sent in this packet + const int32_t* data = o->recData(); //Pointer to data in this packet + + std::lock_guard lock(_dataq_lock); + + for (uint16_t i = 0; i < size; ++i) + { + _dataq.push(data[i]); + } + //std::copy (data, data + size, _dataq); - comm_->setBaudRate (recData_); ackBits_.set (COMM_CBCODE_REC_DATA); } + /************************************************************************/ /************************************************************************/ @@ -1411,33 +1419,49 @@ void Driver::changeBaud (uint32_t* baudRate, float* timeout) /************************************************************************/ -void Driver::recSize (uint32_t* recSize, float* timeout) +void Driver::recSize (float* timeout) { auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_REC_SIZE); - comm_->transmit_recSize (*recSize); + comm_->transmit_recSize(); - if (waitForResponse (COMM_CBCODE_REC_SIZE, timeout)) - *recSize = recSize_; + waitForResponse (COMM_CBCODE_REC_SIZE, timeout); } /************************************************************************/ -void Driver::recData (int32_t* recData, float* timeout) +void Driver::recData (float* timeout) { auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_REC_DATA); - comm_->transmit_recData (**recData); + comm_->transmit_recData (recSize_); + + waitForResponse (COMM_CBCODE_REC_DATA, timeout); +} + +/************************************************************************/ + +std::vector Driver::getData (void) +{ + std::vector data; + + std::lock_guard lock(_dataq_lock); - if (waitForResponse (COMM_CBCODE_REC_DATA, timeout)) - *recData = recData_; + while (!_dataq.empty()) + { + //TODO :data.push_back (ADC_to_VM (_dataq.front())); + _dataq.pop(); + } + + return data; } + /************************************************************************/ /************************************************************************/ } diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.h b/XSMU-2.4.0/wrapper/python/libxsmu.h index fced588..85bdde1 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.h +++ b/XSMU-2.4.0/wrapper/python/libxsmu.h @@ -253,8 +253,8 @@ void VM_getTerminal(int deviceID, float timeout, void changeBaud (int deviceID, unsigned int baudRate, float timeout, unsigned int *ret_baudRate, float *ret_timeout); -void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, unsigned int *ret_lease_time_ms, float *ret_timeout); - +void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, + unsigned int *ret_lease_time_ms, float *ret_timeout); #ifdef __cplusplus } // extern "C" From c48b580a38a11c071fa6b25ae90b4a99073eb803 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 20 Sep 2017 17:23:09 +0530 Subject: [PATCH 34/50] Added testing python interface for recSize, startRec and stopRec functions --- XSMU-2.4.0/code/app/app/Comm.h | 13 +++--- XSMU-2.4.0/code/app/app/virtuaSMU.h | 9 ++-- XSMU-2.4.0/code/app/src/Comm.cxx | 2 +- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 32 ++++++++++---- XSMU-2.4.0/wrapper/python/libxsmu.cxx | 44 +++++++++++++++++++ XSMU-2.4.0/wrapper/python/libxsmu.h | 61 +++++++++++++++++++++++++++ XSMU-2.4.0/wrapper/python/libxsmu.i | 20 +++++++++ 7 files changed, 162 insertions(+), 19 deletions(-) diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index 0554751..c5439e8 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -1666,22 +1666,21 @@ class CommResponse_recData : public CommPacket_recData CommResponse_recData (void); public: - uint16_t dataSize (void) const {return smu::ntoh(size_);} + uint16_t size (void) const {return smu::ntoh(size_);} int32_t * recData (void) const { - for (uint16_t i = 0; i < sizeof(recData_)/sizeof(recData_[0]); ++i) + for (uint16_t i = 0; i < size_; ++i) { - hostData_[i] = smu::ntoh(recData_[i]); + recData_[i] = smu::ntoh(recData_[i]); } - return (hostData_); + return (recData_); } private: uint16_t size_; - int32_t recData_[]; - mutable int32_t hostData_ [sizeof(recData_) / sizeof(recData_[0])]; + mutable int32_t recData_[]; }; /************************************************************************/ @@ -2526,7 +2525,7 @@ class CommCB_recData : public CommCB {} public: - uint16_t dataSize (void) const {return size_;} + uint16_t size (void) const {return size_;} int32_t *recData (void) const {return recData_;} private: diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index ad58f70..3a024d6 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -173,8 +173,8 @@ class Driver { void changeBaud (uint32_t* baudRate, float* timeout); - void recSize (float* timeout); - void recData (float* timeout); + void recSize (uint16_t* recSize, float* timeout); + void recData (uint16_t* size, float* timeout); /***************************************************/ public: @@ -274,8 +274,11 @@ class Driver { public: std::vector getData (void); + void startRec (void); + void stopRec (void); - +private: + bool _rec; }; /************************************************************************/ diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 1f53f4f..a625dc3 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -790,7 +790,7 @@ void Comm::recDataCB (const void* data, uint16_t size) reinterpret_cast (data); do_callback (new (&callbackObject_) - CommCB_recData (res->dataSize(), res->recData())); + CommCB_recData (res->size(), res->recData())); } /************************************************************************/ /************************************************************************/ diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 0a91f59..1ddbae0 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -611,7 +611,7 @@ void Driver::recDataCB (const CommCB* oCB) const CommCB_recData* o = reinterpret_cast (oCB); - uint16_t size = o->dataSize(); //Size of data sent in this packet + uint16_t size = o->size(); //Size of data sent in this packet const int32_t* data = o->recData(); //Pointer to data in this packet std::lock_guard lock(_dataq_lock); @@ -620,7 +620,6 @@ void Driver::recDataCB (const CommCB* oCB) { _dataq.push(data[i]); } - //std::copy (data, data + size, _dataq); ackBits_.set (COMM_CBCODE_REC_DATA); } @@ -768,7 +767,7 @@ void Driver::thread (void) Timer timer; uint32_t lease_time_ms = 10000; - float timeout = 1; + float timeout = 2; keepAlive (&lease_time_ms, &timeout); double last_sent_at = timer.get(); @@ -1419,7 +1418,7 @@ void Driver::changeBaud (uint32_t* baudRate, float* timeout) /************************************************************************/ -void Driver::recSize (float* timeout) +void Driver::recSize (uint16_t* recSize, float* timeout) { auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") @@ -1428,19 +1427,22 @@ void Driver::recSize (float* timeout) comm_->transmit_recSize(); - waitForResponse (COMM_CBCODE_REC_SIZE, timeout); + if (waitForResponse (COMM_CBCODE_REC_SIZE, timeout)) + *recSize = recSize_; } /************************************************************************/ -void Driver::recData (float* timeout) +void Driver::recData (uint16_t* recSize, float* timeout) { auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_REC_DATA); - comm_->transmit_recData (recSize_); + *recSize = recSize_; + + comm_->transmit_recData (*recSize); waitForResponse (COMM_CBCODE_REC_DATA, timeout); } @@ -1455,13 +1457,27 @@ std::vector Driver::getData (void) while (!_dataq.empty()) { - //TODO :data.push_back (ADC_to_VM (_dataq.front())); + data.push_back(_dataq.front()); _dataq.pop(); } return data; } +/************************************************************************/ + +void Driver::startRec (void) +{ + _rec = true; + PRINT_DEBUG ("REC : " << _rec); +} + +void Driver::stopRec (void) +{ + _rec = false; + PRINT_DEBUG ("REC : " << _rec); +} + /************************************************************************/ /************************************************************************/ } diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index fb4638a..100dee1 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -873,6 +873,32 @@ void changeBaud (int deviceID, unsigned int baudRate, float timeout, /************************************************************************/ +// void getData (int deviceID, std::vector *ret_data) +// { +// VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; +// +// std::vector data_; +// +// data_ = virtuaSMU->getData(); +// +// *ret_data = data_; +// } + +void startRec (int deviceID) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + virtuaSMU->startRec(); +} + +void stopRec (int deviceID) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + virtuaSMU->stopRec(); +} + +/************************************************************************/ +//Only for testing + void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, unsigned int *ret_lease_time_ms, float *ret_timeout) { @@ -891,5 +917,23 @@ void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, *ret_lease_time_ms = lease_time_ms_; } +void recSize (int deviceID, float timeout, + short unsigned int *ret_recSize, float *ret_timeout) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + short unsigned int recSize_; + float timeout_ = timeout; + + virtuaSMU->recSize (&recSize_, &timeout_); + + *ret_recSize = 0; + + if ((*ret_timeout = timeout_) == 0) + return; + + *ret_recSize = recSize_; +} + /************************************************************************/ /************************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.h b/XSMU-2.4.0/wrapper/python/libxsmu.h index 85bdde1..fe7b255 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.h +++ b/XSMU-2.4.0/wrapper/python/libxsmu.h @@ -249,13 +249,74 @@ void VM_getTerminal(int deviceID, float timeout, unsigned int *ret_terminal, float *ret_timeout); /************************************************************************/ +/** + * \brief Changes the Baud Rate of communication between the computer and the SMU. + * + * \return Current Baud Rate of communcation if a valid Baud Rate was provided. + * Otherwise, a NoOperation() exception is thrown. + * + */ void changeBaud (int deviceID, unsigned int baudRate, float timeout, unsigned int *ret_baudRate, float *ret_timeout); +/************************************************************************/ +/** + * \brief Gets data streamed from the SMU. + * + * \return C++ Vector containing streamed data from the SMU as float type + * + * This function will only return non-zero data when the \ref startRec function has been called, that starts streaming data from the SMU. + * + */ + +//void getData (int deviceID, std::vector *ret_data); + +/************************************************************************/ +/** + * \brief Starts recording streamed data from the SMU + * + * \return None + * + * This function sets a flag in the driver, to start recording streamed data from the SMU. + */ + +void startRec (int deviceID); +/************************************************************************/ +/** + * \brief Stops recording streamed data from the SMU + * + * \return None + * + * This function unsets a flag in the driver, to stop recording streamed data from the SMU. + */ + +void stopRec (int deviceID); + +/************************************************************************/ +/** + * \brief Sends a KEEP_ALIVE packet to the SMU, asking the SMU to communcate as usual + * for the next \ref lease_time_ms milliseconds + * + * \return The duration for which the SMU has been asked to keep alive. + * + */ void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, unsigned int *ret_lease_time_ms, float *ret_timeout); +/************************************************************************/ +/** + * \brief Queries the number of datapoints in the standby data queue in the SMU + * + * \return Number of datapoints in the standby data queue in the SMU + * + */ + +void recSize (int deviceID, float timeout, + short unsigned int *ret_recSize, float *ret_timeout); + +/************************************************************************/ +/************************************************************************/ #ifdef __cplusplus } // extern "C" diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.i b/XSMU-2.4.0/wrapper/python/libxsmu.i index 3ac1a1a..9059fc1 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.i +++ b/XSMU-2.4.0/wrapper/python/libxsmu.i @@ -1,9 +1,16 @@ %module libxsmu %include "typemaps.i" +%include "std_vector.i" +%include "stdint.i" %{ #include "libxsmu.h" %} +namespace std +{ + %template(FloatVector) vector; +} + %{ extern int scan(void); @@ -212,6 +219,12 @@ extern void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, unsigned int *ret_lease_time_ms, float *ret_timeout); +extern void startRec (int deviceID); + +extern void stopRec (int deviceID); + +extern void recSize (int deviceID, float timeout, + short unsigned int *ret_recSize, float *ret_timeout); /**************************************************************/ %} @@ -395,5 +408,12 @@ extern void changeBaud (int deviceID, unsigned int baudRate, float timeout, extern void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, unsigned int *OUTPUT, float *OUTPUT); +extern void startRec (int deviceID); + +extern void stopRec (int deviceID); + +extern void recSize (int deviceID, float timeout, + short unsigned int *OUTPUT, float *OUTPUT); + /**************************************************************/ /**************************************************************/ \ No newline at end of file From da6a9d380773e0b6353d7088de75dbfed09c8ea2 Mon Sep 17 00:00:00 2001 From: Shyam Date: Wed, 20 Sep 2017 18:32:36 +0530 Subject: [PATCH 35/50] Added test python files and results for REC_SIZE, START_REC and STOP_REC --- XSMU-2.4.0/wrapper/python/libxsmu.cxx | 2 - XSMU-2.4.0/wrapper/python/test/recSize.py | 51 ++ XSMU-2.4.0/wrapper/python/test/startRec.py | 50 ++ changeBaudTesting.md | 764 +++++++++++---------- 4 files changed, 509 insertions(+), 358 deletions(-) create mode 100644 XSMU-2.4.0/wrapper/python/test/recSize.py create mode 100644 XSMU-2.4.0/wrapper/python/test/startRec.py diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index 100dee1..93026c7 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -927,8 +927,6 @@ void recSize (int deviceID, float timeout, virtuaSMU->recSize (&recSize_, &timeout_); - *ret_recSize = 0; - if ((*ret_timeout = timeout_) == 0) return; diff --git a/XSMU-2.4.0/wrapper/python/test/recSize.py b/XSMU-2.4.0/wrapper/python/test/recSize.py new file mode 100644 index 0000000..2f5458c --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/recSize.py @@ -0,0 +1,51 @@ +import libxsmu, time, math, sys +from time import sleep + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +sleep (5) + +########################################################################## +# Queries the number of datapoints stored in standby data queue in SMU + +timeout = 5.0 + +recSize, timeout = libxsmu.recSize (deviceID, timeout) +print \ + "recSize: ", recSize, "\n" \ + "Timeout: ", timeout + +if (timeout == 0.0): + print 'Communication timeout in changeBaud' + exit (-2) + +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) diff --git a/XSMU-2.4.0/wrapper/python/test/startRec.py b/XSMU-2.4.0/wrapper/python/test/startRec.py new file mode 100644 index 0000000..ea1e5f3 --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/startRec.py @@ -0,0 +1,50 @@ +import libxsmu, time, math, sys +from time import sleep + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +sleep (5) + +########################################################################## +# Start recording streamed data from the SMU + +libxsmu.startRec (deviceID) +print \ + "Started Recording Streamed Data" + +sleep(5) + +libxsmu.stopRec (deviceID) +print \ + "Stopped Recording Streamed Data" + +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) diff --git a/changeBaudTesting.md b/changeBaudTesting.md index e5e1837..34efe72 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -133,12 +133,12 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll ++ std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; ++ std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; ++ std::cout << "virtuaSMU : AckBits Set" << std::endl; - + ^^ void Driver::changeBaud (uint32_t*, float*) ++ std::cout << "virtuaSMU : AckBits Reset" << std::endl; ++ std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; ++ std::cout << "virtuaSMU : Recieved Response" << std::endl; - + ^^ Comm.cxx ^^ void Comm::changeBaudCB (const void* data, uint16_t size) ++ std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; @@ -148,7 +148,7 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll ^^ void Comm::transmit_changeBaud (uint32_t baudRate) ++ std::cout << "Comm : QP4_Packet allocated" << std::endl; ++ std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; - + ^^ checkRecieveQueue() ++ std::cout << "Comm : Recieved Data Size : " << rxsize << std::endl; @@ -173,7 +173,7 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll --- - Added LCD print statements to firmware (Application.cxx) inside Application::changeBaudCB() function - + ``` freezeLocalDisplay(); lcd.cursorAt (0, 0); @@ -185,11 +185,11 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll const CommCB_changeBaud* o = reinterpret_cast (oCB); - + baudRate = o->baudRate(); appComm.transmit_changeBaud (baudRate); - - + + freezeLocalDisplay(); lcd.cursorAt (0, 0); lcd << " Transmitted "; @@ -210,9 +210,9 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll libxsmu version: 2.1.2 Hardware version: 4.0.0 Firmware version: 255.255.253 - Device ID : 0 - goodID : 1 - Remaining time: 0.887270927429 sec + Device ID : 0 + goodID : 1 + Remaining time: 0.887270927429 sec virtuaSMU : AckBits Reset Comm : QP4_Packet allocated @@ -224,7 +224,7 @@ The SMU is to stream voltmeter data at a specified frequency. This requires foll On LCD -> "Transmitted changeBaud" ``` - Baud Rate: 9600 + Baud Rate: 9600 Timeout: 0.0 Communication timeout in changeBaud ``` @@ -252,77 +252,77 @@ libxsmu version: 2.1.2 50 P 34 4 31 1 -0 +0 2C , F9 � 12  -0 +0 1  -0 -0 +0 +0 58 X 50 P 4C L 4F O 52 R 45 E -20 +20 53 S 4D M 55 U -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 4  -0 -0 +0 +0 FF � FF � FF � FD � Hardware version: 4.0.0 Firmware version: 255.255.253 -Device ID : 0 -goodID : 1 -Remaining time: 0.889459848404 sec +Device ID : 0 +goodID : 1 +Remaining time: 0.889459848404 sec 51 Q 50 P 34 4 31 1 -0 -8 +0 +8 FF � 30 0 -0 +0 2B + -0 -0 -0 -0 +0 +0 +0 +0 25 % 80 � -Baud Rate: 9600 +Baud Rate: 9600 Timeout: 0.0 Communication timeout in changeBaud ``` @@ -337,50 +337,50 @@ libxsmu version: 2.1.2 50 P 34 4 31 1 -0 +0 2C , F9 � 12  -0 +0 1  -0 -0 +0 +0 58 X 50 P 4C L 4F O 52 R 45 E -20 +20 53 S 4D M 55 U -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 4  -0 -0 +0 +0 FF � FF � FF � @@ -388,9 +388,9 @@ FD � void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 1 Hardware version: 4.0.0 Firmware version: 255.255.253 -Device ID : 0 -goodID : 1 -Remaining time: 0.882127046585 sec +Device ID : 0 +goodID : 1 +Remaining time: 0.882127046585 sec void smu::Comm::transmit_changeBaud(uint32_t):1393:Comm : QP4_Packet allocated void smu::Comm::transmit_changeBaud(uint32_t):1400:Comm : Packet Sealed and Transmitted @@ -398,22 +398,22 @@ void smu::Comm::transmit_changeBaud(uint32_t):1400:Comm : Packet Sealed and Tran 50 P 34 4 31 1 -0 -8 +0 +8 FF � 30 0 -0 +0 2B + -0 -0 -0 -0 +0 +0 +0 +0 25 % 80 � void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 43 void smu::Comm::changeBaudCB(const void*, uint16_t):746:Comm : Packet Size Okay void smu::Comm::changeBaudCB(const void*, uint16_t):752:Comm : Callback Completed -Baud Rate: 9600 +Baud Rate: 9600 Timeout: 0.0 Communication timeout in changeBaud ``` @@ -428,50 +428,50 @@ libxsmu version: 2.1.2 50 P 34 4 31 1 -0 +0 2C , F9 � 12  -0 +0 1  -0 -0 +0 +0 58 X 50 P 4C L 4F O 52 R 45 E -20 +20 53 S 4D M 55 U -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 4  -0 -0 +0 +0 FF � FF � FF � @@ -479,9 +479,9 @@ FD � void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 1 Hardware version: 4.0.0 Firmware version: 255.255.253 -Device ID : 0 -goodID : 1 -Remaining time: 0.884266853333 sec +Device ID : 0 +goodID : 1 +Remaining time: 0.884266853333 sec libxsmu changeBaud 9600 5 @@ -493,16 +493,16 @@ void smu::Driver::changeBaud(uint32_t*, float*):1247:virtuaSMU : Transmitted bau 50 P 34 4 31 1 -0 -8 +0 +8 FF � 30 0 -0 +0 2B + -0 -0 -0 -0 +0 +0 +0 +0 25 % 80 � void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 43 @@ -517,7 +517,7 @@ void smu::Comm::changeBaudCB(const void*, uint16_t):752:Comm : Callback Complete libxsmu timeout 9600 0 -Baud Rate: 9600 +Baud Rate: 9600 Timeout: 0.0 Communication timeout in changeBaud ``` @@ -533,50 +533,50 @@ libxsmu version: 2.1.2 50 P 34 4 31 1 -0 +0 2C , F9 � 12  -0 +0 1  -0 -0 +0 +0 58 X 50 P 4C L 4F O 52 R 45 E -20 +20 53 S 4D M 55 U -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 4  -0 -0 +0 +0 FF � FF � FF � @@ -584,9 +584,9 @@ FD � void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 1 Hardware version: 4.0.0 Firmware version: 255.255.253 -Device ID : 0 -goodID : 1 -Remaining time: 0.884332180023 sec +Device ID : 0 +goodID : 1 +Remaining time: 0.884332180023 sec libxsmu changeBaud 9600 5 void smu::Driver::changeBaud(uint32_t*, float*):1246:virtuaSMU : AckBits Reset @@ -597,16 +597,16 @@ void smu::Driver::changeBaud(uint32_t*, float*):1249:virtuaSMU : Transmitted bau 50 P 34 4 31 1 -0 -8 +0 +8 FF � 30 0 -0 +0 2B + -0 -0 -0 -0 +0 +0 +0 +0 25 % 80 � void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 43 @@ -617,7 +617,7 @@ void smu::Driver::changeBaudCB(const smu::CommCB*):590:virtuaSMU : AckBits Set void smu::Comm::changeBaudCB(const void*, uint16_t):752:Comm : Callback Completed void smu::Driver::changeBaud(uint32_t*, float*):1253:virtuaSMU : Recieved Response libxsmu success9600 4.91463 -Baud Rate: 9600 +Baud Rate: 9600 Timeout: 4.9146270752 ``` @@ -635,83 +635,83 @@ Timeout: 4.9146270752 50 P 34 4 31 1 - 0 + 0 2C , F9 � 12  - 0 + 0 1  - 0 - 0 + 0 + 0 58 X 50 P 4C L 4F O 52 R 45 E - 20 + 20 53 S 4D M 55 U - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 4  - 0 - 0 + 0 + 0 FF � FF � FF � FD � Hardware version: 4.0.0 Firmware version: 255.255.253 - Device ID : 0 - goodID : 1 - Remaining time: 0.849823951721 sec + Device ID : 0 + goodID : 1 + Remaining time: 0.849823951721 sec 51 Q 50 P 34 4 31 1 - 0 - 8 + 0 + 8 FF � C7 � - 0 + 0 2  - 0 - 0 - 0 - 0 + 0 + 0 + 0 + 0 27 ' 10  - Lease Time: 10000 + Lease Time: 10000 Timeout: 4.91435289383 ``` - - + + --- - + ### Testing for async thread calling keepAlive() and locking mechanism in Comm Added : - PRINT_DEBUG ("Asynch thread launched") in open() @@ -726,12 +726,12 @@ Added : Hardware version: 4.0.0 Firmware version: 255.255.253 void smu::Driver::open(const char*, float*):622:Asynch thread launched - Device ID : 0 - goodID : 1 - Remaining time: 0.869105100632 sec + Device ID : 0 + goodID : 1 + Remaining time: 0.869105100632 sec void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired - Lease Time: 10000 + Lease Time: 10000 Timeout: 4.89869022369 void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired void smu::Driver::thread():735:Inside thread : Keep Alive sent @@ -746,12 +746,12 @@ Added : Hardware version: 4.0.0 Firmware version: 255.255.253 void smu::Driver::open(const char*, float*):622:Asynch thread launched - Device ID : 0 - goodID : 1 - Remaining time: 0.869477987289 sec + Device ID : 0 + goodID : 1 + Remaining time: 0.869477987289 sec void smu::Driver::changeBaud(uint32_t*, float*):1373:Lock Acquired - Baud Rate: 9600 + Baud Rate: 9600 Timeout: 4.9146399498 void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired void smu::Driver::thread():735:Inside thread : Keep Alive sent @@ -765,12 +765,12 @@ Added : Hardware version: 4.0.0 Firmware version: 255.255.253 void smu::Driver::open(const char*, float*):622:Asynch thread launched - Device ID : 0 - goodID : 1 - Remaining time: 0.850958108902 sec + Device ID : 0 + goodID : 1 + Remaining time: 0.850958108902 sec void smu::Driver::VS_setVoltage(float*, float*):944:Lock Acquired - Voltage: 0.999929249287 + Voltage: 0.999929249287 Timeout: 4.91469097137 void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired void smu::Driver::thread():735:Inside thread : Keep Alive sent @@ -784,177 +784,177 @@ Added : Hardware version: 4.0.0 Firmware version: 255.255.253 void smu::Driver::open(const char*, float*):622:Asynch thread launched - Device ID : 0 - goodID : 1 - Remaining time: 0.870882987976 sec + Device ID : 0 + goodID : 1 + Remaining time: 0.870882987976 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.13914418221 sec + voltage : -0.101999998093 + Remaining time : 1.13914418221 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15525889397 sec + voltage : -0.101999998093 + Remaining time : 1.15525889397 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17055797577 sec + voltage : -0.101999998093 + Remaining time : 1.17055797577 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.1550321579 sec + voltage : -0.101999998093 + Remaining time : 1.1550321579 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17103505135 sec + voltage : -0.101999998093 + Remaining time : 1.17103505135 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20280408859 sec + voltage : -0.101999998093 + Remaining time : 1.20280408859 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15487217903 sec + voltage : -0.101999998093 + Remaining time : 1.15487217903 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17105913162 sec + voltage : -0.101999998093 + Remaining time : 1.17105913162 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20312213898 sec + voltage : -0.101999998093 + Remaining time : 1.20312213898 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20294713974 sec + voltage : -0.101999998093 + Remaining time : 1.20294713974 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15506291389 sec + voltage : -0.101999998093 + Remaining time : 1.15506291389 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.1709561348 sec + voltage : -0.101999998093 + Remaining time : 1.1709561348 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20299291611 sec + voltage : -0.101999998093 + Remaining time : 1.20299291611 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15482211113 sec + voltage : -0.101999998093 + Remaining time : 1.15482211113 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17106795311 sec + voltage : -0.101999998093 + Remaining time : 1.17106795311 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20310091972 sec + voltage : -0.101999998093 + Remaining time : 1.20310091972 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20291304588 sec + voltage : -0.101999998093 + Remaining time : 1.20291304588 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15489888191 sec + voltage : -0.101999998093 + Remaining time : 1.15489888191 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17089796066 sec + voltage : -0.101999998093 + Remaining time : 1.17089796066 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20286202431 sec + voltage : -0.101999998093 + Remaining time : 1.20286202431 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15500307083 sec + voltage : -0.101999998093 + Remaining time : 1.15500307083 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17052602768 sec + voltage : -0.101999998093 + Remaining time : 1.17052602768 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20300483704 sec + voltage : -0.101999998093 + Remaining time : 1.20300483704 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20285892487 sec + voltage : -0.101999998093 + Remaining time : 1.20285892487 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15503001213 sec + voltage : -0.101999998093 + Remaining time : 1.15503001213 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17059803009 sec + voltage : -0.101999998093 + Remaining time : 1.17059803009 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20324611664 sec + voltage : -0.101999998093 + Remaining time : 1.20324611664 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15489792824 sec + voltage : -0.101999998093 + Remaining time : 1.15489792824 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17091703415 sec + voltage : -0.101999998093 + Remaining time : 1.17091703415 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20329713821 sec + voltage : -0.101999998093 + Remaining time : 1.20329713821 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20329809189 sec + voltage : -0.101999998093 + Remaining time : 1.20329809189 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15476918221 sec + voltage : -0.101999998093 + Remaining time : 1.15476918221 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17097902298 sec + voltage : -0.101999998093 + Remaining time : 1.17097902298 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20291399956 sec + voltage : -0.101999998093 + Remaining time : 1.20291399956 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15500283241 sec + voltage : -0.101999998093 + Remaining time : 1.15500283241 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17109894753 sec + voltage : -0.101999998093 + Remaining time : 1.17109894753 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20278191566 sec + voltage : -0.101999998093 + Remaining time : 1.20278191566 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20280718803 sec + voltage : -0.101999998093 + Remaining time : 1.20280718803 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15464901924 sec + voltage : -0.101999998093 + Remaining time : 1.15464901924 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.17091703415 sec + voltage : -0.101999998093 + Remaining time : 1.17091703415 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.20296692848 sec + voltage : -0.101999998093 + Remaining time : 1.20296692848 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired - voltage : -0.101999998093 - Remaining time : 1.15501594543 sec + voltage : -0.101999998093 + Remaining time : 1.15501594543 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired ^CTraceback (most recent call last): @@ -975,13 +975,13 @@ libxsmu version: 2.1.2 Hardware version: 4.0.0 Firmware version: 255.255.253 void smu::Driver::open(const char*, float*):622:Async thread launched -Device ID : 0 -goodID : 1 -Remaining time: 0.832612991333 sec +Device ID : 0 +goodID : 1 +Remaining time: 0.832612991333 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1094:Lock Acquired -voltage : -2.67028808594e-05 -Remaining time : 1.18702793121 sec +voltage : -2.67028808594e-05 +Remaining time : 1.18702793121 sec void smu::Driver::keepAlive(uint32_t*, float*):718:Trying to Acquire Lock void smu::Driver::keepAlive(uint32_t*, float*):720:Lock Acquired @@ -989,7 +989,7 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent ``` - Added std::launch::async as argument to std::async to always set asynchronous operation of thread. - Fixed bug in `Driver::thread()` to convert ms into seconds for comparison inside while look -- Output : +- Output : ``` libxsmu version: 2.1.2 @@ -1000,8 +1000,8 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent Hardware version: 4.0.0 Firmware version: 255.255.253 void smu::Driver::open(const char*, float*):624:Async thread launched - Device ID : 0 - goodID : 1 + Device ID : 0 + goodID : 1 Remaining time: void smu::Driver::keepAlive(uint32_t*, float*)0.88267493248 sec : 721:Trying to Acquire Lock @@ -1010,87 +1010,87 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent void smu::Driver::thread():void smu::Driver::VM_read(uint16_t*, float*, float*):739:1098:Lock Acquired Inside thread : Keep Alive sent void smu::Driver::thread():743:Inside thread : Alive 139 - voltage : -2.47955322266e-05 - Remaining time : 1.17120504379 sec + voltage : -2.47955322266e-05 + Remaining time : 1.17120504379 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired - voltage : -2.86102294922e-05 - Remaining time : 1.17108106613 sec + voltage : -2.86102294922e-05 + Remaining time : 1.17108106613 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired - voltage : -2.86102294922e-05 - Remaining time : 1.15503096581 sec + voltage : -2.86102294922e-05 + Remaining time : 1.15503096581 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired void smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock - voltage : -2.67028808594e-05 - Remaining time : void smu::Driver::keepAlive(uint32_t*, float*)1.17121624947 sec + voltage : -2.67028808594e-05 + Remaining time : void smu::Driver::keepAlive(uint32_t*, float*)1.17121624947 sec :723:Lock Acquired void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::thread():751:Inside thread : Keep Alive sent void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired - voltage : -2.5749206543e-05 - Remaining time : 1.16077613831 sec + voltage : -2.5749206543e-05 + Remaining time : 1.16077613831 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired - voltage : -2.95639038086e-05 - Remaining time : 1.17108201981 sec + voltage : -2.95639038086e-05 + Remaining time : 1.17108201981 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired - voltage : -2.5749206543e-05 - Remaining time : 1.1545920372 sec + voltage : -2.5749206543e-05 + Remaining time : 1.1545920372 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired void smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock - voltage : void smu::Driver::keepAlive(uint32_t*, float*):-2.86102294922e-05723 + voltage : void smu::Driver::keepAlive(uint32_t*, float*):-2.86102294922e-05723 Remaining time ::Lock Acquired - 1.17104387283 sec + 1.17104387283 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::thread():751:Inside thread : Keep Alive sentvoid smu::Driver::VM_read(uint16_t*, float*, float*):1098: Lock Acquired - voltage : -2.5749206543e-05 - Remaining time : 1.16069293022 sec + voltage : -2.5749206543e-05 + Remaining time : 1.16069293022 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired - voltage : -2.67028808594e-05 - Remaining time : 1.17099499702 sec + voltage : -2.67028808594e-05 + Remaining time : 1.17099499702 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired - voltage : -2.67028808594e-05 - Remaining time : 1.15505194664 sec + voltage : -2.67028808594e-05 + Remaining time : 1.15505194664 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired void smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock - voltage : -2.47955322266e-05 - Remaining time : 1.1710100174 secvoid smu::Driver::keepAlive(uint32_t*, float*) + voltage : -2.47955322266e-05 + Remaining time : 1.1710100174 secvoid smu::Driver::keepAlive(uint32_t*, float*) :723:Lock Acquired void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::thread():751:Inside thread : Keep Alive sent void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired - voltage : -2.5749206543e-05 - Remaining time : 1.16075015068 sec + voltage : -2.5749206543e-05 + Remaining time : 1.16075015068 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired - voltage : -2.5749206543e-05 - Remaining time : 1.1713449955 sec + voltage : -2.5749206543e-05 + Remaining time : 1.1713449955 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired - voltage : -2.5749206543e-05 - Remaining time : 1.15498399734 sec + voltage : -2.5749206543e-05 + Remaining time : 1.15498399734 sec void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired @@ -1100,4 +1100,56 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent File "VM_getReading.py", line 40, in voltage, timeout = libxsmu.VM_getReading (deviceID, filter_length, timeout) KeyboardInterrupt + ``` + +--- +- Testing for REC_SIZE +- ``python wrapper/test/python/recSize.py` +- Output : + + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):632:Opening Device + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):658:Async thread launched + Device ID : 0 + goodID : 1 + Remaining time: 0.873402833939 sec + + void smu::Driver::keepAlive(uint32_t*, float*):755:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):757:Lock Acquired + void smu::Driver::recSize(uint16_t*, float*):1424:Lock Acquired + recSize: 0 + Timeout: 4.91455888748 + void smu::Driver::close():664:Closing Device + ``` +--- + +- Testing for START_REC and STOP_REC +- `python wrapper/test/python/startRec.py` +- Output : + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):632:Opening Device + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):658:Async thread launched + void smu::Driver::keepAlive(uint32_t*, float*)Device ID : :0 + goodID : 1 + Remaining time: 7550.869968891144:Trying to Acquire Lock sec + + + void smu::Driver::keepAlive(uint32_t*, float*):757:Lock Acquired + void smu::Driver::startRec():1472:REC : 1 + Started Recording Streamed Data + void smu::Driver::stopRec():1478:REC : 0 + Stopped Recording Streamed Data + void smu::Driver::close():664:Closing Device ``` \ No newline at end of file From d9333e2ba523c05015dec7c36e5d94e00288041a Mon Sep 17 00:00:00 2001 From: Shyam Date: Wed, 20 Sep 2017 19:18:18 +0530 Subject: [PATCH 36/50] Added python tesing interface, test file, and updated test results for REC_DATA --- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 29 +++++++++++++ XSMU-2.4.0/wrapper/python/libxsmu.cxx | 20 +++++++++ XSMU-2.4.0/wrapper/python/libxsmu.h | 13 +++++- XSMU-2.4.0/wrapper/python/libxsmu.i | 6 ++- XSMU-2.4.0/wrapper/python/test/recData.py | 51 +++++++++++++++++++++++ XSMU-2.4.0/wrapper/python/test/recSize.py | 2 +- changeBaudTesting.md | 30 +++++++++++++ 7 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 XSMU-2.4.0/wrapper/python/test/recData.py diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 1ddbae0..1a97b70 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -1404,6 +1404,11 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) /************************************************************************/ void Driver::changeBaud (uint32_t* baudRate, float* timeout) +/* + * Transmits a request for a change in the baudrate of communication + * channel; waits for acknowledgement of a change in baudrate in the + * firmware + */ { auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") @@ -1419,6 +1424,11 @@ void Driver::changeBaud (uint32_t* baudRate, float* timeout) /************************************************************************/ void Driver::recSize (uint16_t* recSize, float* timeout) +/* + * Transmits a request for the size of standby data queue stored in the + * SMU RAM, through the communication channel; and waits for a response + * within timeout duration. + */ { auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") @@ -1434,6 +1444,11 @@ void Driver::recSize (uint16_t* recSize, float* timeout) /************************************************************************/ void Driver::recData (uint16_t* recSize, float* timeout) +/* + * Transmits a request for data stored in the data queue in SMU RAM, + * through the communication channel; and waits for a response + * within timeout duration. + */ { auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") @@ -1450,6 +1465,12 @@ void Driver::recData (uint16_t* recSize, float* timeout) /************************************************************************/ std::vector Driver::getData (void) +/* + * Passes streamed data stored in the Driver to the Application layer. + * Data stored in the queue is cleared as it passed to the user. + * + * Output : std::vector + */ { std::vector data; @@ -1467,12 +1488,20 @@ std::vector Driver::getData (void) /************************************************************************/ void Driver::startRec (void) +/* + * Sets a flag to instruct the SMU to start streaming data, and the driver + * to start recording the streamed data. + */ { _rec = true; PRINT_DEBUG ("REC : " << _rec); } void Driver::stopRec (void) +/* + * Unsets a flag to instruct the SMU to stop streaming data, and the driver + * to stop recording. + */ { _rec = false; PRINT_DEBUG ("REC : " << _rec); diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index 93026c7..99d19ca 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -927,6 +927,26 @@ void recSize (int deviceID, float timeout, virtuaSMU->recSize (&recSize_, &timeout_); + *ret_recSize = 0; + + if ((*ret_timeout = timeout_) == 0) + return; + + *ret_recSize = recSize_; +} + +void recData (int deviceID, float timeout, + short unsigned int *ret_recSize, float *ret_timeout) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + short unsigned int recSize_; + float timeout_ = timeout; + + virtuaSMU->recData (&recSize_, &timeout_); + + *ret_recSize = 0; + if ((*ret_timeout = timeout_) == 0) return; diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.h b/XSMU-2.4.0/wrapper/python/libxsmu.h index fe7b255..998ab93 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.h +++ b/XSMU-2.4.0/wrapper/python/libxsmu.h @@ -280,7 +280,7 @@ void changeBaud (int deviceID, unsigned int baudRate, float timeout, * This function sets a flag in the driver, to start recording streamed data from the SMU. */ -void startRec (int deviceID); +//void startRec (int deviceID); /************************************************************************/ /** * \brief Stops recording streamed data from the SMU @@ -315,6 +315,17 @@ void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, void recSize (int deviceID, float timeout, short unsigned int *ret_recSize, float *ret_timeout); +/************************************************************************/ +/** + * \brief Queries the data in the standby data queue in the SMU + * + * \return Number of datapoints being transmitted by the SMU + * + */ + +void recData (int deviceID, float timeout, + short unsigned int *ret_recSize, float *ret_timeout); + /************************************************************************/ /************************************************************************/ #ifdef __cplusplus diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.i b/XSMU-2.4.0/wrapper/python/libxsmu.i index 9059fc1..75376f2 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.i +++ b/XSMU-2.4.0/wrapper/python/libxsmu.i @@ -225,6 +225,10 @@ extern void stopRec (int deviceID); extern void recSize (int deviceID, float timeout, short unsigned int *ret_recSize, float *ret_timeout); + +extern void recData (int deviceID, float timeout, + short unsigned int *ret_recSize, float *ret_timeout); + /**************************************************************/ %} @@ -412,7 +416,7 @@ extern void startRec (int deviceID); extern void stopRec (int deviceID); -extern void recSize (int deviceID, float timeout, +extern void recData (int deviceID, float timeout, short unsigned int *OUTPUT, float *OUTPUT); /**************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/test/recData.py b/XSMU-2.4.0/wrapper/python/test/recData.py new file mode 100644 index 0000000..8c4711f --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/recData.py @@ -0,0 +1,51 @@ +import libxsmu, time, math, sys +from time import sleep + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +sleep (5) + +########################################################################## +# Queries the number of datapoints stored in standby data queue in SMU + +timeout = 5.0 + +recSize, timeout = libxsmu.recData (deviceID, timeout) +print \ + "recSize: ", recSize, "\n" \ + "Timeout: ", timeout + +if (timeout == 0.0): + print 'Communication timeout in recData' + exit (-2) + +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) diff --git a/XSMU-2.4.0/wrapper/python/test/recSize.py b/XSMU-2.4.0/wrapper/python/test/recSize.py index 2f5458c..2a697ca 100644 --- a/XSMU-2.4.0/wrapper/python/test/recSize.py +++ b/XSMU-2.4.0/wrapper/python/test/recSize.py @@ -42,7 +42,7 @@ "Timeout: ", timeout if (timeout == 0.0): - print 'Communication timeout in changeBaud' + print 'Communication timeout in recSize' exit (-2) ########################################################################## diff --git a/changeBaudTesting.md b/changeBaudTesting.md index 34efe72..74cbe69 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -989,6 +989,7 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent ``` - Added std::launch::async as argument to std::async to always set asynchronous operation of thread. - Fixed bug in `Driver::thread()` to convert ms into seconds for comparison inside while look +- Result : Passed - Output : ``` @@ -1105,6 +1106,7 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent --- - Testing for REC_SIZE - ``python wrapper/test/python/recSize.py` +- Result : Passed - Output : ``` @@ -1131,6 +1133,7 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent - Testing for START_REC and STOP_REC - `python wrapper/test/python/startRec.py` +- Result : Passed - Output : ``` libxsmu version: 2.1.2 @@ -1152,4 +1155,31 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent void smu::Driver::stopRec():1478:REC : 0 Stopped Recording Streamed Data void smu::Driver::close():664:Closing Device + ``` +--- + +- Testing for REC_DATA +- `python wrapper/test` +- Result : Failed +- Output : + + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):632:Opening Device + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):658:Async thread launched + Device ID : 0 + goodID : 1void smu::Driver::keepAlive(uint32_t*, float*):755:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*) + Remaining time: :757:0.866751909256Lock Acquired + sec + + void smu::Driver::recData(uint16_t*, float*):1454:Lock Acquired + recSize: 0 + Timeout: 0.0 + Communication timeout in recData ``` \ No newline at end of file From 03bf56c81b2deff1e7ae938db14508bbb91e2ee8 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Thu, 21 Sep 2017 12:56:35 +0530 Subject: [PATCH 37/50] Converted array to std::vector in CommCB_resData, added apply calibration dummy function --- XSMU-2.4.0/code/app/app/Comm.h | 23 +++++++++-------------- XSMU-2.4.0/code/app/app/virtuaSMU.h | 11 +++++++++-- XSMU-2.4.0/code/app/src/Comm.cxx | 20 +++++++++++++++++--- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 26 +++++++++++++++++++++----- 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index c5439e8..764598a 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -1652,12 +1652,12 @@ class CommPacket_recData : public CommPacket class CommRequest_recData : public CommPacket_recData { public: - CommRequest_recData (uint16_t recSize) : - recSize_ (smu::hton (recSize)) + CommRequest_recData (uint16_t size) : + size_ (smu::hton (size)) {} private: - uint16_t recSize_; + uint16_t size_; }; class CommResponse_recData : public CommPacket_recData @@ -1668,19 +1668,14 @@ class CommResponse_recData : public CommPacket_recData public: uint16_t size (void) const {return smu::ntoh(size_);} - int32_t * recData (void) const + int32_t recData (uint16_t idx) const { - for (uint16_t i = 0; i < size_; ++i) - { - recData_[i] = smu::ntoh(recData_[i]); - } - - return (recData_); + return smu::ntoh(recData_[idx]); } private: uint16_t size_; - mutable int32_t recData_[]; + int32_t recData_[]; }; /************************************************************************/ @@ -2517,7 +2512,7 @@ class CommCB_recSize : public CommCB class CommCB_recData : public CommCB { public: - CommCB_recData (uint16_t size, int32_t *recData) : + CommCB_recData (uint16_t size, std::vector recData) : CommCB (COMM_CBCODE_REC_DATA), size_ (size), recData_ (recData) @@ -2526,11 +2521,11 @@ class CommCB_recData : public CommCB public: uint16_t size (void) const {return size_;} - int32_t *recData (void) const {return recData_;} + std::vector recData (void) const {return recData_;} private: uint16_t size_; - int32_t *recData_; + std::vector recData_; }; /************************************************************************/ diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index 3a024d6..cf65f10 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -268,8 +268,12 @@ class Driver { private: - uint16_t recSize_; //Stores size of available data with FW - std::queue _dataq; //Stores data obtained from FW + uint16_t recSize_; //Stores size of available data with FW + std::queue _dataq_32; //Stores ADC data obtained from FW + + //Stores ADC data converted to float using calibration table + std::queue _dataq; + std::mutex _dataq_lock; public: @@ -279,6 +283,9 @@ class Driver { private: bool _rec; + +private: + float applyCalibration (int32_t adc_value); }; /************************************************************************/ diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index a625dc3..69be1b4 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -4,6 +4,7 @@ #include #include #include +#include #define PRINT_DEBUG(x) { \ std::cerr << __PRETTY_FUNCTION__ << ":" << __LINE__ << ":" << x << std::endl; } @@ -789,8 +790,17 @@ void Comm::recDataCB (const void* data, uint16_t size) const CommResponse_recData* res = reinterpret_cast (data); + //Construct a std::vector from the recieved data array + uint16_t n = res->size(); + std::vector recData (n); + + for (uint16_t i = 0; i < n; ++i) + { + recData.push_back (res->recData(i)); + } + do_callback (new (&callbackObject_) - CommCB_recData (res->size(), res->recData())); + CommCB_recData (n, recData)); } /************************************************************************/ /************************************************************************/ @@ -1466,14 +1476,18 @@ void Comm::transmit_recSize (void) /************************************************************************/ -void Comm::transmit_recData (uint16_t recSize) +void Comm::transmit_recData (uint16_t size) +/* + * Creates and transmits a CommRequest_recData packet, requesting for + * 'size' number of datapoints of recorded data to be transmitted + */ { QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_recData)); new (req->body()) - CommRequest_recData (recSize); + CommRequest_recData (size); req->seal(); transmit (req); diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 1a97b70..06aac1f 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -612,13 +612,14 @@ void Driver::recDataCB (const CommCB* oCB) reinterpret_cast (oCB); uint16_t size = o->size(); //Size of data sent in this packet - const int32_t* data = o->recData(); //Pointer to data in this packet + std::vector data = o->recData(); //Data in this packet std::lock_guard lock(_dataq_lock); for (uint16_t i = 0; i < size; ++i) { - _dataq.push(data[i]); + _dataq_32.push (data[i]); + _dataq.push (applyCalibration (data[i])); } ackBits_.set (COMM_CBCODE_REC_DATA); @@ -1443,7 +1444,7 @@ void Driver::recSize (uint16_t* recSize, float* timeout) /************************************************************************/ -void Driver::recData (uint16_t* recSize, float* timeout) +void Driver::recData (uint16_t* size, float* timeout) /* * Transmits a request for data stored in the data queue in SMU RAM, * through the communication channel; and waits for a response @@ -1455,9 +1456,11 @@ void Driver::recData (uint16_t* recSize, float* timeout) ackBits_.reset (COMM_CBCODE_REC_DATA); - *recSize = recSize_; + // Assuming that size of stored data is already stored in recSize_ + // Always call recSize() before recData() (in thread()) + *size = recSize_; - comm_->transmit_recData (*recSize); + comm_->transmit_recData (*size); waitForResponse (COMM_CBCODE_REC_DATA, timeout); } @@ -1480,6 +1483,7 @@ std::vector Driver::getData (void) { data.push_back(_dataq.front()); _dataq.pop(); + _dataq_32.pop(); } return data; @@ -1507,6 +1511,18 @@ void Driver::stopRec (void) PRINT_DEBUG ("REC : " << _rec); } +/************************************************************************/ + +float Driver::applyCalibration (int32_t adc_value) +/* + * Applys the calibration table (depending upon what physical quantity is + * being measured, and the range for the same; eg. current, 100uA range) + * to convert an ADC value into a voltage or current value + */ +{ + return float (adc_value); +} + /************************************************************************/ /************************************************************************/ } From 390b96e259d48bb845e8133c27ce163554f3521c Mon Sep 17 00:00:00 2001 From: Shyam Date: Thu, 21 Sep 2017 14:56:34 +0530 Subject: [PATCH 38/50] Added test results for recData, added missing declaration in libxsmu.i --- XSMU-2.4.0/code/app/src/Comm.cxx | 2 +- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 1 + XSMU-2.4.0/wrapper/python/libxsmu.cxx | 10 +- XSMU-2.4.0/wrapper/python/libxsmu.h | 2 +- XSMU-2.4.0/wrapper/python/libxsmu.i | 5 +- XSMU-2.4.0/wrapper/python/test/recData.py | 4 +- changeBaudTesting.md | 113 ++++++++++++++++++++++ 7 files changed, 127 insertions(+), 10 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 69be1b4..258d40b 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -169,7 +169,7 @@ void Comm::processReceivedData (const void* data, uint16_t size) if (size) do { - //std::printf ("%X %c\n", static_cast (*src), *src); + std::printf ("%X %c\n", static_cast (*src), *src); qp4_->receiver().push_back (*src++); if (qp4_->receiver().ready()) { diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 06aac1f..744bc02 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -1461,6 +1461,7 @@ void Driver::recData (uint16_t* size, float* timeout) *size = recSize_; comm_->transmit_recData (*size); + PRINT_DEBUG ("Successfully transmitted, waiting for response") waitForResponse (COMM_CBCODE_REC_DATA, timeout); } diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index 99d19ca..01c6140 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -936,21 +936,21 @@ void recSize (int deviceID, float timeout, } void recData (int deviceID, float timeout, - short unsigned int *ret_recSize, float *ret_timeout) + short unsigned int *ret_size, float *ret_timeout) { VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; - short unsigned int recSize_; + short unsigned int size_; float timeout_ = timeout; - virtuaSMU->recData (&recSize_, &timeout_); + virtuaSMU->recData (&size_, &timeout_); - *ret_recSize = 0; + *ret_size = 0; if ((*ret_timeout = timeout_) == 0) return; - *ret_recSize = recSize_; + *ret_size = size_; } /************************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.h b/XSMU-2.4.0/wrapper/python/libxsmu.h index 998ab93..d0e6b47 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.h +++ b/XSMU-2.4.0/wrapper/python/libxsmu.h @@ -324,7 +324,7 @@ void recSize (int deviceID, float timeout, */ void recData (int deviceID, float timeout, - short unsigned int *ret_recSize, float *ret_timeout); + short unsigned int *ret_size, float *ret_timeout); /************************************************************************/ /************************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.i b/XSMU-2.4.0/wrapper/python/libxsmu.i index 75376f2..9ec42c6 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.i +++ b/XSMU-2.4.0/wrapper/python/libxsmu.i @@ -227,7 +227,7 @@ extern void recSize (int deviceID, float timeout, short unsigned int *ret_recSize, float *ret_timeout); extern void recData (int deviceID, float timeout, - short unsigned int *ret_recSize, float *ret_timeout); + short unsigned int *ret_size, float *ret_timeout); /**************************************************************/ @@ -416,6 +416,9 @@ extern void startRec (int deviceID); extern void stopRec (int deviceID); +extern void recSize (int deviceID, float timeout, + short unsigned int *OUTPUT, float *OUTPUT); + extern void recData (int deviceID, float timeout, short unsigned int *OUTPUT, float *OUTPUT); diff --git a/XSMU-2.4.0/wrapper/python/test/recData.py b/XSMU-2.4.0/wrapper/python/test/recData.py index 8c4711f..c4bafb8 100644 --- a/XSMU-2.4.0/wrapper/python/test/recData.py +++ b/XSMU-2.4.0/wrapper/python/test/recData.py @@ -32,9 +32,9 @@ sleep (5) ########################################################################## -# Queries the number of datapoints stored in standby data queue in SMU +# Queries the data stored in standby data queue in SMU -timeout = 5.0 +timeout = 10.0 recSize, timeout = libxsmu.recData (deviceID, timeout) print \ diff --git a/changeBaudTesting.md b/changeBaudTesting.md index 74cbe69..c225b6f 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -1182,4 +1182,117 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent recSize: 0 Timeout: 0.0 Communication timeout in recData + ``` + +- Added Opcode print statements, no opcodes shown for recData means that bug is in firmware (no data being transmitted from FW) +- Added lcd print statements to recDataCB in Application.h in FW. (Are not printed) +- Result : Failed +- Output : + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):633:Opening Device + libxsmu version: 2.1.2 + 51 Q + 50 P + 34 4 + 31 1 + 0 + 2C , + F9 � + 12  + 0 + 1  + 0 + 0 + 58 X + 50 P + 4C L + 4F O + 52 R + 45 E + 20 + 53 S + 4D M + 55 U + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4  + 0 + 0 + FF � + FF � + FF � + FD � + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):659:Async thread launched + Device ID : 0 + goodID : void smu::Driver::keepAlive(uint32_t*, float*)1 : + Remaining time: 756:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):758:Lock Acquired + 0.883061885834 sec + + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::keepAlive(uint32_t*, float*):756:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):758:Lock Acquired + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::recData(uint16_t*, float*):1455:Lock Acquired + void smu::Driver::recData(uint16_t*, float*):1464:Successfully transmitted, waiting for response + void smu::Driver::keepAlive(uint32_t*, float*):756:Trying to Acquire Lock + recSize: void smu::Driver::keepAlive(uint32_t*, float*)0 + Timeout: 0.0: + 758:Lock AcquiredCommunication timeout in recData ``` \ No newline at end of file From cd664326851353b79721f643fc6a33fb88db8061 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Thu, 21 Sep 2017 15:23:42 +0530 Subject: [PATCH 39/50] Added missing reserve_ in recSize and recData --- XSMU-2.4.0/code/app/app/Comm.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index 764598a..a51306a 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -1637,6 +1637,7 @@ class CommResponse_recSize : public CommPacket_recSize private: uint16_t recSize_; + uint16_t recData_; }; /************************************************************************/ @@ -1653,11 +1654,13 @@ class CommRequest_recData : public CommPacket_recData { public: CommRequest_recData (uint16_t size) : - size_ (smu::hton (size)) + size_ (smu::hton (size)), + reserve_ (0) {} private: uint16_t size_; + uint16_t reserve_; }; class CommResponse_recData : public CommPacket_recData @@ -1675,6 +1678,7 @@ class CommResponse_recData : public CommPacket_recData private: uint16_t size_; + uint16_t reserve_; int32_t recData_[]; }; From b8ddd3a10d20c9d46c791dc379680d5d0b563758 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Thu, 21 Sep 2017 15:45:30 +0530 Subject: [PATCH 40/50] Modified recData to take size as input from python --- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 4 ---- XSMU-2.4.0/wrapper/python/libxsmu.cxx | 4 ++-- XSMU-2.4.0/wrapper/python/libxsmu.h | 2 +- XSMU-2.4.0/wrapper/python/libxsmu.i | 4 ++-- XSMU-2.4.0/wrapper/python/test/recData.py | 3 ++- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 744bc02..65ecce4 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -1456,10 +1456,6 @@ void Driver::recData (uint16_t* size, float* timeout) ackBits_.reset (COMM_CBCODE_REC_DATA); - // Assuming that size of stored data is already stored in recSize_ - // Always call recSize() before recData() (in thread()) - *size = recSize_; - comm_->transmit_recData (*size); PRINT_DEBUG ("Successfully transmitted, waiting for response") diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index 01c6140..0eb5195 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -935,12 +935,12 @@ void recSize (int deviceID, float timeout, *ret_recSize = recSize_; } -void recData (int deviceID, float timeout, +void recData (int deviceID, short unsigned int size, float timeout, short unsigned int *ret_size, float *ret_timeout) { VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; - short unsigned int size_; + short unsigned int size_ = size; float timeout_ = timeout; virtuaSMU->recData (&size_, &timeout_); diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.h b/XSMU-2.4.0/wrapper/python/libxsmu.h index d0e6b47..98d8a7d 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.h +++ b/XSMU-2.4.0/wrapper/python/libxsmu.h @@ -323,7 +323,7 @@ void recSize (int deviceID, float timeout, * */ -void recData (int deviceID, float timeout, +void recData (int deviceID, short unsigned int size, float timeout, short unsigned int *ret_size, float *ret_timeout); /************************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.i b/XSMU-2.4.0/wrapper/python/libxsmu.i index 9ec42c6..f9e235b 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.i +++ b/XSMU-2.4.0/wrapper/python/libxsmu.i @@ -226,7 +226,7 @@ extern void stopRec (int deviceID); extern void recSize (int deviceID, float timeout, short unsigned int *ret_recSize, float *ret_timeout); -extern void recData (int deviceID, float timeout, +extern void recData (int deviceID, short unsigned int size, float timeout, short unsigned int *ret_size, float *ret_timeout); /**************************************************************/ @@ -419,7 +419,7 @@ extern void stopRec (int deviceID); extern void recSize (int deviceID, float timeout, short unsigned int *OUTPUT, float *OUTPUT); -extern void recData (int deviceID, float timeout, +extern void recData (int deviceID, short unsigned int size, float timeout, short unsigned int *OUTPUT, float *OUTPUT); /**************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/test/recData.py b/XSMU-2.4.0/wrapper/python/test/recData.py index c4bafb8..c4cb259 100644 --- a/XSMU-2.4.0/wrapper/python/test/recData.py +++ b/XSMU-2.4.0/wrapper/python/test/recData.py @@ -35,8 +35,9 @@ # Queries the data stored in standby data queue in SMU timeout = 10.0 +size = 1 -recSize, timeout = libxsmu.recData (deviceID, timeout) +recSize, timeout = libxsmu.recData (deviceID, size, timeout) print \ "recSize: ", recSize, "\n" \ "Timeout: ", timeout From 14f957a3e1d4439c4b9801b365e0d460d702e5e6 Mon Sep 17 00:00:00 2001 From: Shyam Date: Thu, 21 Sep 2017 16:07:44 +0530 Subject: [PATCH 41/50] Added print debug statements for recData --- XSMU-2.4.0/code/app/src/Comm.cxx | 9 +++++++++ XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 258d40b..3168dcd 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -784,8 +784,15 @@ void Comm::recSizeCB (const void* data, uint16_t size) void Comm::recDataCB (const void* data, uint16_t size) { + PRINT_DEBUG ("Size : " << size << "Expected : " << sizeof(CommRequest_recData)) + if (size < sizeof (CommResponse_recData)) + { + PRINT_DEBUG ("SIZE NOT OKAY") return; + } + + PRINT_DEBUG ("SIZE OKAY") const CommResponse_recData* res = reinterpret_cast (data); @@ -799,6 +806,8 @@ void Comm::recDataCB (const void* data, uint16_t size) recData.push_back (res->recData(i)); } + PRINT_DEBUG ("VECTOR CONSTRUCTED") + do_callback (new (&callbackObject_) CommCB_recData (n, recData)); } diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 65ecce4..1df7ff7 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -608,12 +608,15 @@ void Driver::recSizeCB (const CommCB* oCB) void Driver::recDataCB (const CommCB* oCB) { + PRINT_DEBUG ("CB started") + const CommCB_recData* o = reinterpret_cast (oCB); uint16_t size = o->size(); //Size of data sent in this packet std::vector data = o->recData(); //Data in this packet + PRINT_DEBUG ("Trying to acquire dataq lock") std::lock_guard lock(_dataq_lock); for (uint16_t i = 0; i < size; ++i) @@ -622,6 +625,8 @@ void Driver::recDataCB (const CommCB* oCB) _dataq.push (applyCalibration (data[i])); } + PRINT_DEBUG ("Written to dataq") + ackBits_.set (COMM_CBCODE_REC_DATA); } From 9d414d33be5059918cc370c26e7889a6f883961e Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Thu, 21 Sep 2017 17:17:24 +0530 Subject: [PATCH 42/50] Added StartRec and StopRec functions, all the way to firmware --- XSMU-2.4.0/code/app/app/Comm.h | 77 +++++++++++++++++++++- XSMU-2.4.0/code/app/app/virtuaSMU.h | 10 +-- XSMU-2.4.0/code/app/src/Comm.cxx | 62 ++++++++++++++++- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 46 +++++++++++-- XSMU-2.4.0/wrapper/python/libxsmu.cxx | 18 +++-- XSMU-2.4.0/wrapper/python/libxsmu.h | 8 ++- XSMU-2.4.0/wrapper/python/libxsmu.i | 12 ++-- XSMU-2.4.0/wrapper/python/test/startRec.py | 7 +- 8 files changed, 213 insertions(+), 27 deletions(-) diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index a51306a..e984b98 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -69,6 +69,8 @@ enum Comm_Opcode COMM_OPCODE_CHANGE_BAUD, //43 COMM_OPCODE_REC_SIZE, //44 COMM_OPCODE_REC_DATA, //45 + COMM_OPCODE_START_REC, //46 + COMM_OPCODE_STOP_REC, //47 }; enum Comm_SourceMode @@ -1682,6 +1684,50 @@ class CommResponse_recData : public CommPacket_recData int32_t recData_[]; }; +/************************************************************************/ + +class CommPacket_StartRec : public CommPacket +{ +protected: + CommPacket_StartRec (void) : + CommPacket (COMM_OPCODE_START_REC) + {} +}; + +class CommRequest_StartRec : public CommPacket_StartRec +{ +public: + CommRequest_StartRec (void) {} +}; + +class CommResponse_StartRec : public CommPacket_StartRec +{ +private: + CommResponse_StartRec (void); +}; + +/************************************************************************/ + +class CommPacket_StopRec : public CommPacket +{ +protected: + CommPacket_StopRec (void) : + CommPacket (COMM_OPCODE_STOP_REC) + {} +}; + +class CommRequest_StopRec : public CommPacket_StopRec +{ +public: + CommRequest_StopRec (void) {} +}; + +class CommResponse_StopRec : public CommPacket_StopRec +{ +private: + CommResponse_StopRec (void); +}; + /************************************************************************/ /************************************************************************/ @@ -1744,6 +1790,8 @@ enum Comm_CallbackCode COMM_CBCODE_CHANGE_BAUD, //43 COMM_CBCODE_REC_SIZE, //44 COMM_CBCODE_REC_DATA, //45 + COMM_CBCODE_START_REC, //46 + COMM_CBCODE_STOP_REC, //47 }; /************************************************************************/ @@ -2532,6 +2580,25 @@ class CommCB_recData : public CommCB std::vector recData_; }; +/************************************************************************/ + +class CommCB_StartRec : public CommCB +{ +public: + CommCB_StartRec (void) : + CommCB (COMM_CBCODE_START_REC) + {} +}; + +/************************************************************************/ + +class CommCB_StopRec : public CommCB +{ +public: + CommCB_StopRec (void) : + CommCB (COMM_CBCODE_STOP_REC) + {} +}; /************************************************************************/ /************************************************************************/ @@ -2544,6 +2611,8 @@ union CommCB_Union char gen4[sizeof (CommCB_changeBaud)]; char gen5[sizeof (CommCB_recSize)]; char gen6[sizeof (CommCB_recData)]; + char gen7[sizeof (CommCB_StartRec)]; + char gen8[sizeof (CommCB_StopRec)]; char cs0[sizeof (CommCB_CS_SetRange)]; char cs1[sizeof (CommCB_CS_GetCalibration)]; @@ -2686,6 +2755,8 @@ class Comm : public Applet void transmit_changeBaud (uint32_t baudRate); void transmit_recSize (void); void transmit_recData (uint16_t recSize); + void transmit_StartRec (void); + void transmit_StopRec (void); private: QP4* qp4_; @@ -2754,8 +2825,10 @@ class Comm : public Applet void changeBaudCB (const void* data, uint16_t size); - void recSizeCB (const void* data, uint16_t size); - void recDataCB (const void* data, uint16_t size); + void recSizeCB (const void* data, uint16_t size); + void recDataCB (const void* data, uint16_t size); + void StartRecCB (const void* data, uint16_t size); + void StopRecCB (const void* data, uint16_t size); private: void transmit (const QP4_Packet* packet); diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index cf65f10..ecb64b6 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -173,8 +173,10 @@ class Driver { void changeBaud (uint32_t* baudRate, float* timeout); - void recSize (uint16_t* recSize, float* timeout); - void recData (uint16_t* size, float* timeout); + void recSize (uint16_t* recSize, float* timeout); + void recData (uint16_t* size, float* timeout); + void StartRec (float* timeout); + void StopRec (float* timeout); /***************************************************/ public: @@ -247,6 +249,8 @@ class Driver { void changeBaudCB (const CommCB* oCB); void recSizeCB (const CommCB* oCB); void recDataCB (const CommCB* oCB); + void StartRecCB (const CommCB* oCB); + void StopRecCB (const CommCB* oCB); private: Comm* comm_; @@ -278,8 +282,6 @@ class Driver { public: std::vector getData (void); - void startRec (void); - void stopRec (void); private: bool _rec; diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 3168dcd..1822b67 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -246,6 +246,8 @@ void Comm::interpret (const void* data, uint16_t size) &Comm::changeBaudCB, &Comm::recSizeCB, &Comm::recDataCB, + &Comm::StartRecCB, + &Comm::StopRecCB, }; if (size < sizeof (CommPacket)) @@ -254,8 +256,6 @@ void Comm::interpret (const void* data, uint16_t size) const CommPacket *packet = reinterpret_cast (data); - //PRINT_DEBUG ("Opcode: " << packet->opcode()); - if (packet->opcode() < sizeof (cbs) / sizeof (cbs[0])) (this->*cbs[packet->opcode()])(data, size); } @@ -745,7 +745,6 @@ void Comm::VM_setTerminalCB (const void* data, uint16_t size) CommCB_VM_SetTerminal (res->terminal())); } - void Comm::VM_getTerminalCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_VM_GetTerminal)) @@ -758,6 +757,8 @@ void Comm::VM_getTerminalCB (const void* data, uint16_t size) CommCB_VM_GetTerminal (res->terminal())); } +/************************************************************************/ + void Comm::changeBaudCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_changeBaud)) @@ -782,6 +783,8 @@ void Comm::recSizeCB (const void* data, uint16_t size) CommCB_recSize (res->recSize())); } +/************************************************************************/ + void Comm::recDataCB (const void* data, uint16_t size) { PRINT_DEBUG ("Size : " << size << "Expected : " << sizeof(CommRequest_recData)) @@ -811,6 +814,27 @@ void Comm::recDataCB (const void* data, uint16_t size) do_callback (new (&callbackObject_) CommCB_recData (n, recData)); } + +/************************************************************************/ + +void Comm::StartRecCB (const void* data, uint16_t size) +{ + if (size < sizeof (CommResponse_StartRec)) + return; + + do_callback (new (&callbackObject_) CommCB_StartRec); +} + +/************************************************************************/ + +void Comm::StopRecCB (const void* data, uint16_t size) +{ + if (size < sizeof (CommResponse_StopRec)) + return; + + do_callback (new (&callbackObject_) CommCB_StopRec); +} + /************************************************************************/ /************************************************************************/ @@ -1504,6 +1528,38 @@ void Comm::transmit_recData (uint16_t size) qp4_->transmitter().free_packet (req); } +/************************************************************************/ + +void Comm::transmit_StartRec (void) +{ + QP4_Packet* req = + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_StartRec)); + + new (req->body()) + CommRequest_StartRec; + + req->seal(); + transmit (req); + qp4_->transmitter().free_packet (req); +} + +/************************************************************************/ + +void Comm::transmit_StopRec (void) +{ + QP4_Packet* req = + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_StopRec)); + + new (req->body()) + CommRequest_StopRec; + + req->seal(); + transmit (req); + qp4_->transmitter().free_packet (req); +} + /************************************************************************/ /************************************************************************/ } // namespace smu diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 1df7ff7..0c6b071 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -141,6 +141,8 @@ void Driver::comm_cb (const CommCB* oCB) &Driver::changeBaudCB, &Driver::recSizeCB, &Driver::recDataCB, + &Driver::StartRecCB, + &Driver::StopRecCB, }; if (oCB->code() < sizeof (cbs) / sizeof (cbs[0])) @@ -630,6 +632,18 @@ void Driver::recDataCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_REC_DATA); } +/************************************************************************/ + +void Driver::StartRecCB (const CommCB* oCB) +{ + ackBits_.set (COMM_CBCODE_START_REC); +} + +void Driver::StopRecCB (const CommCB* oCB) +{ + ackBits_.set (COMM_CBCODE_STOP_REC); +} + /************************************************************************/ /************************************************************************/ @@ -1493,24 +1507,44 @@ std::vector Driver::getData (void) /************************************************************************/ -void Driver::startRec (void) +void Driver::StartRec (float *timeout) /* * Sets a flag to instruct the SMU to start streaming data, and the driver - * to start recording the streamed data. + * to start recording the streamed data. Then instructs the firmware to + * start streaming data from the ADC */ { _rec = true; - PRINT_DEBUG ("REC : " << _rec); + + auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") + + ackBits_.reset (COMM_CBCODE_START_REC); + + comm_->transmit_StartRec(); + PRINT_DEBUG ("Successfully transmitted, waiting for response") + + waitForResponse (COMM_CBCODE_START_REC, timeout); } -void Driver::stopRec (void) +void Driver::StopRec (float *timeout) /* * Unsets a flag to instruct the SMU to stop streaming data, and the driver - * to stop recording. + * to stop recording. Then instructs the firmware to stop streaming data + * from the ADC */ { _rec = false; - PRINT_DEBUG ("REC : " << _rec); + + auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") + + ackBits_.reset (COMM_CBCODE_STOP_REC); + + comm_->transmit_StopRec(); + PRINT_DEBUG ("Successfully transmitted, waiting for response") + + waitForResponse (COMM_CBCODE_STOP_REC, timeout); } /************************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index 0eb5195..ba6e826 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -884,16 +884,26 @@ void changeBaud (int deviceID, unsigned int baudRate, float timeout, // *ret_data = data_; // } -void startRec (int deviceID) +void StartRec (int deviceID, float timeout, + float *ret_timeout) { VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; - virtuaSMU->startRec(); + + float timeout_ = timeout; + virtuaSMU->StartRec(&timeout_); + + *ret_timeout = timeout_; } -void stopRec (int deviceID) +void StopRec (int deviceID, float timeout, + float *ret_timeout) { VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; - virtuaSMU->stopRec(); + + float timeout_ = timeout; + virtuaSMU->StopRec(&timeout_); + + *ret_timeout = timeout_; } /************************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.h b/XSMU-2.4.0/wrapper/python/libxsmu.h index 98d8a7d..1127cd0 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.h +++ b/XSMU-2.4.0/wrapper/python/libxsmu.h @@ -259,6 +259,7 @@ void VM_getTerminal(int deviceID, float timeout, void changeBaud (int deviceID, unsigned int baudRate, float timeout, unsigned int *ret_baudRate, float *ret_timeout); + /************************************************************************/ /** * \brief Gets data streamed from the SMU. @@ -280,7 +281,9 @@ void changeBaud (int deviceID, unsigned int baudRate, float timeout, * This function sets a flag in the driver, to start recording streamed data from the SMU. */ -//void startRec (int deviceID); +void StartRec (int deviceID, float timeout, + float *ret_timeout); + /************************************************************************/ /** * \brief Stops recording streamed data from the SMU @@ -290,7 +293,8 @@ void changeBaud (int deviceID, unsigned int baudRate, float timeout, * This function unsets a flag in the driver, to stop recording streamed data from the SMU. */ -void stopRec (int deviceID); +void StopRec (int deviceID, float timeout, + float *ret_timeout); /************************************************************************/ /** diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.i b/XSMU-2.4.0/wrapper/python/libxsmu.i index f9e235b..1658d44 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.i +++ b/XSMU-2.4.0/wrapper/python/libxsmu.i @@ -219,9 +219,11 @@ extern void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, unsigned int *ret_lease_time_ms, float *ret_timeout); -extern void startRec (int deviceID); +extern void StartRec (int deviceID, float timeout, + float *ret_timeout); -extern void stopRec (int deviceID); +extern void StopRec (int deviceID, float timeout, + float *ret_timeout); extern void recSize (int deviceID, float timeout, short unsigned int *ret_recSize, float *ret_timeout); @@ -412,9 +414,11 @@ extern void changeBaud (int deviceID, unsigned int baudRate, float timeout, extern void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, unsigned int *OUTPUT, float *OUTPUT); -extern void startRec (int deviceID); +extern void StartRec (int deviceID, float timeout, + float *OUTPUT); -extern void stopRec (int deviceID); +extern void StopRec (int deviceID, float timeout, + float *OUTPUT); extern void recSize (int deviceID, float timeout, short unsigned int *OUTPUT, float *OUTPUT); diff --git a/XSMU-2.4.0/wrapper/python/test/startRec.py b/XSMU-2.4.0/wrapper/python/test/startRec.py index ea1e5f3..dbdea74 100644 --- a/XSMU-2.4.0/wrapper/python/test/startRec.py +++ b/XSMU-2.4.0/wrapper/python/test/startRec.py @@ -34,13 +34,16 @@ ########################################################################## # Start recording streamed data from the SMU -libxsmu.startRec (deviceID) +timeout = 5 + +timeout = libxsmu.StartRec (deviceID, timeout) print \ "Started Recording Streamed Data" sleep(5) +timeout = 5 -libxsmu.stopRec (deviceID) +timeout = libxsmu.StopRec (deviceID, timeout) print \ "Stopped Recording Streamed Data" From c8dcf61dfc33b2fae815e56ce418ffcdcdb617d9 Mon Sep 17 00:00:00 2001 From: Shyam Date: Thu, 21 Sep 2017 17:27:20 +0530 Subject: [PATCH 43/50] Added retest results for START_REC and STOP_REC --- changeBaudTesting.md | 176 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) diff --git a/changeBaudTesting.md b/changeBaudTesting.md index c225b6f..1b47b3d 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -1295,4 +1295,180 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent recSize: void smu::Driver::keepAlive(uint32_t*, float*)0 Timeout: 0.0: 758:Lock AcquiredCommunication timeout in recData + ``` + + +- Implemented START_REC and STOP_REC down to firmware +- New test (`wrapper/python/test/startRec.py`) +- Result : Passed +- Output : + + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):652:Opening Device + libxsmu version: 2.1.2 + 51 Q + 50 P + 34 4 + 31 1 + 0 + 2C , + F9 � + 12  + 0 + 1  + 0 + 0 + 58 X + 50 P + 4C L + 4F O + 52 R + 45 E + 20 + 53 S + 4D M + 55 U + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4  + 0 + 0 + FF � + FF � + FF � + FD � + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):678:Async thread launched + Device ID : 0 + goodID : 1void smu::Driver::keepAlive(uint32_t*, float*): 775: + Remaining time:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):7770.886788845062 sec + + :Lock Acquired + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::keepAlive(uint32_t*, float*):775:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):777:Lock Acquired + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::StartRec(float*):1520:Lock Acquired + void smu::Driver::StartRec(float*):1525:Successfully transmitted, waiting for response + 51 Q + 50 P + 34 4 + 31 1 + 0 + 4  + FF � + D2 � + 0 + 2E . + 0 + 0 + Started Recording Streamed Data + void smu::Driver::keepAlive(uint32_t*, float*):775:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):777:Lock Acquired + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::keepAlive(uint32_t*, float*):775:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):777:Lock Acquired + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::StopRec(float*):1540:Lock Acquired + void smu::Driver::StopRec(float*):1545:Successfully transmitted, waiting for response + 51 Q + 50 P + 34 4 + 31 1 + 0 + 4  + FF � + D1 � + 0 + 2F / + 0 + 0 + Stopped Recording Streamed Data + void smu::Driver::close():684:Closing Device ``` \ No newline at end of file From f5976e097945327f5848bc5a06eb2b930d0d14f8 Mon Sep 17 00:00:00 2001 From: Shyam Date: Thu, 21 Sep 2017 17:59:56 +0530 Subject: [PATCH 44/50] 2 Testing results added for REC_DATA --- changeBaudTesting.md | 576 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 575 insertions(+), 1 deletion(-) diff --git a/changeBaudTesting.md b/changeBaudTesting.md index 1b47b3d..95fe519 100644 --- a/changeBaudTesting.md +++ b/changeBaudTesting.md @@ -1471,4 +1471,578 @@ void smu::Driver::thread():736:Inside thread : Keep Alive sent 0 Stopped Recording Streamed Data void smu::Driver::close():684:Closing Device - ``` \ No newline at end of file + ``` + +- Testing REC_DATA again +- Added more print statements to debug +- Result : Failed +- Output (only for recData function) : + + ``` + void smu::Driver::recData(uint16_t*, float*):1474:Lock Acquired + void smu::Driver::recData(uint16_t*, float*):1479:Successfully transmitted, waiting for response + 51 Q + 50 P + 34 4 + 31 1 + 1  + 8 + EA � + E1 � + 0 + 2D - + 0 + 0 + 0 + 1  + 0 + 0 + 53 S + 20 + 45 E + 52 R + 0 + 0 + 55 U + 4D M + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4  + 0 + FD � + FF � + FF � + FF � + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 3C < + 23 # + D7 � + A + + 0 + 0 + 0 + 1  + 0 + 0 + 0 + 0 + 8 + 2  + F0 � + 14  + 0 + 0 + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 80 � + 25 % + 0 + 0 + 50 P + 51 Q + 0 + FF � + 8 + 0 + 31 1 + 0 + 2F / + 0 + D1 � + 27 ' + 0 + 0 + 0 + 0 + 0 + 0 + 10  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + FF � + B3 � + 4  + 0 + 0 + 2D - + 0 + D2 � + 0 + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 10  + 27 ' + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + FF � + 0 + 0 + F5 � + 4  + B3 � + 4  + F5 � + 4  + 0 + 1  + 4  + 0 + 0 + 0 + 0 + 4  + AF � + AF � + 4  + E7 � + 10  + E3 � + 1  + 0 + 0 + 0 + 10  + 1  + 0 + 18  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 5 + B8 � + void smu::Driver::keepAlive(uint32_t*, float*):775:Trying to Acquire Lock + recSize: void smu::Driver::keepAlive(uint32_t*, float*)0:777 + Timeout: :Lock Acquired0.0 + + Communication timeout in recData + ``` +- Retest +- Result : Failed +- Output : + ``` + void smu::Driver::recData(uint16_t*, float*):1474:Lock Acquired + void smu::Driver::recData(uint16_t*, float*):1479:Successfully transmitted, waiting for response + 51 Q + 50 P + 34 4 + 31 1 + 1  + 8 + E7 � + 16  + 0 + 2D - + 0 + 0 + 0 + 1  + 0 + 0 + 53 S + 20 + 45 E + 52 R + 0 + 0 + 55 U + 4D M + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4  + 0 + FD � + FF � + FF � + FF � + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 3C < + 23 # + D7 � + A + + 1  + 0 + 0 + 1  + 0 + 0 + 0 + 0 + 1C  + F0 � + 55 U + B + + 0 + 1  + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 80 � + 25 % + 0 + 0 + 50 P + 51 Q + 0 + FF � + 8 + 0 + 31 1 + 0 + 2D - + 0 + D2 � + 0 + 1  + 0 + 0 + 10  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 51 Q + B3 � + 4  + FF � + 0 + 31 1 + 34 4 + 50 P + 0 + C7 � + FF � + 8 + 0 + 0 + 0 + 2  + 0 + 10  + 27 ' + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + F5 � + 0 + 0 + F5 � + 4  + B3 � + 4  + F5 � + 4  + 0 + 1  + 4  + 0 + 0 + 0 + 0 + 4  + AF � + AF � + 4  + 1  + E3 � + 10  + E7 � + 10  + 0 + 0 + 0 + 0 + 18  + 0 + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + B8 � + 5 + 0 + 0 + void smu::Driver::keepAlive(uint32_t*, float*):775:Trying to Acquire Lock + recSize: void smu::Driver::keepAlive(uint32_t*, float*):0 + Timeout: 7770.0 + Communication timeout in recData + :Lock Acquired + ``` From 8c3602b19f71fc6760fb7753a10d0614db1406ff Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Thu, 21 Sep 2017 23:49:23 +0530 Subject: [PATCH 45/50] Added polling function in thread, activeCalibration_ in VM, and python interface to getData (Yet to be tested) --- XSMU-2.4.0/code/app/app/VM.h | 17 +++++- XSMU-2.4.0/code/app/app/virtuaSMU.h | 1 + XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 59 ++++++++++++++++---- XSMU-2.4.0/wrapper/python/libxsmu.cxx | 20 +++---- XSMU-2.4.0/wrapper/python/libxsmu.h | 4 +- XSMU-2.4.0/wrapper/python/libxsmu.i | 4 ++ XSMU-2.4.0/wrapper/python/test/changeBaud.py | 2 - XSMU-2.4.0/wrapper/python/test/getData.py | 45 +++++++++++++++ 8 files changed, 126 insertions(+), 26 deletions(-) create mode 100644 XSMU-2.4.0/wrapper/python/test/getData.py diff --git a/XSMU-2.4.0/code/app/app/VM.h b/XSMU-2.4.0/code/app/app/VM.h index 3fae405..247e531 100644 --- a/XSMU-2.4.0/code/app/app/VM.h +++ b/XSMU-2.4.0/code/app/app/VM.h @@ -52,6 +52,20 @@ class VM return calibration_[index].second(); } + +public: + void setActiveCalibration (uint16_t index, int32_t adc, float voltage) { + activeCalibration_[index].set (adc, voltage); + } + + int32_t activeCalibration_adc (uint16_t index) const { + return activeCalibration_[index].first(); + } + + float activeCalibration_voltage (uint16_t index) const { + return activeCalibration_[index].second(); + } + public: VM_Terminal terminal (void) const { return terminal_; } void setTerminal (VM_Terminal __terminal) { terminal_ = __terminal;} @@ -60,8 +74,9 @@ class VM VM_Range range_; float voltage_; VM_CalibrationTable calibration_; + VM_CalibrationTable activeCalibration_; VM_Terminal terminal_; }; -} //namespace smu +} //namespace smu #endif diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index ecb64b6..ac15980 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -64,6 +64,7 @@ class Driver { void keepAlive (uint32_t* lease_time_ms, float* timeout); void thread (void); + void poll (uint16_t* size); void setSourceMode (SourceMode* mode, float* timeout); diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 0c6b071..49a39d0 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -389,6 +389,16 @@ void Driver::VM_setRangeCB (const CommCB* oCB) vm_->setRange (toVM_Range (o->range())); ackBits_.set (COMM_CBCODE_VM_SET_RANGE); + + //TODO : How do I replace the number 5 here? + for (uint16_t index = 0; index < 5; ++index) + { + int32_t adc; + float voltage; + float timeout = 1; + VM_getCalibration (&index, &adc, &voltage, &timeout); + vm_->setActiveCalibration (index, adc, voltage); + } } /************************************************************************/ @@ -803,6 +813,14 @@ void Driver::thread (void) last_sent_at = timer.get(); } + if (_rec) + { + uint16_t size; + recSize(&size, &timeout); + + poll (&size); + } + /******************************************************** * Prevents 100% CPU utilization, * in case the operation is taking longer than 100ms. @@ -813,6 +831,20 @@ void Driver::thread (void) /************************************************************************/ +void Driver::poll (uint16_t *size) +{ + uint16_t dataSize = 64; + float timeout = 1; + + while (size > 0) + { + recData (&dataSize, &timeout); // Stores the data in _dataq_32 + size = size - dataSize; + } +} + +/************************************************************************/ + void Driver::setSourceMode (SourceMode* mode, float* timeout) { auto unique_lock = comm_->lock(); @@ -1491,16 +1523,18 @@ std::vector Driver::getData (void) * Output : std::vector */ { - std::vector data; + std::vector data {1.0, 3.5, 5.1, 7.2}; - std::lock_guard lock(_dataq_lock); - - while (!_dataq.empty()) - { - data.push_back(_dataq.front()); - _dataq.pop(); - _dataq_32.pop(); - } +// std::vector data; +// +// std::lock_guard lock(_dataq_lock); +// +// while (!_dataq.empty()) +// { +// data.push_back(_dataq.front()); +// _dataq.pop(); +// _dataq_32.pop(); +// } return data; } @@ -1551,11 +1585,12 @@ void Driver::StopRec (float *timeout) float Driver::applyCalibration (int32_t adc_value) /* - * Applys the calibration table (depending upon what physical quantity is - * being measured, and the range for the same; eg. current, 100uA range) - * to convert an ADC value into a voltage or current value + * Applys the calibration (depending upon what physical quantity is being + * measured, and the range for the same; eg. current, 100uA range) to + * convert an ADC value into a voltage or current value */ { + //TODO : How to apply calibration from a table? return float (adc_value); } diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index ba6e826..78d993a 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -873,16 +873,16 @@ void changeBaud (int deviceID, unsigned int baudRate, float timeout, /************************************************************************/ -// void getData (int deviceID, std::vector *ret_data) -// { -// VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; -// -// std::vector data_; -// -// data_ = virtuaSMU->getData(); -// -// *ret_data = data_; -// } +std::vector getData (int deviceID) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + std::vector data_ = virtuaSMU->getData(); + + return data_; +} + +/************************************************************************/ void StartRec (int deviceID, float timeout, float *ret_timeout) diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.h b/XSMU-2.4.0/wrapper/python/libxsmu.h index 1127cd0..3cabe7f 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.h +++ b/XSMU-2.4.0/wrapper/python/libxsmu.h @@ -1,6 +1,8 @@ #ifndef __XSMU__ #define __XSMU__ +#include + #ifdef __cplusplus extern "C" { #endif @@ -270,7 +272,7 @@ void changeBaud (int deviceID, unsigned int baudRate, float timeout, * */ -//void getData (int deviceID, std::vector *ret_data); +std::vector getData (int deviceID); /************************************************************************/ /** diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.i b/XSMU-2.4.0/wrapper/python/libxsmu.i index 1658d44..3d849af 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.i +++ b/XSMU-2.4.0/wrapper/python/libxsmu.i @@ -219,6 +219,8 @@ extern void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, unsigned int *ret_lease_time_ms, float *ret_timeout); +extern std::vector getData (int deviceID); + extern void StartRec (int deviceID, float timeout, float *ret_timeout); @@ -414,6 +416,8 @@ extern void changeBaud (int deviceID, unsigned int baudRate, float timeout, extern void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, unsigned int *OUTPUT, float *OUTPUT); +extern std::vector getData (int deviceID); + extern void StartRec (int deviceID, float timeout, float *OUTPUT); diff --git a/XSMU-2.4.0/wrapper/python/test/changeBaud.py b/XSMU-2.4.0/wrapper/python/test/changeBaud.py index 4d55490..d58e5c2 100644 --- a/XSMU-2.4.0/wrapper/python/test/changeBaud.py +++ b/XSMU-2.4.0/wrapper/python/test/changeBaud.py @@ -29,8 +29,6 @@ print 'Communication timeout in open_device.' exit (-2) -sleep (5) - ########################################################################## # Set Baud Rate of communication diff --git a/XSMU-2.4.0/wrapper/python/test/getData.py b/XSMU-2.4.0/wrapper/python/test/getData.py new file mode 100644 index 0000000..1487bc4 --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/getData.py @@ -0,0 +1,45 @@ +import libxsmu, time, math, sys +from time import sleep + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +########################################################################## +# Get streamed data from data queue + +data = libxsmu.getData (deviceID) + +print "Data : " + +for item in data: + print "\t", item, "\n" + +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) From 5e307334b3dbe2035bb0754060b781c5a7e96948 Mon Sep 17 00:00:00 2001 From: Shyam Date: Fri, 22 Sep 2017 11:05:11 +0530 Subject: [PATCH 46/50] Minor start/stop rec modifications --- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 43 +++++++++++++-------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 49a39d0..0c9fb48 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -684,6 +684,8 @@ void Driver::open (const char* serialNo, float* timeout) << BUGFIX_VERSION_NO (versionInfo_->firmware_version()) << std::endl; + _alive = true; + _rec = false; _thread_future = std::async (std::launch::async, &Driver::thread, this); PRINT_DEBUG ("Async thread launched") } @@ -818,6 +820,7 @@ void Driver::thread (void) uint16_t size; recSize(&size, &timeout); + PRINT_DEBUG ("Recieved RecSize = " << size) poll (&size); } @@ -836,10 +839,11 @@ void Driver::poll (uint16_t *size) uint16_t dataSize = 64; float timeout = 1; - while (size > 0) + while (*size > 0) { + PRINT_DEBUG ("Size of data : " << *size) recData (&dataSize, &timeout); // Stores the data in _dataq_32 - size = size - dataSize; + *size -= dataSize; } } @@ -1029,7 +1033,6 @@ void Driver::VS_saveCalibration (float* timeout) void Driver::VS_setVoltage (float* voltage, float* timeout) { auto unique_lock = comm_->lock(); - PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_VS_SET_VOLTAGE); comm_->transmit_VS_setVoltage (*voltage); @@ -1176,9 +1179,7 @@ void Driver::VM_saveCalibration (float* timeout) void Driver::VM_read (uint16_t* filterLength, float* voltage, float* timeout) { - PRINT_DEBUG ("Trying to Acquire Lock") auto unique_lock = comm_->lock(); - PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_VM_READ); comm_->transmit_VM_read (*filterLength); @@ -1463,7 +1464,6 @@ void Driver::changeBaud (uint32_t* baudRate, float* timeout) */ { auto unique_lock = comm_->lock(); - PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); @@ -1483,7 +1483,6 @@ void Driver::recSize (uint16_t* recSize, float* timeout) */ { auto unique_lock = comm_->lock(); - PRINT_DEBUG ("Lock Acquired") ackBits_.reset (COMM_CBCODE_REC_SIZE); @@ -1502,6 +1501,7 @@ void Driver::recData (uint16_t* size, float* timeout) * within timeout duration. */ { + PRINT_DEBUG ("Trying to acquire lock") auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") @@ -1523,18 +1523,18 @@ std::vector Driver::getData (void) * Output : std::vector */ { - std::vector data {1.0, 3.5, 5.1, 7.2}; + //std::vector data {1.0, 3.5, 5.1, 7.2}; -// std::vector data; -// -// std::lock_guard lock(_dataq_lock); -// -// while (!_dataq.empty()) -// { -// data.push_back(_dataq.front()); -// _dataq.pop(); -// _dataq_32.pop(); -// } + std::vector data; + + std::lock_guard lock(_dataq_lock); + + while (!_dataq.empty()) + { + data.push_back(_dataq.front()); + _dataq.pop(); + _dataq_32.pop(); + } return data; } @@ -1548,8 +1548,6 @@ void Driver::StartRec (float *timeout) * start streaming data from the ADC */ { - _rec = true; - auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") @@ -1558,7 +1556,8 @@ void Driver::StartRec (float *timeout) comm_->transmit_StartRec(); PRINT_DEBUG ("Successfully transmitted, waiting for response") - waitForResponse (COMM_CBCODE_START_REC, timeout); + if (waitForResponse (COMM_CBCODE_START_REC, timeout)) + _rec = true; } void Driver::StopRec (float *timeout) @@ -1568,7 +1567,7 @@ void Driver::StopRec (float *timeout) * from the ADC */ { - _rec = false; + _rec = false; auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") From a7041266a9d5ebb77e1110b07a03ff65621f7320 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Fri, 22 Sep 2017 11:45:45 +0530 Subject: [PATCH 47/50] Modified logic in thread, startRec and stopRec --- XSMU-2.4.0/code/app/app/virtuaSMU.h | 4 ++- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 42 +++++++++++++++------------ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index ac15980..c1bc00f 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -64,7 +64,7 @@ class Driver { void keepAlive (uint32_t* lease_time_ms, float* timeout); void thread (void); - void poll (uint16_t* size); + void poll_stream (void); void setSourceMode (SourceMode* mode, float* timeout); @@ -286,6 +286,8 @@ class Driver { private: bool _rec; + double _poll_stream_at = 100e-3; + double _poll_stream_interval; private: float applyCalibration (int32_t adc_value); diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 0c9fb48..9b8bbda 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -612,7 +612,6 @@ void Driver::recSizeCB (const CommCB* oCB) reinterpret_cast (oCB); recSize_ = o->recSize(); - ackBits_.set (COMM_CBCODE_REC_SIZE); } @@ -647,6 +646,9 @@ void Driver::recDataCB (const CommCB* oCB) void Driver::StartRecCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_START_REC); + Timer timer; + _poll_stream_at = timer.get(); + _rec = true; } void Driver::StopRecCB (const CommCB* oCB) @@ -815,13 +817,11 @@ void Driver::thread (void) last_sent_at = timer.get(); } - if (_rec) + if (_rec && timer.get() >= _poll_stream_at) { - uint16_t size; - recSize(&size, &timeout); + poll_stream(); - PRINT_DEBUG ("Recieved RecSize = " << size) - poll (&size); + _poll_stream_at = timer.get() + _poll_stream_interval; } /******************************************************** @@ -834,17 +834,25 @@ void Driver::thread (void) /************************************************************************/ -void Driver::poll (uint16_t *size) +void Driver::poll_stream (void) { - uint16_t dataSize = 64; + uint16_t size; + float timeout = 1; + recSize (&size, &timeout); - while (*size > 0) - { - PRINT_DEBUG ("Size of data : " << *size) - recData (&dataSize, &timeout); // Stores the data in _dataq_32 - *size -= dataSize; - } + if (size) do { + + PRINT_DEBUG ("Size of data : " << size); + + uint16_t rx_size = size; + + float timeout = 1; + recData (&rx_size, &timeout); // Stores the data in _dataq_32 + + size -= rx_size; + + } while (size); } /************************************************************************/ @@ -1556,8 +1564,7 @@ void Driver::StartRec (float *timeout) comm_->transmit_StartRec(); PRINT_DEBUG ("Successfully transmitted, waiting for response") - if (waitForResponse (COMM_CBCODE_START_REC, timeout)) - _rec = true; + waitForResponse (COMM_CBCODE_START_REC, timeout); } void Driver::StopRec (float *timeout) @@ -1567,8 +1574,6 @@ void Driver::StopRec (float *timeout) * from the ADC */ { - _rec = false; - auto unique_lock = comm_->lock(); PRINT_DEBUG ("Lock Acquired") @@ -1578,6 +1583,7 @@ void Driver::StopRec (float *timeout) PRINT_DEBUG ("Successfully transmitted, waiting for response") waitForResponse (COMM_CBCODE_STOP_REC, timeout); + _rec = false; } /************************************************************************/ From f9d4bd671e3d6965e8afcfdbbd55a0772b0d6250 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Sun, 28 Jan 2018 22:40:17 +0530 Subject: [PATCH 48/50] Working Version, after modifications in firmware to make Acquisition an Applet. --- XSMU-2.4.0/code/app/app/Comm.h | 2 +- XSMU-2.4.0/code/app/app/virtuaSMU.h | 2 +- XSMU-2.4.0/code/app/src/Comm.cxx | 2 +- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 68 ++++++++++++++------- XSMU-2.4.0/wrapper/python/libxsmu.cxx | 2 +- XSMU-2.4.0/wrapper/python/test/getData.py | 30 ++++++--- XSMU-2.4.0/wrapper/python/test/keepAlive.py | 26 ++++---- XSMU-2.4.0/wrapper/python/test/log.txt | 0 XSMU-2.4.0/wrapper/python/test/recData.py | 2 +- XSMU-2.4.0/wrapper/python/test/startRec.py | 10 +-- XSMU-2.4.0/wrapper/python/test/version.py | 3 +- 11 files changed, 95 insertions(+), 52 deletions(-) create mode 100644 XSMU-2.4.0/wrapper/python/test/log.txt diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index e984b98..e42aeab 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -1639,7 +1639,7 @@ class CommResponse_recSize : public CommPacket_recSize private: uint16_t recSize_; - uint16_t recData_; + uint16_t reserve_; }; /************************************************************************/ diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index c1bc00f..94f0bdc 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -287,7 +287,7 @@ class Driver { private: bool _rec; double _poll_stream_at = 100e-3; - double _poll_stream_interval; + static constexpr double _poll_stream_interval = 1000e-3; private: float applyCalibration (int32_t adc_value); diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index 1822b67..c8cb9e9 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -169,7 +169,7 @@ void Comm::processReceivedData (const void* data, uint16_t size) if (size) do { - std::printf ("%X %c\n", static_cast (*src), *src); + //std::printf ("%X %c\n", static_cast (*src), *src); qp4_->receiver().push_back (*src++); if (qp4_->receiver().ready()) { diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 9b8bbda..3325f92 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -40,6 +40,8 @@ std::vector Driver::scan (void) for (it = allDevices.begin(); it != allDevices.end(); ++it) if (std::string (it->description()) == "XPLORE SMU") device_list.push_back (*it); + else + std::cout << "Found: " << it->description() << std::endl; return device_list; } @@ -384,21 +386,11 @@ void Driver::CM_readCB (const CommCB* oCB) void Driver::VM_setRangeCB (const CommCB* oCB) { - const CommCB_VM_SetRange* o = - reinterpret_cast (oCB); - - vm_->setRange (toVM_Range (o->range())); - ackBits_.set (COMM_CBCODE_VM_SET_RANGE); + const CommCB_VM_GetCalibration* o = + reinterpret_cast (oCB); - //TODO : How do I replace the number 5 here? - for (uint16_t index = 0; index < 5; ++index) - { - int32_t adc; - float voltage; - float timeout = 1; - VM_getCalibration (&index, &adc, &voltage, &timeout); - vm_->setActiveCalibration (index, adc, voltage); - } + vm_->setCalibration (o->index(), o->adc(), o->voltage()); + ackBits_.set (COMM_CBCODE_VM_GET_CALIBRATION); } /************************************************************************/ @@ -619,12 +611,11 @@ void Driver::recSizeCB (const CommCB* oCB) void Driver::recDataCB (const CommCB* oCB) { - PRINT_DEBUG ("CB started") - const CommCB_recData* o = reinterpret_cast (oCB); uint16_t size = o->size(); //Size of data sent in this packet + PRINT_DEBUG ("***********recSize in CB : " << size) std::vector data = o->recData(); //Data in this packet PRINT_DEBUG ("Trying to acquire dataq lock") @@ -633,6 +624,7 @@ void Driver::recDataCB (const CommCB* oCB) for (uint16_t i = 0; i < size; ++i) { _dataq_32.push (data[i]); + PRINT_DEBUG ("***********recData in CB : " << data[i]) _dataq.push (applyCalibration (data[i])); } @@ -649,6 +641,14 @@ void Driver::StartRecCB (const CommCB* oCB) Timer timer; _poll_stream_at = timer.get(); _rec = true; + + /* + * Change Baud Rate of communication when streaming starts + */ + + // uint32_t baudRate = 9600; + // float timeout = 1; + // changeBaud (&baudRate, &timeout); } void Driver::StopRecCB (const CommCB* oCB) @@ -697,7 +697,17 @@ void Driver::close (void) try { PRINT_DEBUG ("Closing Device") _alive = false; - _thread_future.get(); + if (_thread_future.valid()) + _thread_future.get(); + } + catch (...) + {} + + try + { + float timeout = 1; + uint32_t lease_time_ms = 0; + keepAlive (&lease_time_ms, &timeout); } catch (...) {} @@ -775,10 +785,9 @@ void Driver::identify (float* timeout) { identity_.clear(); versionInfo_->clear(); + ackBits_.reset (COMM_CBCODE_IDN); - ackBits_.reset (COMM_CBCODE_IDN); comm_->transmitIdentify(); - waitForResponse (COMM_CBCODE_IDN, timeout); } @@ -817,7 +826,8 @@ void Driver::thread (void) last_sent_at = timer.get(); } - if (_rec && timer.get() >= _poll_stream_at) + + if (_rec && timer.get() >= _poll_stream_at) { poll_stream(); @@ -841,15 +851,17 @@ void Driver::poll_stream (void) float timeout = 1; recSize (&size, &timeout); - if (size) do { + PRINT_DEBUG ("*****************Size of data : " << size); - PRINT_DEBUG ("Size of data : " << size); + if (size) do { uint16_t rx_size = size; - float timeout = 1; + float timeout = 10; recData (&rx_size, &timeout); // Stores the data in _dataq_32 + PRINT_DEBUG (">>>>>>>>>>>>>>>>>>Size of rx data : " << rx_size); + size -= rx_size; } while (size); @@ -1565,6 +1577,7 @@ void Driver::StartRec (float *timeout) PRINT_DEBUG ("Successfully transmitted, waiting for response") waitForResponse (COMM_CBCODE_START_REC, timeout); + PRINT_DEBUG ("Response Recieved") } void Driver::StopRec (float *timeout) @@ -1584,6 +1597,15 @@ void Driver::StopRec (float *timeout) waitForResponse (COMM_CBCODE_STOP_REC, timeout); _rec = false; + PRINT_DEBUG ("Response Recieved") + + /* + * Restore Baud Rate of communication when streaming stops + */ + + // uint32_t baudRate = 9600; + // float time_out = 1; + // changeBaud (&baudRate, &time_out); } /************************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index 78d993a..3e29742 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -955,7 +955,7 @@ void recData (int deviceID, short unsigned int size, float timeout, virtuaSMU->recData (&size_, &timeout_); - *ret_size = 0; + *ret_size = 0; if ((*ret_timeout = timeout_) == 0) return; diff --git a/XSMU-2.4.0/wrapper/python/test/getData.py b/XSMU-2.4.0/wrapper/python/test/getData.py index 1487bc4..650b1a4 100644 --- a/XSMU-2.4.0/wrapper/python/test/getData.py +++ b/XSMU-2.4.0/wrapper/python/test/getData.py @@ -32,13 +32,29 @@ ########################################################################## # Get streamed data from data queue -data = libxsmu.getData (deviceID) - -print "Data : " - -for item in data: - print "\t", item, "\n" - +print \ + "Getting Data" + +logfile = open ('log.txt', 'w') + +t0 = time.time() +_time_ = 0 +while (time.time() - t0 < 60): + print "Remaining time: ", 60 - (time.time() - t0), " seconds" + timeout = 5.0 + recSize, timeout = libxsmu.recSize (deviceID, timeout) + data = libxsmu.getData (deviceID) + for voltage in data: + logfile.write (str (_time_) + ", " + str (voltage) + '\n') + print _time_, ',\t', voltage * 1e9, ' nV' + logfile.flush() + _time_ = _time_ + 0.1 + time.sleep (10) + +timeout = 5 +timeout = libxsmu.StopRec (deviceID, timeout) +print \ + "Stopped Recording Streamed Data" ########################################################################## # closes the device. diff --git a/XSMU-2.4.0/wrapper/python/test/keepAlive.py b/XSMU-2.4.0/wrapper/python/test/keepAlive.py index a08af64..cd35b41 100644 --- a/XSMU-2.4.0/wrapper/python/test/keepAlive.py +++ b/XSMU-2.4.0/wrapper/python/test/keepAlive.py @@ -1,4 +1,5 @@ import libxsmu, time, math, sys +from time import sleep ########################################################################## # Scans USB bus for Xplore SMU. @@ -30,18 +31,19 @@ ########################################################################## # Sends Keep_Alive Packet to device - -timeout = 5.0 -lease_time_ms = 10000 - -lease_time_ms, timeout = libxsmu.keepAlive (deviceID, lease_time_ms, timeout) -print \ - "Lease Time: ", lease_time_ms, "\n" \ - "Timeout: ", timeout - -if (timeout == 0.0): - print 'Communication timeout in keepAlive' - exit (-2) +for index in range (3): + timeout = 5.0 + lease_time_ms = 10000 + + lease_time_ms, timeout = libxsmu.keepAlive (deviceID, lease_time_ms, timeout) + print \ + "Lease Time: ", lease_time_ms, "\n" \ + "Timeout: ", timeout + + if (timeout == 0.0): + print 'Communication timeout in keepAlive' + exit (-2) + sleep (5) ########################################################################## # closes the device. diff --git a/XSMU-2.4.0/wrapper/python/test/log.txt b/XSMU-2.4.0/wrapper/python/test/log.txt new file mode 100644 index 0000000..e69de29 diff --git a/XSMU-2.4.0/wrapper/python/test/recData.py b/XSMU-2.4.0/wrapper/python/test/recData.py index c4cb259..7bbf0b2 100644 --- a/XSMU-2.4.0/wrapper/python/test/recData.py +++ b/XSMU-2.4.0/wrapper/python/test/recData.py @@ -35,7 +35,7 @@ # Queries the data stored in standby data queue in SMU timeout = 10.0 -size = 1 +size = 2 recSize, timeout = libxsmu.recData (deviceID, size, timeout) print \ diff --git a/XSMU-2.4.0/wrapper/python/test/startRec.py b/XSMU-2.4.0/wrapper/python/test/startRec.py index dbdea74..b6890a5 100644 --- a/XSMU-2.4.0/wrapper/python/test/startRec.py +++ b/XSMU-2.4.0/wrapper/python/test/startRec.py @@ -34,15 +34,16 @@ ########################################################################## # Start recording streamed data from the SMU -timeout = 5 - +timeout = 5.0 +print \ + "Starting Recording Streamed Data" timeout = libxsmu.StartRec (deviceID, timeout) print \ "Started Recording Streamed Data" -sleep(5) -timeout = 5 +sleep(20) +timeout = 5.0 timeout = libxsmu.StopRec (deviceID, timeout) print \ "Stopped Recording Streamed Data" @@ -50,4 +51,5 @@ ########################################################################## # closes the device. +sleep(5) libxsmu.close_device(deviceID) diff --git a/XSMU-2.4.0/wrapper/python/test/version.py b/XSMU-2.4.0/wrapper/python/test/version.py index 1ce8eb3..1c919f3 100644 --- a/XSMU-2.4.0/wrapper/python/test/version.py +++ b/XSMU-2.4.0/wrapper/python/test/version.py @@ -1,4 +1,5 @@ import libxsmu, time, math +from time import sleep ########################################################################## # Scans USB bus for Xplore SMU. @@ -37,5 +38,5 @@ ########################################################################## # closes the device. - +sleep(100) libxsmu.close_device(deviceID) From 570b92b79d6aa9088cb2e19279f3a9cd0619bef2 Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Sat, 3 Feb 2018 20:21:30 +0530 Subject: [PATCH 49/50] Data streaming from ADC, tested at V = 0V --- XSMU-2.4.0/code/app/app/Comm.h | 2 +- XSMU-2.4.0/code/app/src/Comm.cxx | 5 +++-- XSMU-2.4.0/code/app/src/virtuaSMU.cxx | 1 - XSMU-2.4.0/wrapper/python/test/recData.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index e42aeab..5b16595 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -1675,7 +1675,7 @@ class CommResponse_recData : public CommPacket_recData int32_t recData (uint16_t idx) const { - return smu::ntoh(recData_[idx]); + return smu::ntoh(recData_[idx]); } private: diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index c8cb9e9..6dc0199 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -787,7 +787,7 @@ void Comm::recSizeCB (const void* data, uint16_t size) void Comm::recDataCB (const void* data, uint16_t size) { - PRINT_DEBUG ("Size : " << size << "Expected : " << sizeof(CommRequest_recData)) + PRINT_DEBUG ("Size : " << size << "Expected : " << sizeof(CommResponse_recData)) if (size < sizeof (CommResponse_recData)) { @@ -802,11 +802,12 @@ void Comm::recDataCB (const void* data, uint16_t size) //Construct a std::vector from the recieved data array uint16_t n = res->size(); - std::vector recData (n); + std::vector recData; for (uint16_t i = 0; i < n; ++i) { recData.push_back (res->recData(i)); + std::cout << "Data pushed: " << recData[i] << std::endl; } PRINT_DEBUG ("VECTOR CONSTRUCTED") diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index 3325f92..6cd7cac 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -624,7 +624,6 @@ void Driver::recDataCB (const CommCB* oCB) for (uint16_t i = 0; i < size; ++i) { _dataq_32.push (data[i]); - PRINT_DEBUG ("***********recData in CB : " << data[i]) _dataq.push (applyCalibration (data[i])); } diff --git a/XSMU-2.4.0/wrapper/python/test/recData.py b/XSMU-2.4.0/wrapper/python/test/recData.py index 7bbf0b2..562b451 100644 --- a/XSMU-2.4.0/wrapper/python/test/recData.py +++ b/XSMU-2.4.0/wrapper/python/test/recData.py @@ -35,7 +35,7 @@ # Queries the data stored in standby data queue in SMU timeout = 10.0 -size = 2 +size = 3 recSize, timeout = libxsmu.recData (deviceID, size, timeout) print \ From 97337cfb048dfc673c1064f248c119851725050b Mon Sep 17 00:00:00 2001 From: gitansh95 Date: Wed, 7 Feb 2018 11:13:39 +0530 Subject: [PATCH 50/50] Modified getData python script to write data to log file --- XSMU-2.4.0/wrapper/python/test/getData.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/XSMU-2.4.0/wrapper/python/test/getData.py b/XSMU-2.4.0/wrapper/python/test/getData.py index 650b1a4..df6c812 100644 --- a/XSMU-2.4.0/wrapper/python/test/getData.py +++ b/XSMU-2.4.0/wrapper/python/test/getData.py @@ -29,6 +29,16 @@ print 'Communication timeout in open_device.' exit (-2) +########################################################################## +# Start recording streamed data from the XSMU + +timeout = 5 +timeout = libxsmu.StartRec (deviceID, timeout) +print \ + "Started Recording Streamed Data" + +sleep (5) + ########################################################################## # Get streamed data from data queue @@ -39,14 +49,14 @@ t0 = time.time() _time_ = 0 -while (time.time() - t0 < 60): - print "Remaining time: ", 60 - (time.time() - t0), " seconds" +while (time.time() - t0 < 60*60): + print "Remaining time: ", 60 - (time.time() - t0) / 60.0, " minutes" timeout = 5.0 recSize, timeout = libxsmu.recSize (deviceID, timeout) data = libxsmu.getData (deviceID) for voltage in data: logfile.write (str (_time_) + ", " + str (voltage) + '\n') - print _time_, ',\t', voltage * 1e9, ' nV' + print _time_, ',\t', voltage * 1e9, ' ADC' logfile.flush() _time_ = _time_ + 0.1 time.sleep (10)