What is wrong with my code
Posted 30 November 2012 - 10:49 PM
Posted 03 December 2012 - 02:10 PM
Also, if you haven't done so take a look at the Stream Mode pseudocode in the User's Guide as it provides more documentation on streaming with the UD driver than the Delphi example:
Posted 04 December 2012 - 03:12 AM
Posted 04 December 2012 - 02:10 PM
Posted 07 December 2012 - 04:26 PM
Posted 07 December 2012 - 06:52 PM
Error 7 is LJE_UNABLE_TO_CONFIG_STREAM, error = 4 is LJE_UNABLE_TO_START_STREAM and error = 5 is LJE_UNABLE_TO_STOP_STREAM. I would expect error 7 for your stream config GoOne or results error checks and error 4 for the "eGet(lngHandle, LJ_ioSTART_STREAM, 0, dblValue, 0)".
I looked over your code again and it looks like I missed a problem with your "ePut(lngHandle, LJ_ioPUT_ANALOG_ENABLE_PORT, 0, 65536, 16)" call. I think you meant "ePut(lngHandle, LJ_ioPUT_ANALOG_ENABLE_PORT, 0, 65535, 16)" to set FIO0-15 to analog inputs. A value of 65536 is 10000000000000000 in binary, so you are setting the FIO lines to digital currently. This is probably the cause of your problem of the stream not starting since you are trying to stream FIO lines as analog inputs but they are configured as digital.
As for the size of the UD driver's buffer, it is the size you set it to in your LJ_chSTREAM_BUFFER_SIZE AddRequest. The value you set is the number of samples the UD driver will buffer. It is possible to read more that 975 samples (U3 hardware's stream buffer is 512-984 samples) in one UD stream call since the UD driver is collecting stream data from the U3 in the background and appending it to its software buffer. Section 4.3.7 of the User's Guide (the link in my first post) describes all of this further.
>So if I pass my large buffer and do a single request of say 500,000 scans will it stream the whole lot into my large buffer.?
If you are going to do that many scans it might be better to read smaller scans and add them to your large buffer. You can try to read that many and see how it works out. To help prevent stream buffer overflows make sure your LJ_chSTREAM_BUFFER_SIZE is larger than your stream scan reads and that you read stream scans at a fast enough rate. Also, note that 1 scan is numChannels samples.
Regarding LJ_chSTREAM_WAIT_MODE settings, you currently have it set to LJ_swNONE which will read the amount of scans currently in the UD driver's stream buffer up to the numScansRequested you passed. The Sleep delay lets the stream buffer build up. If you use the LJ_swSLEEP setting, the stream read call will block until all numScansRequested scans are available or will timeout with no scans. You do not need to use the Sleep calls with this setting.
Posted 08 December 2012 - 04:27 AM
Posted 09 December 2012 - 04:03 AM
For anyone following this post here is the code using my first guess values.
It will be tidied up later.
DataArray : array[1..1000000] of Double; // 50,000/Sec x 20 Sec.
ReadArray : array[1..20000] of double; // Reads 1,000 Scans from the Driver buffer from up to 16 ch.
// A Scan is a read of all ActiveChannels.
// Give the Driver a large buffer.
lngErrorcode := AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSTREAM_BUFFER_SIZE, 50000, 0, 0);
// Configure reads to retrieve a fixed amount at a time (LJ_swSLEEP).
lngErrorcode := AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSTREAM_WAIT_MODE, LJ_swSLEEP, 0, 0);
// I will request 1,000 scans per loop. A Scan is all ActiveChannels.
// 50000/(1000 * ActiveChannels) = Loops per second.
// * Form1.SpinEditLogSeconds.value = Total Loops.
// Ceil = Round Up the number of loops.
n := 1; // The LoggedData index
ii := 0;
while ii < Ceil((50000/(1000 * ActiveChannels)) * Form1.SpinEditLogSeconds.value) do
// Request 1,000 scans. The amount of data = 1,000 x ActiveChannels
numScans := 1000; numScansRequested := numScans;
// Get the 1,000 scans from the Driver Buffer into the ReadArray
lngErrorcode := eGet(lngHandle, LJ_ioGET_STREAM_DATA, LJ_chALL_CHANNELS, numScansRequested, @ReadArray);
// Append the valid part of the ReadArray to the DataArray
for a := 1 to (1000 * ActiveChannels) do
DataArray[n] := ReadArray[a];
n := n +1;
ii := ii +1;
Because the number of loops is rounded up, the data will be logged slightly more than the Form1.SpinEditLogSeconds.value.
That is ok because the 2Sec, 5Sec, ... 20Sec are only nominal periods of logging.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users