Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

A question about hardcopy GPIB remote control?

HI
    I  have implemented some basic functions.Now I want to use the remote print screen, but there are some problems:
1,use viReadToFile ,the documents are only have 4096kb
2,use viRead,Program death
    This is my VB.NET source with viReadToFile code:
 
Private Sub FSE_btnHDCP_Click(sender As Object, e As EventArgs) Handles FSE_btnHDCP.Click
             status = viVPrintf(vi, ":SYST:COMM:GPIB:RTER EOI" + vbCrLf, 0) '此命令更改分隔符。
        status = viVPrintf(vi, ":HCOP:DEV:LANG WMF" + vbCrLf, 0) '设置WMF格式        
        status = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 20000) '设置超时
        status = viVPrintf(vi, ":HCOP:DEST1 'MMEM'" + vbCrLf, 0) '
        status = viVPrintf(vi, ":MMEM:NAME 'C:\USER\DATA\FILE.WMF'" + vbCrLf, 0) '
             status = viVPrintf(vi, ":HCOP" + vbCrLf, 0) '开始
        
        status = viVPrintf(vi, ":MMEM:MSIS 'C’" + vbCrLf, 0) '
        status = viVPrintf(vi, ":MMEM:CDIR '\USER\DATA\'" + vbCrLf, 0) '
        status = viVPrintf(vi, ":MMEM:DATA? 'FILE.WMF'" + vbCrLf, 0) '
        status = viRead(vi, strRes, 16, retCount)
        Dim x As Integer = Val(Mid(strRes, 2, 1))
        Dim y As Integer = Val(Mid(strRes, 3, x))
        VI_txtOUT.Text = retCount
        status = viVPrintf(vi, ":MMEM:MSIS 'C’" + vbCrLf, 0) '
        status = viVPrintf(vi, ":MMEM:CDIR '\USER\DATA\'" + vbCrLf, 0) '
        status = viVPrintf(vi, ":MMEM:DATA? 'FILE.WMF'" + vbCrLf, 0) '
        status = viReadToFile(vi, "D:\YouName.WMF", x + y + 2, retCount) '最大4096,且写入不覆盖。
        status = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 2000) '设置超时为默认2秒
    End Sub
 
      This is my VB.NET source with viRead code:
 
     Private Sub FSE_btnHDCP_Click(sender As Object, e As EventArgs) Handles FSE_btnHDCP.Click

        status = viVPrintf(vi, ":SYST:COMM:GPIB:RTER EOI" + vbCrLf, 0) '此命令更改分隔符。
        status = viVPrintf(vi, ":HCOP:DEV:LANG WMF" + vbCrLf, 0) '设置WMF格式
        status = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 20000) '设置超时
        status = viVPrintf(vi, ":HCOP:DEST1 'MMEM'" + vbCrLf, 0) '
        status = viVPrintf(vi, ":MMEM:NAME 'C:\USER\DATA\FILE.WMF'" + vbCrLf, 0) '
        status = viVPrintf(vi, ":HCOP" + vbCrLf, 0) '开始
        Threading.Thread.Sleep(2000)
        status = viVPrintf(vi, ":MMEM:MSIS 'C’" + vbCrLf, 0) '
       status = viVPrintf(vi, ":MMEM:CDIR '\USER\DATA\'" + vbCrLf, 0) '
        status = viVPrintf(vi, ":MMEM:DATA? 'FILE.WMF'" + vbCrLf, 0) '
 
        status = viRead(vi, strRes, 16, retCount)
        Dim x As Integer = Val(Mid(strRes, 2, 1))
        Dim y As Integer = Val(Mid(strRes, 3, x))
        VI_txtOUT.Text = retCount
 
        status = viVPrintf(vi, ":MMEM:MSIS 'C’" + vbCrLf, 0) '
        status = viVPrintf(vi, ":MMEM:CDIR '\USER\DATA\'" + vbCrLf, 0) '
        status = viVPrintf(vi, ":MMEM:DATA? 'FILE.WMF'" + vbCrLf, 0) '
        status = viRead(vi, strRes, x + y + 2, retCount) '太长时读出为空,容易卡死
        If (status < VI_SUCCESS) Then
 
           MsgBox(" Failed to read from the instrument! ")
 
        End If
        VI_txtOUT.Text = VI_txtOUT.Text & retCount
 

        If strRes = “” Then
             MsgBox(“nothing”)
         Else
             strRes = Mid(strRes, x + 3, y)
             FileOpen(1, Application.StartupPath + "\YouName.WMF", OpenMode.Output) '输出文档
             Print(1, strRes)
             FileClose(1)
         End If
 
        status = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 2000) '设置超时为默认2秒
    End Sub
 
 

if use  viVScanf or  viVQueryf like:

status = viVScanf(vi, "%t", strRes) 

status = viVQueryf(vi, ":MMEM:DATA? 'FILE.WMF'“ + vbCrLf, "%t", strRes)

 

Sometimes the result is empty, and sometimes the result is “#572676淄茪” 

0 Kudos
Message 1 of 20
(4,407 Views)

@xiaochouyu wrote:

and sometimes the result is “#572676淄茪” 


Agilent/Keysight instrument?  That format looks like something they use.  That # is the start of the data block.  Then the next character tells you how many characters the length is.  In this case, it tells me there are 5 characters for the length: 72676.

 

So what you need to do to read this is to read 2 bytes.  Remove the # and do a Val() on the second character.  Then read that many characters and do a Val() on those.  Now you read that many characters to get the actual data in the hard copy.

 

NOTE: Also make sure you have any termination characters turned OFF for this process.  You can turn it back on when you are done reading the data block.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 20
(4,380 Views)

Thank you for your reply

    In my source code you can see I had used 

status = viVPrintf(vi, ":SYST:COMM:GPIB:RTER EOI" + vbCrLf, 0)
  to turned OFF termination characters .
 
   and used 
 
    Dim x As Integer = Val(Mid(strRes, 2, 1))
    Dim y As Integer = Val(Mid(strRes, 3, x))
    status = viReadToFile(vi, "D:\YouName.WMF", x + y + 2, retCount)
 
   to read actual bytes in the hard copy.
 
   So I think the reason is not here.the reason maybe is how to use viRead or viReadToFile correctly.
 
PS: I use R&S FSEA30

 

 
0 Kudos
Message 3 of 20
(4,367 Views)

I thought you have incorrect Terminator setting.

 

May check the IO Trace log.

 

YY

0 Kudos
Message 4 of 20
(4,359 Views)

 thank you

   now i can't use  I/O Trace

  when i install NI-VISA RUNTIME , My VISA program can't connection instrument.

     when i install IO library , When running NI I/O Trace I get the error "visa32.dll is not built for NI I/O Trace.

  How to solve the problem of the conflict between“NI-VISA” and “IO library”?

 

0 Kudos
Message 5 of 20
(4,341 Views)

I would like to suggest to use the latest version of IO Library and NI-VISA.

 

My experence, a system has 2 visa will cause a lot of unexpected results. However, this is normal in real life.

 

 

0 Kudos
Message 6 of 20
(4,338 Views)

thank you

I'm puzzled that the function should be the same, though the source of visa32.dll is different.

 

this is  my Declare:

 Declare Function viOpenDefaultRM Lib "VISA32.DLL" (ByRef sesn As Integer) As Integer

 Declare Function viOpen Lib "VISA32.DLL" (ByVal sesn As Integer, ByVal viDesc As String, ByVal mode As Integer, ByVal timeout As Integer, ByRef vi As Integer) As Integer

 

Why can't be used in NI_VISA. NI_VISAshould be more standard

 

0 Kudos
Message 7 of 20
(4,335 Views)

 A new discovery is that under condition NI-VISA mode , I can connect through TCPIP, but I can't connect through GPIB.

 PS: The linker I used is GPIB to USB.

0 Kudos
Message 8 of 20
(4,319 Views)

the data size  is 72676kb,but only read out  4096kb.So I think the <block>size only 4096kb.

So the problem solution should be how to read <block> continuously .

 I continuous  use "viread ",but only first work.

0 Kudos
Message 9 of 20
(4,309 Views)

hi:

     I found that I can only read the maximum of 4096kb using “viread”.So I think the max block size of instrument can only be 4096kb.

 

 

              status = viReadToFile(vi, "D:\YouName.WMF", 72676, retCount) 

              the result is  retCount = 4096

 

   continuous  use "viread ",but only first work.

   How to read block data continuously?

 

 

 

 

status = viVPrintf(vi, ":SYST:COMM:GPIB:RTER EOI" + vbCrLf, 0) 
status = viVPrintf(vi, ":HCOP:DEV:LANG WMF" + vbCrLf, 0) 
status = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 20000)
status = viVPrintf(vi, ":HCOP:DEST1 'MMEM'" + vbCrLf, 0) 
status = viVPrintf(vi, ":MMEM:NAME 'C:\USER\DATA\FILE.WMF'" + vbCrLf, 0) 
status = viVPrintf(vi, ":HCOP" + vbCrLf, 0) 
status = viVPrintf(vi, ":MMEM:MSIS 'C’" + vbCrLf, 0) 

status = viVPrintf(vi, ":MMEM:CDIR '\USER\DATA\'" + vbCrLf, 0) 
status = viVPrintf(vi, ":MMEM:DATA? 'FILE.WMF'" + vbCrLf, 0) 

status = viVPrintf(vi, ":MMEM:MSIS 'C’" + vbCrLf, 0) 
status = viVPrintf(vi, ":MMEM:CDIR '\USER\DATA\'" + vbCrLf, 0) 
status = viVPrintf(vi, ":MMEM:DATA? 'FILE.WMF'" + vbCrLf, 0) 
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount) 
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)
status = viReadToFile(vi, "D:\YouName.WMF", 4096, retCount)

0 Kudos
Message 10 of 20
(4,314 Views)