Basic device class This class contains all basic method of all devices, like Connect, Exec, WhatAmI etc.
More...
#include <Device.h>
|
| Device (std::string ipAddress, int timeoutInMs, SEND_METHOD mode=DIRECT_SEND, bool throwException=true) |
| Constructor for the Device without passing a logging object. More...
|
|
| Device (std::string ipAddress, int timeoutInMs, PIL::Logging *logger, SEND_METHOD mode=DIRECT_SEND, bool throwException=true) |
| Constructor of Device generates a socket handle without connecting to it. More...
|
|
| Device (std::string ipAddress, uint16_t srcPort, uint16_t destPort, int timeoutInMs, PIL::Logging *logger, SEND_METHOD mode=DIRECT_SEND, bool throwException=true) |
| Base class containing the base functionality of all devices. And parameters to store the name connection type, etc. More...
|
|
| ~Device () |
|
PIL_ERROR_CODE | Connect () |
| Establish a connection to the device. More...
|
|
PIL_ERROR_CODE | Disconnect () |
| Disconnect from the device. More...
|
|
bool | isOpen () const |
| Checks if the connection to the device is established. More...
|
|
bool | isBuffered () const |
| Checks if the commands sent to the device get buffered. More...
|
|
std::string | getDeviceIdentifier () |
| Gets the name of the currently connected device. More...
|
|
PIL_ERROR_CODE | Exec (const std::string &command, ExecArgs *args=nullptr, char *result=nullptr, bool br=true, int size=1024) |
| execute a (SCPI) command More...
|
|
PIL_ERROR_CODE | Exec (const std::string &command, ExecArgs *args, std::string *result, bool br) |
|
PIL_ERROR_CODE | ExecCommands (std::string &commands) |
|
std::string | ReturnErrorMessage () |
|
std::string | getBufferedScript () |
| Transforms the current buffered script into a string and returns it. More...
|
|
void | changeSendMode (SEND_METHOD mode) |
| Changes the send mode of this device, i.e. whether the commands get buffered or sent directly to the device. More...
|
|
PIL_ERROR_CODE | delay (double delayTime) |
| Stops the execution for the specified amount of time in seconds. If buffering is enabled, the delay is included in the buffered script. Otherwise this thread sleeps for the given time. More...
|
|
|
PIL_ERROR_CODE | handleErrorsAndLogging (PIL_ERROR_CODE errorCode, bool throwException, PIL::Level logLevel, const std::string &fileName, int line, std::string formatStr,...) |
| Handle logging messages, logs it based on the previously passed logging object. If exceptions are enabled throw an exception otherwise return the error code. More...
|
|
|
static bool | errorOccured (PIL_ERROR_CODE errorCode) |
| Checks if a error occured given the error code. More...
|
|
static PIL_ERROR_CODE | postRequest (const std::string &url, std::string &payload) |
| Sends a post request to the given url with the given payload. More...
|
|
static std::string | vectorToStringNL (std::vector< std::string > vector) |
| Transforms the given vector into a string. Each vector entry will be a line in the resulting string. More...
|
|
static std::string | replaceAllSubstrings (std::string str, const std::string &from, const std::string &to) |
| Replaces all substrings in the string with the given replacement string. More...
|
|
static std::vector< std::string > | splitString (const std::string &toSplit, const std::string &delimiter) |
| Splits a string by the given delimiter. More...
|
|
Basic device class This class contains all basic method of all devices, like Connect, Exec, WhatAmI etc.
◆ SEND_METHOD
Enumerator |
---|
DIRECT_SEND | |
BUFFER_ENABLED | |
◆ Device() [1/3]
Device::Device |
( |
std::string |
ipAddress, |
|
|
int |
timeoutInMs, |
|
|
SEND_METHOD |
mode = DIRECT_SEND , |
|
|
bool |
throwException = true |
|
) |
| |
|
explicit |
Constructor for the Device without passing a logging object.
- Parameters
-
ipAddress | IP address of the device |
timeoutInMs | |
◆ Device() [2/3]
Device::Device |
( |
std::string |
ipAddress, |
|
|
int |
timeoutInMs, |
|
|
PIL::Logging * |
logger, |
|
|
SEND_METHOD |
mode = DIRECT_SEND , |
|
|
bool |
throwException = true |
|
) |
| |
|
explicit |
Constructor of Device generates a socket handle without connecting to it.
- Parameters
-
ipAddress | The ip address to connect to the device. |
timeoutInMs | Timeout of the socket in milliseconds. |
logger | Pass a logging object to configure what types of messages should be logged. If nullptr is passed, logging is disabled. |
◆ Device() [3/3]
Device::Device |
( |
std::string |
ipAddress, |
|
|
uint16_t |
srcPort, |
|
|
uint16_t |
destPort, |
|
|
int |
timeoutInMs, |
|
|
PIL::Logging * |
logger, |
|
|
SEND_METHOD |
mode = DIRECT_SEND , |
|
|
bool |
throwException = true |
|
) |
| |
|
explicit |
Base class containing the base functionality of all devices. And parameters to store the name connection type, etc.
- Authors
- Wuhao Liu, Alexander Braml, Florian Frank
- Copyright
- University of Passau
◆ ~Device()
◆ changeSendMode()
Changes the send mode of this device, i.e. whether the commands get buffered or sent directly to the device.
- Parameters
-
mode | The new send mode to use. |
◆ Connect()
PIL_ERROR_CODE Device::Connect |
( |
| ) |
|
Establish a connection to the device.
- Returns
- if the connection is established return PIL_NO_ERROR otherwise return error code.
- Exceptions
-
PIL::Exception | if the connection could not established. |
◆ delay()
PIL_ERROR_CODE Device::delay |
( |
double |
delayTime | ) |
|
Stops the execution for the specified amount of time in seconds. If buffering is enabled, the delay is included in the buffered script. Otherwise this thread sleeps for the given time.
- Parameters
-
delayTime | The delay in seconds. |
- Returns
- The received error code.
◆ Disconnect()
PIL_ERROR_CODE Device::Disconnect |
( |
| ) |
|
Disconnect from the device.
- Returns
- if the connection is disconnected return PIL_NO_ERROR otherwise return error code.
- Exceptions
-
PIL::Exception | if the connection could not disconnected. |
◆ errorOccured()
bool Device::errorOccured |
( |
PIL_ERROR_CODE |
errorCode | ) |
|
|
staticprotected |
Checks if a error occured given the error code.
- Parameters
-
errorCode | The error code to check. |
- Returns
- true if and only if there is an error.
◆ Exec() [1/2]
PIL_ERROR_CODE Device::Exec |
( |
const std::string & |
command, |
|
|
ExecArgs * |
args, |
|
|
std::string * |
result, |
|
|
bool |
br |
|
) |
| |
◆ Exec() [2/2]
PIL_ERROR_CODE Device::Exec |
( |
const std::string & |
command, |
|
|
ExecArgs * |
args = nullptr , |
|
|
char * |
result = nullptr , |
|
|
bool |
br = true , |
|
|
int |
size = 1024 |
|
) |
| |
execute a (SCPI) command
- Parameters
-
message | a (SCPI) command |
result[out] | The string will contain the result message(Max length: 1024) |
br | whether add a '\n' at the end of the command |
- Note
- Different companies, devices may have different levels of support for SCPI. Some device may require '\n', some may not. That is why here is a br param.
- Todo:
- Deal with execution timeout;
- Warning
- Some commands may timeout
PIL_ERROR_CODE Exec(const std::string &command, ExecArgs *args=nullptr, char *result=nullptr, bool br=true, int size=1024)
execute a (SCPI) command
Definition: Device.cpp:189
Mixed Single Oscilloscope(Oscillator) Commend operations of a single generator are defined....
Definition: KST3000.h:26
◆ ExecCommands()
PIL_ERROR_CODE Device::ExecCommands |
( |
std::string & |
commands | ) |
|
◆ getBufferedScript()
std::string Device::getBufferedScript |
( |
| ) |
|
Transforms the current buffered script into a string and returns it.
- Returns
- The currently buffered script as a string.
◆ getDeviceIdentifier()
std::string Device::getDeviceIdentifier |
( |
| ) |
|
Gets the name of the currently connected device.
- Returns
- The name of this device.
◆ handleErrorsAndLogging()
PIL_ERROR_CODE Device::handleErrorsAndLogging |
( |
PIL_ERROR_CODE |
errorCode, |
|
|
bool |
throwException, |
|
|
PIL::Level |
logLevel, |
|
|
const std::string & |
fileName, |
|
|
int |
line, |
|
|
std::string |
formatStr, |
|
|
|
... |
|
) |
| |
|
protected |
Handle logging messages, logs it based on the previously passed logging object. If exceptions are enabled throw an exception otherwise return the error code.
- Parameters
-
errorCode | error code to identify the error. |
throwException | if true, throw an exception. |
logLevel | log level of the message. |
fileName | name of the file where the error occurred. |
line | line number where the error occurred. |
formatStr | format string for the error message. |
... | variable arguments for the format string. |
- Returns
- error code.
◆ isBuffered()
bool Device::isBuffered |
( |
| ) |
const |
Checks if the commands sent to the device get buffered.
- Returns
- true if connection is buffering is enabled, otherwise false.
◆ isOpen()
bool Device::isOpen |
( |
| ) |
const |
Checks if the connection to the device is established.
- Returns
- true if connection is established, otherwise false.
◆ postRequest()
PIL_ERROR_CODE Device::postRequest |
( |
const std::string & |
url, |
|
|
std::string & |
payload |
|
) |
| |
|
staticprotected |
Sends a post request to the given url with the given payload.
- Parameters
-
url | The url to send the post request to. |
payload | The payload to send. |
◆ replaceAllSubstrings()
std::string Device::replaceAllSubstrings |
( |
std::string |
str, |
|
|
const std::string & |
from, |
|
|
const std::string & |
to |
|
) |
| |
|
staticprotected |
Replaces all substrings in the string with the given replacement string.
- Parameters
-
str | String to replace substrings in. |
from | The substring to replace. |
to | The string to replace all matching substrings with. |
- Returns
- The processed string
◆ ReturnErrorMessage()
std::string Device::ReturnErrorMessage |
( |
| ) |
|
◆ splitString()
std::vector< std::string > Device::splitString |
( |
const std::string & |
toSplit, |
|
|
const std::string & |
delimiter |
|
) |
| |
|
staticprotected |
Splits a string by the given delimiter.
- Parameters
-
toSplit | The string to split. |
delimiter | The delimter to split the string by. |
- Returns
- A vector of substrings of toSplit.
◆ vectorToStringNL()
std::string Device::vectorToStringNL |
( |
std::vector< std::string > |
vector | ) |
|
|
staticprotected |
Transforms the given vector into a string. Each vector entry will be a line in the resulting string.
- Parameters
-
vector | The vector to transform. |
- Returns
- The given vector as string.
◆ m_BufferedScript
std::vector<std::string> Device::m_BufferedScript |
|
protected |
◆ m_destPort
int Device::m_destPort = 5025 |
|
protected |
◆ m_DeviceName
std::string Device::m_DeviceName {} |
|
protected |
◆ m_EnableExceptions
bool Device::m_EnableExceptions |
|
protected |
◆ m_ErrorHandle
PIL_ErrorHandle Device::m_ErrorHandle |
|
protected |
◆ m_IPAddr
std::string Device::m_IPAddr |
|
protected |
◆ m_Logger
PIL::Logging* Device::m_Logger |
|
protected |
◆ m_SendMode
◆ m_SocketHandle
PIL::Socket* Device::m_SocketHandle |
|
protected |
◆ m_srcPort
int Device::m_srcPort = 5025 |
|
protected |
The documentation for this class was generated from the following files:
- /home/runner/work/instrument_control_lib/instrument_control_lib/include/Device.h
- /home/runner/work/instrument_control_lib/instrument_control_lib/src/Device.cpp