-
Notifications
You must be signed in to change notification settings - Fork 6
Base Device
Base device is a template that every device needs to inherit in order to work with RadCat systems. BaseDevice is a component based class thus you need to use it with templates. A basic way to inherit would be with
Class YourDevice : public BaseDevice<Component1,Component2,...> {}
Component creation and assigning is handled by RadCat systems.
BaseDevice gives you few handy functions that you can implement and use to make your life easier. You can use component getter to use or store component references in your code with a basic function.
component& name = getComponent<ComponentName>()
You can also cast it as const if you dont want to edit and only want to read the component.
Also base device has some pure virtual functions that you need to implement in your class. If you dont your class WONT compile. These functions are:
bool connect()bool disconnect()void cycleCheck()double readValue(const std::string& parameter)bool setValue(const std::string& parameter, double value)
These functions are implemented by RadCat system automaticly thus its inportant to understand what each one does and when each one is called.
Lets start with connect() and disconnect().
these functions are called whenever device tries to connect and disconnect from the program. You need to implement FTDI or other communication components inside these functions in order to connect and disconnect from the program.
cycleCheck() does what it says. Its run once per CPU cycle to check anything you need. You want to check temperature every cycle? You can implement a function inside cycleCheck() to do so. But there is an important caveat here. Doing heavy stuff inside cycleCheck() every CPU cycle can slow down program alot. Thus we recommend implementing a time based system where it check the time passed every cycle and fires the check function when enough time passes.
Also you may not want other people to see / change variables you implement under the hood. Thus its a good idea to make them private and use double readValue(const std::string& parameter) and bool setValue(const std::string& parameter, double value) to expose only the values you want.
Thats it for the Base Device. Happy device creation.