VB Code problem PCSU1000

Hello,

I use the following VB2008 code to control the PCSU1000:

Option Explicit On
Public Class MainForm
Dim DataBuffer1(0 To 5000) As Long
Dim DataBuffer2(0 To 5000) As Long
Dim SettingsArray(0 To 10) As Long
Private Declare Sub ReadCh1 Lib “DSOLink.dll” (ByVal Buffer As Long)
Private Declare Sub ReadCh2 Lib “DSOLink.dll” (ByVal Buffer As Long)
Private Declare Function DataReady Lib “DSOLink.dll” () As Boolean
Private Declare Sub Voltage1 Lib “PCSU1000D.dll” (ByVal Volts As Long)
Private Declare Sub Voltage2 Lib “PCSU1000D.dll” (ByVal Volts As Long)
Private Declare Sub Time Lib “PCSU1000D.dll” (ByVal Rate As Long)
Private Declare Sub RunOn Lib “PCSU1000D.dll” (ByVal Run_On As Long)
Private Declare Sub SingleOn Lib “PCSU1000D.dll” (ByVal Single_On As Long)
Private Declare Sub YPosition1 Lib “PCSU1000D.dll” (ByVal y_pos As Long)
Private Declare Sub YPosition2 Lib “PCSU1000D.dll” (ByVal y_pos As Long)
Private Declare Sub TrgOn Lib “PCSU1000D.dll” (ByVal trg_On As Long)
Private Declare Sub TrgLevel Lib “PCSU1000D.dll” (ByVal TrgLevel As Long)
Private Declare Sub TrgSource Lib “PCSU1000D.dll” (ByVal TrgLevel As Long)
Private Declare Sub TrgEdge Lib “PCSU1000D.dll” (ByVal Positive_Negative As Long)
Private Declare Sub Coupling1 Lib “PCSU1000D.dll” (ByVal AC_DC_GND As Long)
Private Declare Sub Coupling2 Lib “PCSU1000D.dll” (ByVal AC_DC_GND As Long)
Private Declare Sub Show_PCSU1000 Lib “PCSU1000D.dll” (ByVal Visible As Long)
Private Declare Sub Start_PCSU1000 Lib “PCSU1000D.dll” ()
Private Declare Sub Stop_PCSU1000 Lib “PCSU1000D.dll” ()
Private Declare Function GetSettings Lib “PCSU1000D.dll” (ByVal SettingsArray As Long) As Boolean
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Stop_PCSU1000()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Start_PCSU1000()
End Sub
Private Sub ReadData_BUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReadData_BUT.Click
Dim i As Long
Output_LB.Items.Clear()
ReadCh1(DataBuffer1(0))
Output_LB.Items.Add(“Sample rate [Hz]” + Chr(9) + Str(DataBuffer1(0)))
Output_LB.Items.Add(“Full scale [mV]” + Chr(9) + Str(DataBuffer1(1)))
Output_LB.Items.Add(“GND level [counts]” + Chr(9) + Str(DataBuffer1(2)))
Output_LB.Items.Add("")
For i = 0 To 20
Output_LB.Items.Add(“Data(” + Str(i) + “)” + Chr(9) + Chr(9) + Str(DataBuffer1(i + 3)))
Next
End Sub
End Class

Execution fails on command: ReadCh1(DataBuffer1(0))

What is going wrong? I used the example from Velleman DLL manual.

Please advice and reply,

Regards
Christian

Please change ReadCh1(DataBuffer1(0))toReadCh1 DataBuffer1(0)

Yes, but the funny thing is Visual Studio 2008 changes this entry back into: ReadCh1(DataBuffer1(0))
It does NOT accept: ReadCh1 DataBuffer1(0)

Try it your self.

[quote=“VEL255”]Please change ReadCh1(DataBuffer1(0))toReadCh1 DataBuffer1(0)[/quote]That is Visual Basic 6. In Visual Basic .NET all method calls require parentheses.

Both are completely different programming languages and environments.

[quote]What is going wrong? I used the example from Velleman DLL manual.[/quote]I hope that was not Visual Basic 6 code.

[quote]I used the example from Velleman DLL manual.[/quote]It is Visual Basic 6 code.
In VB 2008 all “As Long” should be changed to “As Integer” in your code.
In VB 2008 this is OK:ReadCh1(DataBuffer1(0))

Also change:

Private Declare Sub ReadCh1 Lib "DSOLink.dll" (Buffer As Long) Private Declare Sub ReadCh2 Lib "DSOLink.dll" (Buffer As Long)to: Private Declare Sub ReadCh1 Lib "DSOLink.dll" (ByRef Buffer As Integer) Private Declare Sub ReadCh2 Lib "DSOLink.dll" (ByRef Buffer As Integer)

For more details please see: “Parameter Passing Mechanism for Visual Basic 6.0 Users”
http://msdn.microsoft.com/en-us/library/41zywfyc(v=vs.80).aspx

Still NO solution: same error: AccesViolationException on line: ReadCh1(DataBuffer1(0))

Didi you try it yourself in VB2008, it really doesn’t function?

Something must be wrong in the DLL DSOlink. I use 64-bit Windows 8.

Please advice.
Chris

Here is the link to download a PCSU1000 DLL demo project written in VB 2008:
box.com/s/q5n369y61v9hvd1qhbob
To test:

  • Extract the downloaded package
  • Double click the PCSU1000_DemoVB2008.sln

This demo works fine on 64-bit Windows 7.

All the required DLL files and PCSU1000GU.EXE are in the subfolder \bin\x86\Debug.
This version of the PCSU1000D.DLL requires the PCSU1000GU.EXE should be in the same folder as the DLL.

The PCSU1000GU.EXE included to the project is a new version v4.06.

Yes, Thanks for your assistance everything works fine now!
DLL’s you send work OK.

Best Regards,
Christian