I'm new to C# and come from an embedded C background so I hope I'm not embarassing myself not too much. I need to write a simulator for a variable frequency drive which sends device parameters to a PLC. What I would like to do is create a parameter class that contains information such as scaling factor, engineering value, binary value of the parameter etc so that a floating point parameter can be converted to binary for transmission.
I'd like to instantiate the object as follows:
VFDRealParam phasecurrent = new VFDRealParam(0, 1.25, VFDRealParam.pa ram_t.PARAM_BYT E);
but when assigning to the parameter it would be great if it could be possible to simply do an assignment:
phasecurrent = 67.4;
I'm thinking of a class declaration such as:
When invoking the overloaded typecast operator VFDRealParam(do uble), it seems I can only return a new object of type VFDRealParam meaning that the scaling factor, default value etc. that was stored when the object was first instantiated is now lost. If it is actually possible, how can I go about doing this simple assignment, or do I have to resort to properties and using get/set? How can I get the parameter to retain its stored properties?
Help from anybody will be greatly appreciated.
Thanks!
I'd like to instantiate the object as follows:
VFDRealParam phasecurrent = new VFDRealParam(0, 1.25, VFDRealParam.pa ram_t.PARAM_BYT E);
but when assigning to the parameter it would be great if it could be possible to simply do an assignment:
phasecurrent = 67.4;
I'm thinking of a class declaration such as:
Code:
class VFDRealParam : VFDParamBase
{
double _eng_data;
double _scaling_factor;
byte _byte_val;
param_t _type;
public VFDRealParam(double init_val, double scaling_factor, param_t type)
{
_eng_data = init_val;
_scaling_factor = scaling_factor;
_type = type;
ScaleFromEng();
}
public static implicit operator VFDRealParam(double value)
{
....
}
....
}
Help from anybody will be greatly appreciated.
Thanks!
Comment