Jump to content
  • 0

cbWinBufToArray Sample Order for multi-channel scan (USB-1208LS)


TekLord

Question

Is there a document that describes the sample order when transferring data from the Windows buffer to an array?

My VB6 application appears to work correctly when using a single channel. However, when I select two channels, I do not know the sample alignment in the VB array.

 

 

Private Sub cmd_StartBgnd_Click()

'NOTE: Must call MCCReset prior to starting measurements
    
    Dim CBCount As Long
    Dim Options As Long
    Dim CurCount As Long, CurIndex As Long
    Dim Status As Integer
    Dim Offset As Long
    Dim i As Integer
    Dim EngUnits As Single
    Dim indexMem As Integer
    Dim sTemp As String
    
    Me.cmd_StartBgnd.Enabled = False
    Me.cmd_StartBgnd.Visible = False
    Me.cmd_StopConvert.Enabled = True
    Me.cmd_StopConvert.Visible = True
    
    Me.lbl_ShowStat.Caption = "Running"
    
    CBCount = TotalPoints                                   'samples collected per channel is equal to CBCount / (HighChan – LowChan + 1).
   
    'collect data in BACKGROUND continuously
    Options = BACKGROUND + CONTINUOUS + CONVERTDATA '+ SCALEDATA
    ULStat = cbAInScan(MCC.BoardNum, LowChan, HighChan, CBCount, CBRate, CBRange, MemHandle, Options)
    If ULStat <> 0 Then Stop
    
    bRun = True
    
    indexMem = 0
    Offset = 0                                          'CurIndex start of latest channel scan in MemHandle buffer
    Do
        ULStat = cbGetStatus(MCC.BoardNum, Status, CurCount, CurIndex, AIFUNCTION)
        If ULStat <> 0 Then Exit Do
        
        'curindex increments by PacketSize (64 samples)
        If ((CurIndex > HighChan) And (CurIndex <> indexMem)) Then
            indexMem = CurIndex
            
            'transfer samples from the buffer to the array starting with offset in the buffer
            ULStat = cbWinBufToArray(MemHandle&, ADData(Offset), Offset, PacketSize)
            If ULStat <> 0 Then Exit Do
            
            'update textbox for diagnostic purposes
            Select Case Offset
                Case 0
                    sTemp = ""      'clear the text
            End Select
            sTemp = sTemp & "Index: " & CurIndex & " Offset: " & Offset & vbCrLf
            sTemp = sTemp & "Start: " & Offset & " Stop: " & Offset + (PacketSize - 1) & vbCrLf
            For i = Offset To (Offset + PacketSize - 4) Step 4
                sTemp = sTemp & i & " " & ADData(i) & " " & ADData(i + 1) & " " & ADData(i + 2) & " " & ADData(i + 3) & vbCrLf
            Next i
            Me.txt_ScanData(0).Text = sTemp
            sTemp = sTemp & vbCrLf
        
            'keep track of the pointer
            Offset = Offset + PacketSize
            If Offset > (TotalPoints - 1) Then Offset = 0

        End If

        DoEvents
        If (Not bRun) And (Offset = 0) Then Exit Do     'exit polling loop if stop button pressed and all packets reported
    Loop

    ULStat = cbStopBackground(MCC.BoardNum, AIFUNCTION) 'stop the measurement
    
    If ULStat <> 0 Then Stop
    
End Sub

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

The minimum you should make the data buffer is packet size (64) times the number of channels. It's a one-dimensional buffer, and the channels are interleaved one after the other. If you fail to do this, you could get channel rotation. For example, channel 0 shows up as channel 1. 

Link to comment
Share on other sites

  • 0
Posted (edited)

JRys,

I really appreciate your assistance. Please let me know if you see any obvious mistakes.

== Allocating Buffer and VB6 Array ==

    NumChans = (HighChan - LowChan) + 1                                             'number of channels to be scanned (1 - 0 + 1 = 2)
    TotalPoints = NumChans * PacketSize * NumBuffers                         'channels * packet size * buffers (2 * 64 * 2 = 256)
    MemHandle = cbWinBufAlloc(TotalPoints)                                           'create the buffer (256 samples)

    ReDim ADData(TotalPoints - 1)                                                              'VB6 array (256 samples, 0-255)

== Question ==

When reading the documentation related to cbGetStatus, CurIndex is supposed to show "the index to the start of the last completed channel scan ..."

When I am scanning a single channel, CurIndex sequences as 63, 127, 191...

But when I scan two channels, CurIndex sequences as 62, 126, 190...

I can't figure this out. My goal is to transfer 64 samples (1 packet) from the buffer to the VB6 array every 64 samples. The CurIndex variance is causing me problems. As an alternative solution, I have been monitoring CurCount. (When CurCount increments by 64 I then transfer from the buffer to the array.) Any ideas?

Finally, for cbWinBufToArray, can the first point of the VB6 array be specified as "DataArray%"? I would like to use 8 packets of data to "fill" a 512 sample array. Can I specify DataArray as VB6(0), VB6(64), ... ? I guess I want to know if the function "points" to the starting point of the VB6 array element specified. It "seems" to work, but I don't know if the data is truly valid.

2024-06-06_14-38-06.jpg

2024-06-06_14-39-05.jpg

Edited by TekLord
Added Screenshots
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...