Code: Select all
class function TCanApi4.GetParam(const device: can_device_t; const paramType: Word;
const objClass: can_objclass_t; const objHandle: Longword; out value: AnsiString)
: can_status_t;
var
param: can_any_param_t;
begin
param.base.size := SizeOf(can_param_string255_t);
param.base.&type := paramType;
param.base.objclass := Ord(objClass);
param.base.objhandle := objHandle;
Result := GetParam(device, param);
if (Result = CAN_ERR_OK) then
value := AnsiString(param.string255.value);
end;
And as the Note says: Converting the value to a string will result in an empty string. So in this case we need a different implementation. I suggest the follwowing, which returns a TBytes (dynamic array of bytes, length set to 256 in the function).Represents an array of values in range of [0, 1], that give information about the
clients connected to a net. The array index equals the handle of a client and the
value is a flag indicating connectivity (1) or not (0):
If clients[ i ] not equal to 0: Client 'i' is connected to the net.
Note: The first value of the array is always 0. For this reason, the attempt of
converting this array to a string ends in an empty string.
Code: Select all
class function TCanApi4.GetParam(const device: can_device_t; const paramType: Word;
const objclass: can_objclass_t; const objhandle: HCANOBJECT;
out Value: TBytes): can_status_t;
var
param: can_any_param_t;
i: Integer;
begin
param.base.size := SizeOf(can_param_string255_t);
param.base.&type := paramType;
param.base.objclass := Ord(objclass);
param.base.objhandle := objhandle.Value;
Result := GetParam(device, param);
if (Result = CAN_ERR_OK) then begin
// the next 3 lines are different
SetLength(Value, CAN_PARAM_CONST_MAX_STRINGLEN);
for i := 0 to CAN_PARAM_CONST_MAX_STRINGLEN - 1 do
Value[i] := Byte(param.string255.Value[i]);
end;
end;