06-04-2012 10:23 AM
06-04-2012 04:20 PM
So i found this procedure in vb by Agilent that is suppose to do the thing
but the problem here is that with IO.Read(4) , the bytes i recieve in a byte array aren't coming right , first byte is always wrong , rest of them are fine but with reverse order. for e.g if i get 10, 70, 2, 0 when i read a single reading from instrument. if i divide the reading from instrument by scale factor , it's give the DINT value and if i convert that to byte array , it gives 110(first byte changed),0,2,70(rest order swaped)..what's going on here? ..even using this is not helping ..Am i doing something wrong in the configuration?..
Private Sub cmdMeasureNorm_Click() Dim readByte() As Byte Dim rdg() As Long Dim reading() As Double Dim i As Integer Dim iscale As String Dim numReadings As Integer numReadings = txtReadings.Text ReDim reading(numReadings) ReDim rdg(numReadings) timeResult.Text = "" txtResults.Text = "" timeResult.Refresh txtResults.Refresh StartTimer With DMM .WriteString "PRESET NORM" 'TARM AUTO, TRIG SYN, DCV AUTORANGE 'DINT good for 5-1/2 or more digits .WriteString "OFORMAT DINT" 'FAST AND ACCURATE - 4-BYTE INTEGERS .WriteString "NRDGS 15, SYN" '15 READINGS PER TRIGGER, SYN SAMPLE EVENT For i = 1 To numReadings readByte = .IO.Read(4) 'SYN EVENT, 4-bytes per DINT value 'build 4-byte long values If readByte(0) > 127 Then 'negative rdg(i) = CLng(-2147483648#) + (readByte(0) - CLng(128)) * CLng(16777216) _ + readByte(1) * CLng(65536) _ + readByte(2) * CLng(256) + readByte(3) Else 'positive rdg(i) = readByte(0) * CLng(16777216) + readByte(1) * CLng(65536) _ + readByte(2) * CLng(256) + readByte(3) End If Next i 'get instrument scale value and multiply 'with all long values to get instrument measurement .WriteString "ISCALE?" 'scale factor for DINT format iscale = .ReadString For i = 1 To numReadings reading(i) = Round((rdg(i) * Val(iscale)), 6) Next i timeResult.Text = EndTimer 'readings in hand timeResult.Refresh 'output to textbox For i = 1 To numReadings txtResults.SelText = i & ": " & Str$(reading(i)) & " volts DC" & vbCrLf Next i End With End Sub
06-05-2012 10:06 AM
Not anything related to NI. Contact Agilent.