fix pistringlist pibinarystream write pibinarystream::binaryStreamSize() PIByteArray pibinarystream read with more size fix pistring pibinarystream read optimization fix bug in PIIOBinaryStream read and write if failed workaround in PIIOString::readDevice PISPI readDevice bug Fixed
53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
#include "pip.h"
|
|
void _() {
|
|
|
|
//! [0]
|
|
class SomeIO: public PIIODevice {
|
|
PIIODEVICE(SomeIO, "myio")
|
|
public:
|
|
SomeIO(): PIIODevice() {}
|
|
protected:
|
|
bool openDevice() override {
|
|
// open your device here
|
|
return if_success;
|
|
}
|
|
int readDevice(void * read_to, int max_size) override {
|
|
// read from your device here
|
|
return readed_bytes;
|
|
}
|
|
int writeDevice(const void * data, int max_size) override {
|
|
// write to your device here
|
|
return written_bytes;
|
|
}
|
|
void configureFromFullPathDevice(const PIString & full_path) override {
|
|
// parse full_path and configure device here
|
|
}
|
|
};
|
|
REGISTER_DEVICE(SomeIO)
|
|
//! [0]
|
|
//! [configure]
|
|
// file example.conf
|
|
dev.reopenEnabled = false
|
|
dev.device = /dev/ttyS0
|
|
dev.speed = 9600
|
|
// end example.conf
|
|
// code
|
|
PISerial ser;
|
|
ser.configure("example.conf", "dev");
|
|
//! [configure]
|
|
//! [configureDevice]
|
|
class SomeIO: public PIIODevice {
|
|
...
|
|
bool configureDevice(const void * e_main, const void * e_parent) override {
|
|
PIConfig::Entry * em = (PIConfig::Entry * )e_main;
|
|
PIConfig::Entry * ep = (PIConfig::Entry * )e_parent;
|
|
setStringParam(readDeviceSetting<PIString>("stringParam", stringParam(), em, ep));
|
|
setIntParam(readDeviceSetting<int>("intParam", intParam(), em, ep));
|
|
return true;
|
|
}
|
|
...
|
|
};
|
|
//! [configureDevice]
|
|
|
|
};
|