iles NIGLOBAL.bas and VBIB-32.BAS to my project in VB5. I have successfully retrieved information from the device and sent strings to it, but when I try and use a constructed string variable, I get an error 'unable to write to device' does anyone know why?Yes I know I asked the question in the first place, but since I solved it just after I posted it, I thought I may as well share the soultion if anyone else was in need:
Basically, It was because I need to include some code before calling the tellGPIB command. I tried sending a normal string "SOUR1:FREQ 1000" from the same command button. Didn't work. (I said it did before, but that was from somewhere else in my code).
What was wrong? I took a look at the initialize function for my form which works.
Every procedure that uses the tellGPIB function (or similar) needs to have the following added before the function is called:
Dev% = ildev(BDINDEX, PRIMARY_ADDR_OF_FG310, NO_SECONDARY_ADDR, TIMEOUT, EOTMODE, EOSMODE)
If (ibsta And EERR) Then
ErrMsg = "Unable
to open device" & Chr(13) & "ibsta = &H" & _
Hex(ibsta) & Chr(13) & "iberr = " & iberr
MsgBox ErrMsg, vbCritical, "Error"
End If
ilclr Dev% 'Reset GPIB portion of device
If (ibsta And EERR) Then
Call GPIBCleanup("Unable to clear device")
End If
So, the code for cmdSetFrequency would be as follows:
Private Sub cmdSetFrequency_Click()
Dev% = ildev(BDINDEX, PRIMARY_ADDR_OF_FG310, NO_SECONDARY_ADDR, TIMEOUT, EOTMODE, EOSMODE)
If (ibsta And EERR) Then
ErrMsg = "Unable to open device" & Chr(13) & "ibsta = &H" & _
Hex(ibsta) & Chr(13) & "iberr = " & iberr
MsgBox ErrMsg, vbCritical, "Error"
End If
ilclr Dev% 'Reset GPIB portion of device
If (ibsta And EERR) Then
Call GPIBCleanup("Unable to clear device")
End If
Dim Msg As String, Frequency As String, Header As String
Frequency = txtFrequency.Text 'This is a string variable
Header = "SOUR1:FREQ "
Msg = Header & Frequency
tell
GPIB Msg
End Sub
This Now works perfectly. tellGPIB remains unchanged from before.
Hope this is of use to anyone who has the same problem.