-
Notifications
You must be signed in to change notification settings - Fork 0
Simple properties attributes and metadata reading #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5271c1a
44da1ba
d4b9472
1e67a95
6b346c1
eb83099
0fafd54
b5a15c3
33b3752
cca8ea5
ed39e4f
ad407d5
f4b2a53
a5f03dc
ec07eb5
d02ccae
d27e326
cd757d5
a0d2f18
b4ed30e
2d836d1
7f63be8
d2b0566
1a84ccd
c9cbf11
2591238
36bcb0e
39204d3
568f656
f1c6d9a
b38ad57
d65e190
9ece61f
b00df6e
481bbdb
72c0eb7
27b7ded
0c8b358
4033bfe
e5d530f
ef7e4af
9a1c2a7
e645142
8d033ba
034ddbb
72765da
a0ed3af
bf54bf4
a5fd85e
ced9806
21815c5
262ef1a
75f63e5
1a8c7b2
93cfbb9
c317fc5
beff957
7890b1a
aab8d7c
da35652
40a2a9f
b92eff6
d961cb9
fe91866
6524936
1acda8b
37f12bc
94f6e6c
cbcaddb
f37fef9
44ccd00
e4c40ce
f64c2f6
655de8b
a0cf83a
06f4278
badb1fb
5bd6255
300610d
187ba2e
d47e28b
652e12f
8b9c0b5
42adc9c
f739863
d66dad1
0df6c6f
6e4ffe8
541282a
0453cd2
85352f5
90e4287
40085e8
28c6c75
da3fb60
8a6eb33
68d80d3
2df4952
8173143
40396ba
66630b2
dba5b55
404d520
708af6c
823ec87
cf1ab74
c5ffbb8
628ed9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /* | ||
| * Example that shows how to create conversion functions for custom defined in openDAQ. | ||
| * Functions demonstrate conversions to and from openDAQ structure to its | ||
| * equivalent in native C. | ||
| */ | ||
| #include <daq_example_utils.h> | ||
|
|
||
| // Struct conversion | ||
| /* | ||
| * Conversion from and to daqStruct objects to C style structs. | ||
| * Warning: These types of conversions require prior knowledge of | ||
| * the struct structure and its definition in C. For conversion | ||
| * from C to openDAQ a pointer to the TypeManager is needed because | ||
| * of the way openDAQ structs are implemented. | ||
| */ | ||
| struct daqExample_Coordinates daqExample_fromDaqCoordinates(daqStruct* daq) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These converters should really not use the name
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the conversion methods I suggested that we always use |
||
| { | ||
| struct daqExample_Coordinates native = { 0,0,0 }; | ||
|
|
||
| daqBaseObject* value = NULL; | ||
| daqBaseObject* integerValue = NULL; | ||
|
|
||
| daqString* fieldName = exdaq_toDaqString("x"); | ||
| daqStruct_get(daq, fieldName, &value); | ||
| daqQueryInterface(value, DAQ_INTEGER_INTF_ID, &integerValue); | ||
| native.x = exdaq_fromDaqInteger((daqInteger*) integerValue); | ||
| daqReleaseRef(integerValue); | ||
| daqReleaseRef(value); | ||
| daqReleaseRef(fieldName); | ||
|
|
||
| fieldName = exdaq_toDaqString("y"); | ||
| daqStruct_get(daq, fieldName, &value); | ||
| daqQueryInterface(value, DAQ_INTEGER_INTF_ID, &integerValue); | ||
| native.y = exdaq_fromDaqInteger((daqInteger*) integerValue); | ||
| daqReleaseRef(integerValue); | ||
| daqReleaseRef(value); | ||
| daqReleaseRef(fieldName); | ||
|
|
||
| fieldName = exdaq_toDaqString("z"); | ||
| daqStruct_get(daq, fieldName, &value); | ||
| daqQueryInterface(value, DAQ_INTEGER_INTF_ID, &integerValue); | ||
| native.z = exdaq_fromDaqInteger((daqInteger*) integerValue); | ||
| daqReleaseRef(integerValue); | ||
| daqReleaseRef(value); | ||
| daqReleaseRef(fieldName); | ||
|
|
||
| return native; | ||
| } | ||
|
|
||
| daqStruct* daqExample_toDaqCoordinates(struct daqExample_Coordinates native, daqTypeManager* typeManager) | ||
| { | ||
| daqStructBuilder* builder = NULL; | ||
| daqStructBuilder_createStructBuilder(&builder, exdaq_toDaqString("DAQ_Coordinates"), typeManager); | ||
|
|
||
| daqString* fieldName = NULL; | ||
| daqInteger* fieldValue = NULL; | ||
|
|
||
| fieldName = exdaq_toDaqString("x"); | ||
| fieldValue = exdaq_toDaqInteger(native.x); | ||
| daqStructBuilder_set(builder, fieldName, (daqBaseObject*) fieldValue); | ||
| daqReleaseRef(fieldName); | ||
| daqReleaseRef(fieldValue); | ||
|
|
||
| fieldName = exdaq_toDaqString("y"); | ||
| fieldValue = exdaq_toDaqInteger(native.y); | ||
| daqStructBuilder_set(builder, fieldName, (daqBaseObject*) fieldValue); | ||
| daqReleaseRef(fieldName); | ||
| daqReleaseRef(fieldValue); | ||
|
|
||
| fieldName = exdaq_toDaqString("z"); | ||
| fieldValue = exdaq_toDaqInteger(native.z); | ||
| daqStructBuilder_set(builder, fieldName, (daqBaseObject*) fieldValue); | ||
| daqReleaseRef(fieldName); | ||
| daqReleaseRef(fieldValue); | ||
|
|
||
| daqStruct* daq = NULL; | ||
| daqStructBuilder_build(builder, &daq); | ||
| daqReleaseRef(builder); | ||
|
|
||
| return daq; | ||
| } | ||
|
|
||
| // Enumeration conversion | ||
| /* | ||
| * Conversion from and to openDAQ String (daqEnumeration) core type | ||
| * from C language (enum ComponentStutesTypeEnum). | ||
| * Warning: These types of conversions require prior knowledge of | ||
| * the enumeration structure and its definition in C. For conversion | ||
| * from C to openDAQ a pointer to the TypeManager is needed because | ||
| * of the way openDAQ enumeration is implemented. | ||
| */ | ||
| enum daqExample_ComponentStatusTypeEnum daqExample_fromDaqCompStatusTypeEnum(daqEnumeration* daq) | ||
| { | ||
| int64_t intValue = -1; | ||
| daqEnumeration_getIntValue(daq, &intValue); | ||
|
|
||
| return intValue; | ||
| } | ||
|
|
||
| daqEnumeration* daqExample_toCompStatusTypeEnum(enum daqExample_ComponentStatusTypeEnum native, daqTypeManager* typeManager) | ||
| { | ||
| daqEnumeration* daq = NULL; | ||
| daqInteger* valueInt = exdaq_toDaqInteger(native); | ||
| daqString* valueName = exdaq_toDaqString("ComponentStatusType"); | ||
|
|
||
| daqEnumeration_createEnumerationWithIntValue(&daq, valueName, valueInt, typeManager); | ||
|
|
||
| daqReleaseRef(valueName); | ||
| daqReleaseRef(valueInt); | ||
| return daq; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| daqInstance* simulatorInstance = NULL; | ||
| setupSimulator(&simulatorInstance); | ||
| daqExmaple_addCustomTypes(simulatorInstance); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo. |
||
|
|
||
| daqInstance* instance = NULL; | ||
| daqDevice* simulator = NULL; | ||
| addSimulator(&simulator, &instance); | ||
|
|
||
| daqContext* context = NULL; | ||
| daqComponent_getContext((daqComponent*)simulator, &context); | ||
| daqTypeManager* typeManager = NULL; | ||
| daqContext_getTypeManager(context, &typeManager); | ||
|
|
||
| enum daqExample_ComponentStatusTypeEnum enumStatusType = daqExample_ComponentStatusType_Error; | ||
| daqEnumeration* daqEnum = daqExample_toCompStatusTypeEnum(enumStatusType, typeManager); | ||
| enum daqExample_ComponentStatusTypeEnum enumStatusType2 = daqExample_fromDaqCompStatusTypeEnum(daqEnum); | ||
|
|
||
| if (enumStatusType == enumStatusType2) | ||
| printf("Structs are the same after transforming them to and from openDAQ.\n"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enumeration, not struct. |
||
| else | ||
| printf("Structs are different!\n"); | ||
|
|
||
| struct daqExample_Coordinates nativeCoordinates = {4, 4, 4}; | ||
| daqStruct* tempStruct = daqExample_toDaqCoordinates(nativeCoordinates, typeManager); | ||
| struct daqExample_Coordinates nativeCoordinates2 = daqExample_fromDaqCoordinates(tempStruct); | ||
|
|
||
| if (nativeCoordinates.x == nativeCoordinates2.x && | ||
| nativeCoordinates.y == nativeCoordinates2.y && | ||
| nativeCoordinates.z == nativeCoordinates2.z) | ||
| printf("Enums are the same after transforming them to and from openDAQ.\n"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Struct, not enum. |
||
| else | ||
| printf("Enums are different!\n"); | ||
|
|
||
| daqReleaseRef(typeManager); | ||
| daqReleaseRef(tempStruct); | ||
|
|
||
| daqReleaseRef(simulator); | ||
| daqReleaseRef(instance); | ||
| daqReleaseRef(simulatorInstance); | ||
|
|
||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Example that demonstrates conversions between native C types | ||
| * and their openDAQ equvalents. | ||
| */ | ||
| #include <daq_c_conversions.h> | ||
|
|
||
| int main() | ||
| { | ||
| // Integer example | ||
| int64_t i = 10; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why ijklmn? Especially when used for different type variables. Use representative names. |
||
| daqInteger* daqIn = exdaq_toDaqInteger(i); | ||
| int64_t i2 = daqExample_fromDaqInteger(daqIn); | ||
| printf("Integer is equal: %s\n", i == i2 ? "True": "False"); | ||
| daqReleaseRef(daqIn); | ||
|
|
||
| // Float example | ||
| double j = 1.0; | ||
| daqFloatObject* daqFl = exdaq_toDaqFloat(j); | ||
| double j2 = exdaq_fromDaqFloat(daqFl); | ||
| printf("Float is equal: %s\n", j == j2 ? "True" : "False"); | ||
| daqReleaseRef(daqFl); | ||
|
|
||
| // String example | ||
| char* k = "check"; | ||
| daqString* daqStr = exdaq_toDaqString(k); | ||
| char* k2 = exdaq_fromDaqString(daqStr); | ||
| printf("String is equal: %s\n", strcmp(k, k2) == 0 ? "True" : "False"); | ||
| daqReleaseRef(daqStr); | ||
|
|
||
| // Bool example | ||
| uint8_t l = True; | ||
| daqBoolean* daqBl = exdaq_toDaqBoolean(l); | ||
| uint8_t l2 = exdaq_fromDaqBoolean(daqBl); | ||
| printf("Boolean is equal: %s\n", l == l2 ? "True" : "False"); | ||
| daqReleaseRef(daqBl); | ||
|
|
||
| // Complex Number example | ||
| struct exdaq_ComplexNumber m = { 1,5 }; | ||
| daqComplexNumber* daqComplex = exdaq_toDaqComplex(&m); | ||
| struct exdaq_ComplexNumber m2 = exdaq_fromDaqComplex(daqComplex); | ||
| printf("Complex Number is equal: %s\n", ((m.imaginary == m2.imaginary) && (m.real == m2.real)) ? "True" : "False"); | ||
| daqReleaseRef(daqComplex); | ||
|
|
||
| // Range example | ||
| struct daqExample_Range n = { 1,10 }; | ||
| daqRange* daqRng = exdaq_toDaqRange(n); | ||
| struct daqExample_Range n2 = exdaq_fromDaqRange(daqRng); | ||
| printf("Range is equal: %s\n", ((n.max == n2.max) && (n.min == n2.min)) ? "True" : "False"); | ||
| daqReleaseRef(daqRng); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Example that show how to properly display all relevant attributes and | ||
| * metadata in properties. | ||
| */ | ||
| #include <daq_property_utils.h> | ||
|
|
||
| void printPropertyTree(daqPropertyObject* propertyObject) | ||
| { | ||
| daqList* visibleProperties = NULL; | ||
| daqPropertyObject_getVisibleProperties(propertyObject, &visibleProperties); | ||
|
|
||
| daqSizeT count = 0; | ||
| daqList_getCount(visibleProperties, &count); | ||
|
|
||
| for (daqSizeT i = 0; i < count; i++) | ||
| { | ||
| daqBaseObject* listItem = NULL; | ||
| daqProperty* property = NULL; | ||
|
|
||
| daqList_getItemAt(visibleProperties, i, &listItem); | ||
| daqQueryInterface(listItem, DAQ_PROPERTY_INTF_ID, &property); | ||
| daqReleaseRef(listItem); | ||
|
|
||
| daqCoreType valueType = daqCtUndefined; | ||
| daqProperty_getValueType(property, &valueType); | ||
|
|
||
| daqBaseObject* propertyValue; | ||
| daqProperty_getValue(property, &propertyValue); | ||
|
|
||
| printPropertyMetadata(property); | ||
|
|
||
| if (valueType == daqCtObject) | ||
| { | ||
| printf("---\n"); | ||
| daqPropertyObject* childPropertyObject = NULL; | ||
| daqQueryInterface(propertyValue, DAQ_PROPERTY_OBJECT_INTF_ID, &childPropertyObject); | ||
| printPropertyTree(childPropertyObject); | ||
| printf("---\n\n"); | ||
| daqReleaseRef(childPropertyObject); | ||
| } | ||
| else | ||
| { | ||
| printf("- Value: "); | ||
| printPropertyValueOrDefault(property, False); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As said above, should use the |
||
| printf("\n"); | ||
| } | ||
|
|
||
| daqReleaseRef(propertyValue); | ||
| daqReleaseRef(property); | ||
| } | ||
|
|
||
| daqReleaseRef(visibleProperties); | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| daqInstance* simulatorInstance = NULL; | ||
| setupSimulator(&simulatorInstance); | ||
|
|
||
| daqInstance* instance = NULL; | ||
| daqDevice* simulator = NULL; | ||
| addSimulator(&simulator, &instance); | ||
|
|
||
| printPropertyTree((daqPropertyObject*) simulator); | ||
|
|
||
| daqReleaseRef(simulator); | ||
| daqReleaseRef(instance); | ||
| daqReleaseRef(simulatorInstance); | ||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing defined in this file should have a
exdaq_prefix. This is purely an example, not meant to be reused. Remove the prefix from the functions defined here (the used enums and structs from the header of course keep the prefix).