Task
Two working pieces shall be measured in parallel using time-triggered dynamic measurement. Because of the different characteristics of the workiing pieces, the first one must be sampled at 4.000 samples/s, for the second one a sample rate of 1.000 samples/s is sufficient.
The measurement channels T1, T2, T3 and T9 are required for the first working piece.
The measurement channles T2, T6, T7, T8, T10, T11 and T12 are required for the second working piece.
Both dynamic measurements shall be started simultaneously. The first measurement takes 2,5 seconds. The second measurement shall be stopped after 5000 measurement values / channel have been sampled.
Example-Code
// Write channel list 1 using the channels T1, T2, T3 and T9.
// It will be used for the first dynamic measurement.
ansiString = “#1;T1;T2;T3;T9#”;
WriteCommandStr(opcWCL, ansiString);
if (ansiString != “#0#”) return -101; // An error occured: cancel starting measurement
// Write channel list 2 using the channels T5, T6, T7, T8, T10, T11 and T12.
// It will be used for the second dynamic measurement.
ansiString = “#2;T2;T6;T7;T8;T10;T11;T12#”;
WriteCommandStr(opcWCL, ansiString);
if (ansiString != “#0#”) return -201; // An error occured: cancel starting measurement
// Define trigger 1, which will be used for the first dynamic measurement.
// TriggerNo 1; time-triggered; * = no input channel required; divisor = 1;
// interval = 0.25ms (-> 4000 values/s); start = 0ms; end = 2500ms
ansiString = “#1;T;*;1;0.25;0;2500#”;
WriteCommandStr(opcDT, ansiString);
if (ansiString != “#0#”) return -102; // An error occured: cancel starting measurement
// Define trigger 2, which will be used for the second dynamic measurement.
// TriggerNo 2; time-triggered; * = no input channel used; divisor = 1;
// interval = 1ms (-> 1000 values/s); start = 0ms; end: * = no end defined
ansiString = “#2;T;*;1;1;0;*#”;
WriteCommandStr(opcDT, ansiString);
if (ansiString != “#0#”) return -202; // An error occured: cancel starting measurement
// Define dynamic measurement 1
// TriggerNo 1; channel list 1; dyn. measurement active;
// number of samples: * = unlimited
ansiString = “#1;1;1;*#”;
WriteCommandStr(opcDDM1, ansiString);
if (ansiString != “#0#”) return -103; // An error occured: cancel starting measurement
// Define dynamic measurement 2:
// TriggerNo 2; channel list 2; dyn. measurement active;
// number of samples: 5000
ansiString = “#2;2;1;5000#”;
WriteCommandStr(opcDDM2, ansiString);
if (ansiString != “#0#”) return -203; // An error occured: cancel starting measurement
// Setup data transfer channel for dynamic measurement values
result = MSC_SetupExtendedDynamicChannel(pDevice, opcRDM1, 4, 1, NULL);
if (result != MSC_STATUS_SUCCESS) return -104;
// Allocate 4 buffers, each with 2,5s * 4000 samples/s * 4 Bytes/sample = 40000 Bytes
// for the measurement values of the first dynamic measurement.
// Assign these buffers to the MscDll.
for (i = 0; i < 4; i++) {
bufDyn1[i] = malloc(40000);
result = MSC_AttachSubChannelBuffer(pDevice, opcRDM1, i, 40000, &bufDyn1[i]);
if (result != MSC_STATUS_SUCCESS) return -105;
}
// Setup data transfer channel for dynamic measurement values
result = MSC_SetupExtendedDynamicChannel(pDevice, opcRDM2, 7, 1, NULL);
if (result != MSC_STATUS_SUCCESS) return -204;
// Allocate 7 buffers, each with 5000 * 4 Bytes = 20000 Bytes
// for the measurement values of the second dynamic measurement.
// Assign these buffers to the MscDll.
for (i = 0; i < 7; i++) {
bufDyn2[i] = malloc(20000);
result = MSC_AttachSubChannelBuffer(pDevice, opcRDM2, i, 20000, &bufDyn2[i]);
if (result != MSC_STATUS_SUCCESS) return -205;
}
// Activate trigger 1. This will start the first dynamic measurement.
ansiString = “#1#”;
WriteCommandStr(opcAT, ansiString);
if (ansiString != “#0#”) return -106; // An error occured: cancel starting measurement
// Activate trigger 2. This will start the second dynamic measurement.
ansiString = “#2#”;
WriteCommandStr(opcAT, ansiString);
if (ansiString != “#0#”) return -206; // An error occured: cancel starting measurement
// Wait until the dynamic measurements are finished.
do {
result = MSC_GetPosition(pDevice, opcRDM1, &nSamplesDyn1);
if (result != MSC_STATUS_SUCCESS) return -107;
result = MSC_GetPosition(pDevice, opcRDM2, &nSymplesDyn2);
if (result != MSC_STATUS_SUCCESS) return -207;
Sleep(50); // Take a break for 50 ms
} while ( (nSamplesDyn1 < 10000) && (nSamplesDyn2 < 5000) );
// Inactivate trigger 1
ansiString = “#1#”;
WriteCommandStr(opcIT, ansiString);
// Inactivate trigger 2
ansiString = “#2#”;
WriteCommandStr(opcIT, ansiString);
// All measurement values are available now and can be evaluated.
Notes
oIn this example, both dynamic measurements are started simultaneously. They can also be started independently.
oThe time-triggered measurements are stopped in different ways: measurement 1 is stopped after a certain time, measurement 2 is stopped after a certain number of samples have been taken. Using the time-triggered dynamic measurement, both methods are equal.
In reality, one would use either of these methods for both measurements.
oThe do-while-loop is finished, if all dynamic measurements are finished. Since the first dynamic measurement stops earlier, it would be possible to evaluate its measurement values earlier.
oMeasurement channel T2 is used in both dynamic measurements. This is not a problem, since both dynamic measurements use an independent recording of the measurement values.