03-07-2010 03:35 AM
Salve a tutti,
sono nuovo al mondo di VB6.
Sto scrivendo il codice in VB6 per acquisire dati da una scheda DAQPad-6015 (per ora sto utilizzando un simulatore offerto da Measurements & Automation). Il mio problema e che non riesco a capire i parametri di DAQmxReadAnalogF64. In pratica dovrei campionare ogni 0,1 sec 10 campioni. vi posto il codice
Option Explicit
Dim running As Boolean
Public Sub cm_Click()
Dim myTask As Long
Dim y As Variant
Dim data(100) As Double
DAQmxErrChk DAQmxLoadTask("voltaggioFV", myTask)
running = True
Do While running
DAQmxErrChk DAQmxReadAnalogF64(myTask, 100, 10, DAQmx_Val_GroupByChannel, data(0), 100, 100, ByVal 0&)
CWGraph1.PlotY (data)
Label1.Caption = data(0)
'Label3.Caption = data(99)
y = CWDSP1.BwLPF(data, 50, 10, 3)
CWGraph2.PlotY (y)
Timer1.Interval = 2000
Open "c:\File.txt" For Append As #1
Write #1, Time; Tab(35); data(0)
Close #1
DoEvents
Loop
DAQmxErrChk DAQmxStopTask(myTask)
DAQmxErrChk DAQmxClearTask(myTask)
Exit Sub
ErrorHandler:
DAQmxStopTask myTask
DAQmxClearTask myTask
MsgBox Err.Description
End Sub
Public Sub Timer1_Timer()
Timer1.Enabled = True
Label2.Caption = Time
Open "c:\File.txt" For Append As #1
Write #1, Time
Close #1
End Sub
Private Sub cmd_Stop_Click()
running = False
Timer1.Enabled = False
End Sub
Vi ringrazio
Buona Domenica
Andrea
03-08-2010 02:31 AM
Ciao Andrea,
puoi trovare tutte le informazioni sui parametri utilizzati dalla funzione DAQmxReadAnalogF64 nell'Help del driver DAQmx:
da Start >> Programmi >> National Instruments >> NI-DAQ >> Text based code support >> NI-DAQmx C Reference Help ed esegui una ricerca per la voce "DAQmxReadAnalogF64"
Serena
03-08-2010 03:02 AM
Grazie per la celerità nella risposta,
purtroppo la ricerca non da nessun risultato. Ho cercato su internet ma niente.
Mentre posto ti chiedo un altra cosa, io filtro il segnale in ingresso con un filtro Lowpass Butterworth. Graficando il segnale filtrato me lo inverte, ossia se il grafico del segnale va da 0 a 100 il filtro mi grafica da 100 a 0.
Grazie Serena
03-08-2010 03:45 AM - edited 03-08-2010 03:47 AM
Mi pare strano che tu non abbia trovato nulla, inserendo la voce "DAQmxReadAnalogF64" nel tab Search trovi la seguente pagina:
int32 DAQmxReadAnalogF64(TaskHandle taskHandle, int32 numSampsPerChan, float64 timeout, bool32 fillMode, float64 readArray[], uInt32 arraySizeInSamps, int32 *sampsPerChanRead, bool32 *reserved);
Reads multiple floating-point samples from a task that contains one or more analog input channels.
Input | ||||||||||
Name | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
taskHandle | TaskHandle | The task to read samples from. | ||||||||
numSampsPerChan | int32 | The number of samples, per channel, to read. The default value of -1 (DAQmx_Val_Auto) reads all available samples. If readArray does not contain enough space, this function returns as many samples as fit in readArray. NI-DAQmx determines how many samples to read based on whether the task acquires samples continuously or acquires a finite number of samples. If the task acquires samples continuously and you set this parameter to -1, this function reads all the samples currently available in the buffer. If the task acquires a finite number of samples and you set this parameter to -1, the function waits for the task to acquire all requested samples, then reads those samples. If you set the Read All Available Samples property to TRUE, the function reads the samples currently available in the buffer and does not wait for the task to acquire all requested samples. | ||||||||
timeout | float64 | The amount of time, in seconds, to wait for the function to read the sample(s). The default value is 10.0 seconds. To specify an infinite wait, pass -1 (DAQmx_Val_WaitInfinitely). This function returns an error if the timeout elapses. A value of 0 indicates to try once to read the requested samples. If all the requested samples are read, the function is successful. Otherwise, the function returns a timeout error and returns the samples that were actually read. | ||||||||
fillMode | bool32 | Specifies whether or not the samples are interleaved.
| ||||||||
arraySizeInSamps | uInt32 | The size of the array, in samples, into which samples are read. | ||||||||
reserved | bool32 * | Reserved for future use. Pass NULL to this parameter. | ||||||||
Output | ||||||||||
Name | Type | Description | ||||||||
readArray | float64 [] | The array to read samples into, organized according to fillMode. | ||||||||
sampsPerChanRead | int32 * | The actual number of samples read from each channel. |
Name | Type | Description |
---|---|---|
status | int32 | The error code returned by the function in the event of an error or warning. A value of 0 indicates success. A positive value indicates a warning. A negative value indicates an error. |
Per quanto riguarda il filtro, potrebbe dipendere dai parametri che utilizzi. In particolare che funzione usi per implementare il filtro?
03-08-2010 06:41 AM
La funzione del filtro è questa
y = CWDSP1.BwLPF(data, 50, 10, 3)
CWGraph2.PlotY (y)
Ma per quanto riguarda il DAQmxReadAnalogF64 come gestisco input contemporanei da più canali dello stesso Device all'interno dello stesso task?
Ho provato a creare tanti task quanto i canali ma se li faccio partire contemporaneamente mi stampa a schermo "Specifiche riservate".
03-08-2010 11:05 AM
Ricevi l'errore di Risorsa riservata perchè per ciascuna scheda puoi creare un solo task dello stesso tipo (un solo task di AI, uno di AO, ecc), ma all'interno del task puoi creare più canali, per esempio
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0:2","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
così crei i canali dallo 0 al 2.
Puoi trovare degli esempi di acquisizione dati in Start>> Programmi >> National Instruments >> NI DAQ >> Text-based Code support
03-08-2010 01:54 PM
Scusami ma mi sono spiegato male. Io ho un task all'interno del quale ho 4 canali fisici (2 corrente e 2 tensione). Devo creare un interfaccia in Visual Basic 6 che legge dai 4 canali e grafica i valori nella stessa frame.
Come faccio nella frame a leggere contemporaneamente dai 4 canali e scindere i valori delle correnti e tensioni per graficarli?
Grazie per l'aiuto
03-08-2010 02:46 PM
Ti allego una sorta di schema. al click sul Bottone dovrebbe leggere dai canali e graficarli (come ho postato sopra)
Buona Serata
Andrea