Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Cr1000 and HADCP column shift


parthi Mar 10, 2020 03:16 PM

Hi Team, we have  a TRDI HADCP connected to a cr1000 logger through csio port. The issue is that when we start adcp,  first few reading are collected properly but then the data columns are getting shifted and also its collecting rubbish datas. We suspected the adcp and changed with brand new one and also replaced the cable but the problem persists. It would be great if you help me solve this issue.Thanks


JDavis Mar 10, 2020 09:12 PM

This is my example code for the PD23 format from a HADCP. That covers all the information most customers want.

 

Public CMData(13)
Alias CMData(2) = HighVolume
Alias CMData(3) = LowVolume
Alias CMData(4) = FaultCount
Alias CMData(5) = StageA
Alias CMData(6) = StageP
Alias CMData(7) = FlowRate
Alias CMData(8) = MeanVelocity
Alias CMData(9) = Area
Alias CMData(10) = Temperature
Alias CMData(11) = Pitch
Alias CMData(12) = roll
Alias CMData(13) = HADPC_Battery
Dim RawString As String * 500
Public NBytesReturned



'Main Program
BeginProg
  SerialOpen (ComRS232,9600,3,0,500) 'Change to match sensor serial configuration
  Scan (1,Sec,0,0)

    SerialInRecord (ComRS232,RawString,&h5052,0,&h0D,NBytesReturned,00)
    'Note that NBytesReturned is 0 if no data came in
    SplitStr (CMData(),RawString,",",13,4)

  NextScan
EndProg

 

If you want all the cell data, you need to set the ADCP to the PD0 format. Here is the example code for that format.

 

'CR1000 Series Datalogger

'RDI PD0 format reference program

Const MaxCellCount = 30 'Number of cells configured in sensor
Const MaxEnsembleLength = 20000

Public PTemp, batt_volt
Dim EnsembleString As String * MaxEnsembleLength
Dim i As Long, k As Long
Public BytesAvailable As Long
Public CalculatedChecksum As Long, EnsembleCheck As Long


Public EnsembleStart As Long, EnsembleLength As Long
Public VariableLeaderStart As Long, FixedLeaderStart As Long, VelocityStart As Long, CorrelationStart As Long
Public EchoIntenseStart As Long, PercentGoodStart As Long, StatusProfileStart As Long
Public NewEnsemble As Boolean, NeedMoreBytes As Boolean, EnsembleValid As Boolean

'Fixed Leader Variables
Public NumberOfCells As Long, RangeCellLength As Long, BlankAfterTransmit As Long
Public LowCorrThresh As Long, ErrorVelocityMax As Long, Bin1Distance As Long
Public FalseTargetThreshold As Long

'Variable Leader Variables
Public EnsembleNumber As Long, BITResult As Long, SpeedOfSound As Long
Public DepthOfTranducer As Long, Pitch As Long, Roll As Long
Public Salinity As Long, TransducerTemp As Long, BITHex As String

'Data Types
Public NumberDataTypes As Long, DataTypeOffset(13) As Long, DataTypeID(13) As Long

'Velocity Values
Public Velocity1(MaxCellCount) As Long,  Velocity2(MaxCellCount) As Long, Velocity3(MaxCellCount) As Long

'Quality Values
Public Correlation1(MaxCellCount) As Long,  Correlation2(MaxCellCount) As Long, Correlation3(MaxCellCount) As Long
Public Echo1(MaxCellCount) As Long,  Echo2(MaxCellCount) As Long, Echo3(MaxCellCount) As Long
Public PercentGood1(MaxCellCount) As Long,  PercentGood2(MaxCellCount) As Long, PercentGood3(MaxCellCount) As Long

Dim ProcessVelocity As Boolean, ProcessCorrelation As Boolean, ProcessEcho As Boolean
Dim ProcessPercentGood As Boolean, ProcessFixedLeader As Boolean, ProcessVariableLeader As Boolean

'Define Data Tables
DataTable (Test,1,1000)
  DataInterval (0,15,Sec,10)
  Minimum (1,batt_volt,FP2,0,False)
  Sample (1,PTemp,FP2)
EndTable

Sub EnsembleShiftUp
  'Shifts entire buffer up, so that EnsembleStart is now 1
  MoveBytes (EnsembleString,0,EnsembleString,EnsembleStart-1,MaxEnsembleLength - EnsembleStart + 1)
  EnsembleStart = 1
EndSub

Sub BufferShiftUp(NumberToShift As Long)
  'Shifts entire buffer up by number of bytes
  MoveBytes (EnsembleString,0,EnsembleString,NumberToShift,MaxEnsembleLength - NumberToShift)
EndSub

Function SignedInt16(tempDec As Long) 'Converts two byte long to 16bit signed
  If tempDec>32767 Then
    tempDec=tempDec-65536
  EndIf
  SignedInt16=tempDec
EndFunction

'Main Program
BeginProg
  SerialOpen (COMRS232,-115200,3,0, MaxEnsembleLength *2 + 1 ) 'Be sure to open in binary format
  Scan (1,Sec,0,0)
    PanelTemp (PTemp,250)
    Battery (batt_volt)

    If IfTime (0,2,Min) Then
      SerialOutBlock (COMRS232,"cs" & CHR(13) & CHR(10),4)
    EndIf
    If IfTime (1,2,Min) Then  'Change interval to coincide with sensor
      BytesAvailable = SerialInChk(ComRS232)
      SerialInBlock (COMRS232,EnsembleString,BytesAvailable)

      EnsembleStart = 0
      For i = 1 To BytesAvailable 'Find start of Ensemble
        If ASCII(EnsembleString(1,1,i)) = 127 Then  '&h7F is 127
          If ASCII(EnsembleString(1,1,i+1)) = 127 Then
            EnsembleStart    = i
            NewEnsemble = true
            ExitFor
          EndIf
        EndIf
      Next i  'next byte in buffer

    EndIf

    If NewEnsemble Then 'check ensemble data validity
      EnsembleValid = false
      If BytesAvailable >=6 Then 'enough bytes to read length
        EnsembleLength = ASCII(EnsembleString(1,1,EnsembleStart + 3)) * 256 +  ASCII(EnsembleString(1,1,EnsembleStart + 2))
        NumberDataTypes = ASCII(EnsembleString(1,1,EnsembleStart + 5))

        If  BytesAvailable >= (EnsembleStart + EnsembleLength + 1) Then 'Enough length for whole ensemble
          NeedMoreBytes = false

          'Checksum validation
          EnsembleCheck =  ASCII(EnsembleString(1,1,EnsembleStart + EnsembleLength + 1)) * 256 +  ASCII(EnsembleString(1,1,EnsembleStart  + EnsembleLength))
          CalculatedChecksum = 0
          For i = 0 To (EnsembleLength - 1)
            CalculatedChecksum = (CalculatedChecksum + ASCII(EnsembleString(1,1,EnsembleStart + i)) ) MOD 65536
          Next i  'Byte of ensemble
          If CalculatedChecksum = EnsembleCheck Then
            EnsembleValid = true

          Else
            EnsembleValid = false
          EndIf 'checksums equal

        Else
          NeedMoreBytes = true
          'Catch invalid ensemble lengths
          If  EnsembleLength +2 > MaxEnsembleLength Then
            Call BufferShiftUp(EnsembleStart)
          EndIf
        EndIf  'Enough bytes

      EndIf 'bytes available for header


      NewEnsemble = false
    EndIf 'end ensemble data processing





    If EnsembleValid  Then 'process data from ensemble
      For i = 1 To NumberDataTypes
        DataTypeOffset(i) =   ASCII(EnsembleString(1,1,EnsembleStart + i *2 + 4  )) + 256 *  ASCII(EnsembleString(1,1,EnsembleStart + i *2 + 5  ))
        DataTypeID(i) =  ASCII(EnsembleString(1,1,EnsembleStart + DataTypeOffset(i) )) + 256 *  ASCII(EnsembleString(1,1,EnsembleStart + DataTypeOffset(i) + 1))

        If DataTypeID(i) = 256 Then
          'Velocity Data located
          VelocityStart = EnsembleStart + DataTypeOffset(i)
          ProcessVelocity = true
        EndIf  'End ID is velocity

        If DataTypeID(i) = 512 Then
          'Correlation Data located
          CorrelationStart = EnsembleStart + DataTypeOffset(i)
          ProcessCorrelation = true
        EndIf  'End ID is velocity

        If DataTypeID(i) = 768 Then
          'Echo Data located
          EchoIntenseStart = EnsembleStart + DataTypeOffset(i)
          ProcessEcho = true
        EndIf  'End ID is velocity

        If DataTypeID(i) = 1024 Then
          'Percent Good Data located
          PercentGoodStart = EnsembleStart + DataTypeOffset(i)
          ProcessPercentGood = true
        EndIf  'End ID is velocity

        If DataTypeID(i) = 0 Then
          'Fixed Leader Data located
          FixedLeaderStart = EnsembleStart + DataTypeOffset(i)
          ProcessFixedLeader = true
        EndIf  'End ID is velocity

        If DataTypeID(i) = 128 Then
          'Variable Leader Data located
          VariableLeaderStart = EnsembleStart + DataTypeOffset(i)
          ProcessVariableLeader = true
        EndIf  'End ID is velocity

      Next i   'next datatype
    EndIf  'ensemble valid




    If ProcessVelocity Then
      For i = 1 To MaxCellCount
        Velocity1(i) = ASCII(EnsembleString(1,1,VelocityStart + i*8 -6)) + 256 *  ASCII(EnsembleString(1,1,VelocityStart  + i*8 -5))
        Velocity1(i) = SignedInt16(Velocity1(i))

        Velocity2(i) = ASCII(EnsembleString(1,1,VelocityStart + i*8 -4)) + 256 *  ASCII(EnsembleString(1,1,VelocityStart  + i*8 -3))
        Velocity2(i) = SignedInt16(Velocity2(i))

        Velocity3(i) = ASCII(EnsembleString(1,1,VelocityStart + i*8 -2)) + 256 *  ASCII(EnsembleString(1,1,VelocityStart  + i*8 -1))
        Velocity3(i) = SignedInt16(Velocity3(i))
      Next i  'next cell
      ProcessVelocity = false
    EndIf

    If ProcessFixedLeader Then
      NumberOfCells = ASCII(EnsembleString(1,1,FixedLeaderStart + 9 ))
      RangeCellLength = ASCII(EnsembleString(1,1,FixedLeaderStart + 12 )) + 256 * ASCII(EnsembleString(1,1,FixedLeaderStart + 13 ))
      BlankAfterTransmit = ASCII(EnsembleString(1,1,FixedLeaderStart + 14 )) + 256 * ASCII(EnsembleString(1,1,FixedLeaderStart + 15 ))
      LowCorrThresh = ASCII(EnsembleString(1,1,FixedLeaderStart + 17 ))
      ErrorVelocityMax =  ASCII(EnsembleString(1,1,FixedLeaderStart + 20 )) + 256 * ASCII(EnsembleString(1,1,FixedLeaderStart + 21 ))
      FalseTargetThreshold = ASCII(EnsembleString(1,1,FixedLeaderStart + 38 ))
      ProcessFixedLeader = false
    EndIf

    If ProcessVariableLeader Then
      EnsembleNumber = ASCII(EnsembleString(1,1,VariableLeaderStart + 2 )) + 256 * ASCII(EnsembleString(1,1,VariableLeaderStart + 3 ))
      BITResult = ASCII(EnsembleString(1,1,VariableLeaderStart + 12 )) + 256 * ASCII(EnsembleString(1,1,VariableLeaderStart + 13 ))
      BITHex =  FormatLong (BITResult,"%X")
      SpeedOfSound = ASCII(EnsembleString(1,1,VariableLeaderStart + 14 )) + 256 * ASCII(EnsembleString(1,1,VariableLeaderStart + 15 ))
      DepthOfTranducer =  ASCII(EnsembleString(1,1,VariableLeaderStart + 16 )) + 256 * ASCII(EnsembleString(1,1,VariableLeaderStart + 17 ))
      Pitch = ASCII(EnsembleString(1,1,VariableLeaderStart + 20 )) + 256 * ASCII(EnsembleString(1,1,VariableLeaderStart + 21 ))
      Roll =  ASCII(EnsembleString(1,1,VariableLeaderStart + 22 )) + 256 * ASCII(EnsembleString(1,1,VariableLeaderStart + 23 ))
      Salinity = ASCII(EnsembleString(1,1,VariableLeaderStart + 24 )) + 256 * ASCII(EnsembleString(1,1,VariableLeaderStart + 25 ))
      TransducerTemp = ASCII(EnsembleString(1,1,VariableLeaderStart + 26 )) + 256 * ASCII(EnsembleString(1,1,VariableLeaderStart + 27 ))
      ProcessVariableLeader = false
    EndIf

    If ProcessEcho Then
      For i = 1 To MaxCellCount
        Echo1(i) = ASCII(EnsembleString(1,1,EchoIntenseStart + i *4 -2))
        Echo2(i) = ASCII(EnsembleString(1,1,EchoIntenseStart + i *4 -1))
        Echo3(i) = ASCII(EnsembleString(1,1,EchoIntenseStart + i *4 ))
      Next i
      ProcessEcho = false
    EndIf

    If ProcessCorrelation Then
      For i = 1 To MaxCellCount
        Correlation1(i) = ASCII(EnsembleString(1,1,CorrelationStart + i *4 -2))
        Correlation2(i) = ASCII(EnsembleString(1,1,CorrelationStart + i *4 -1))
        Correlation3(i) = ASCII(EnsembleString(1,1,CorrelationStart + i *4 ))
      Next i
      ProcessCorrelation = false
    EndIf


    If ProcessPercentGood Then
      For i = 1 To MaxCellCount
        PercentGood1(i) = ASCII(EnsembleString(1,1,PercentGoodStart + i *4 -2))
        PercentGood2(i) = ASCII(EnsembleString(1,1,PercentGoodStart + i *4 -1))
        PercentGood3(i) = ASCII(EnsembleString(1,1,PercentGoodStart + i *4 ))
      Next i
      ProcessPercentGood = false
    EndIf


    CallTable Test
  NextScan
EndProg

 

Log in or register to post/reply in the forum.