04-18-2014 08:59 AM
Good afternoon,
after a lot of time i'm here yet.
The problem with the PCI 6601 aren't finished in sense that i have tried a lot of solution but my sistem crashed after some acquisition.
The code that had write on Visual Basic 6 are :
'Inizializzo la scheda PCI-6601
Public Sub init_6601(NumSens As Integer)
Dim edge As DAQmxEdge1
On Error GoTo ErrorHandler
MyChannel(NumSens) = "My Channel" & NumSens 'Definisce il nome per il canale (optional)
'Creo i tre task che servono per il funzionamento del programma
DAQmxErrChk DAQmxCreateTask("", taskHandle(NumSens))
'Questa funzione serve a creare il canale dalla quale poi viene effettuata la misura
If (NumSens = 0) Then
DAQmxErrChk DAQmxCreateCIPulseWidthChan(taskHandle(NumSens), "Dev1/ctr1", MyChannel(NumSens), 0.00001, _
0.0009, DAQmx_Val_TimeUnits3_Seconds, DAQmx_Val_Edge1_Rising, "") ' DAQmx_Val_TimeUnits3_Ticks, DAQmx_Val_Edge1_Rising, "")
ElseIf (NumSens = 1) Then
DAQmxErrChk DAQmxCreateCIPulseWidthChan(taskHandle(NumSens), "Dev1/ctr2", MyChannel(NumSens), 0.00001, _
0.0009, DAQmx_Val_TimeUnits3_Ticks, DAQmx_Val_Edge1_Rising, "") 'DAQmx_Val_TimeUnits3_Seconds, DAQmx_Val_Edge1_Rising, "")
Else
DAQmxErrChk DAQmxCreateCIPulseWidthChan(taskHandle(NumSens), "Dev1/ctr3", MyChannel(NumSens), 0.00001, _
0.0009, DAQmx_Val_TimeUnits3_Seconds, DAQmx_Val_Edge1_Rising, "")
End If
DAQmxErrChk DAQmxSetReadReadAllAvailSamp(taskHandle(NumSens), False)
'Con questa funzione si sincronizza il timebase della scheda con il segnale da leggere
DAQmxErrChk DAQmxSetCIPulseWidthDigSyncEnable(taskHandle(NumSens), MyChannel(NumSens), True)
'DAQmxErrChk DAQmxSetReadOverWrite(taskHandle(NumSens), DAQmx_Val_OverwriteMode1_OverwriteUnreadSamps)
'DAQmxErrChk DAQmxCfgSampClkTiming(taskHandle(NumSens), "", 100000, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_ContSamps, 10000)
'provare queste due funzioni per aspettare che il campione sia realmente disponibile.
'La seconda èdovrebbe essere quella che da il migliore compromesso tra uso CPU e velocità.
'DAQmxErrChk DAQmxSetReadWaitMode(taskHandle(NumSens), DAQmx_Val_WaitMode_WaitForInterrupt)
'DAQmxErrChk DAQmxSetReadWaitMode(taskHandle(NumSens), DAQmx_Val_WaitMode_Yield)
'Setta il numero di campioni da acquisire ogni volta che va in lettura e
'il modo di lettura. Si è impostato "contsamps" per avere la lettura continua
'La dimensione del buffer è determinata da quel 10000 che va messo così secondo le specifiche del daqmx
DAQmxErrChk DAQmxCfgImplicitTiming(taskHandle(NumSens), DAQmx_Val_AcquisitionType_ContSamps, 10000) 'DAQmx_Val_AcquisitionType_ContSamps
'La scheda NI PCI 6601 ha soltanto un canale per il DMA (Direct Memory Access) quindi non riesco a leggere
'contemporaneamente tre task per volta. Quindi devo attivare un meccanismo diverso per la lettura
'basato sugli interrupt, ogni volta che ho una lettura automaticamente leggo il dato
DAQmxErrChk DAQmxSetCIDataXferMech(taskHandle(NumSens), MyChannel(NumSens), DAQmx_Val_DataTransferMechanism_Interrupts)
'La funzione di seguito serve semplicemente per leggere il campione più recente generato
DAQmxErrChk DAQmxSetReadRelativeTo(taskHandle(NumSens), DAQmx_Val_ReadRelativeTo_MostRecentSamp)
'La seguente funzione è complementare ad una utilizzata nell'inizializzazione e serve per impostare la lettura
'sull'ultimo campione generato
DAQmxErrChk DAQmxSetReadOffset(taskHandle(NumSens), -1)
DAQmxStartTask taskHandle(NumSens)
taskIsRunning(NumSens) = True
Exit Sub
ErrorHandler:
For i = 0 To 2
If taskIsRunning(i) = True Then
DAQmxStopTask taskHandle(i)
DAQmxClearTask taskHandle(i)
taskIsRunning(i) = False
End If
Next i
MsgBox "Error: " & Err.number & " " & Err.Description, , "Error"
End Sub
For the reading i use :
DAQmxErrChk DAQmxReadCounterF64(taskHandle(NumSens), -1, 0.5, temp(NumSens, 0), 10000, ReadSamp(NumSens), ByVal &O0)
Well, my problem are very simple, I want an continuos acquisition on three channel and the input signal's frequency that i have to measure is 1 kHz .
when i try to keep 2 channel after some cycles appears the error -200141 (buffer overwriting). Why?
The read function is called some times every ms and evry time keep out an different value, even if that are impossible because the input signal is at 1 kHz, and why the buffer fill up? What is wrong in my code?
Thanks in advance for your help
Have a nice day!!
Igor Piero Prato
04-29-2014 08:59 AM
HI Igor84,
Error 200141 occurs when the data acquisition device acquires data faster than the computer can read it from the FIFO (first-in-first-out) input buffer.
You can see this document:
Error 200141 Occurs When Doing Buffered Event Counting
http://digital.ni.com/public.nsf/allkb/83656593DCF1FB0F862570B6004D7222?OpenDocument
and this forum :
Buffer Overflow -200141
http://forums.ni.com/t5/Measurement-Studio-for-VC/Buffer-Overflow-200141/m-p/607234
I hope that these links can help you.
Regards