Commit c61935e0 authored by ahoms's avatar ahoms
Browse files

* implemented Espia serial methods


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@52 45c4679d-1946-429d-baad-37912b19538b
parent c6aaca8b
......@@ -21,8 +21,8 @@ class Espia
void serWrite(const std::string& buffer,
int block_size = 0, double block_delay = 0,
bool no_wait = false);
void serRead(std::string& buffer, int& len, double timeout);
void serReadStr(std::string& buffer, int& len,
void serRead(std::string& buffer, int len, double timeout);
void serReadStr(std::string& buffer, int len,
const std::string& term, double timeout);
static void throwError(int ret, std::string file, std::string func,
......@@ -31,7 +31,8 @@ class Espia
private:
void open(int dev_nr);
void close();
unsigned long sec2us(double sec);
int m_dev_nr;
espia_t m_dev;
......@@ -42,10 +43,16 @@ class Espia
int aux_ret = (ret); \
if (aux_ret < 0) \
Espia::throwError(aux_ret, __FILE__, \
__FUNCTION__, __LINE__); \
__FUNCTION__, __LINE__); \
} while (0)
inline unsigned long Espia::sec2us(double sec)
{
return (unsigned long) (sec * 1e6);
}
} // namespace lima
#endif // ESPIA_H
......@@ -37,6 +37,35 @@ void Espia::close()
m_dev_nr = Invalid;
}
void Espia::serWrite(const string& buffer, int block_size, double block_delay,
bool no_wait)
{
unsigned long len = buffer.length();
char *ptr = len ? (char *) buffer.data() : NULL;
CHECK_CALL(espia_ser_write(m_dev, ptr, &len, block_size,
sec2us(block_delay), !no_wait));
}
void Espia::serRead(string& buffer, int len, double timeout)
{
buffer.resize(len);
char *ptr = len ? (char *) buffer.data() : NULL;
unsigned long ret_len = len;
CHECK_CALL(espia_ser_read(m_dev, ptr, &ret_len, sec2us(timeout)));
buffer.resize(ret_len);
}
void Espia::serReadStr(string& buffer, int len, const string& term,
double timeout)
{
buffer.resize(len);
char *ptr = len ? (char *) buffer.data() : NULL;
char *term_ptr = (char *) term.data();
unsigned long ret_len = len;
CHECK_CALL(espia_ser_read_str(m_dev, ptr, &ret_len, term_ptr,
term.length(), sec2us(timeout)));
buffer.resize(ret_len);
}
void Espia::throwError(int ret, string file, string func, int line)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment