Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

I have added the two f

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?I have a Sony/Tektronix AFG310 Arbitrary Function Generator. I have successfully retrieved information I need and also sent strings such as "SOUR1:FREQ 2000", but when I try and use variables to construct this string it fails.

My Code adds the string "SOUR1:FREQ " to a value entered in a text box by a user. I have checked the data types and compared strings, and all is fine.

My Code:

Private Sub cmdSetFrequency_Click()
Dim Msg As String, Frequency As String, Header As String

Frequen
cy = txtFrequency.Text
Header = "SOUR1:FREQ "
Msg = Header & Frequency
tellGPIB Msg
End Sub

TellGPIB is a custom function I wrote to send all the stuff that goes with it:

Private Sub tellGPIB(CommandString As String)
ilwrt Dev%, CommandString, Len(CommandString)
If (ibsta And EERR) Then
Call GPIBCleanup("Unable to write to device")
End If
End Sub

For some reason, it doesn't work, and I can't see why not. It all looks fine to me.

This works:

tellGPIB "SOUR1:FREQ 2000"

so why doesn't it work when I construct the string?
0 Kudos
Message 1 of 3
(3,329 Views)
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.
0 Kudos
Message 2 of 3
(3,329 Views)
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?Actually, if you put the code that is missing into the function tellGPIB then you will not need to keep adding it to every procedure that needs to call tellGPIB.
0 Kudos
Message 3 of 3
(3,329 Views)