Author Topic: Visual Basic Code Example To Download Screen Shot from TDS3000/MSO4101/TDS5054s  (Read 2053 times)

0 Members and 1 Guest are viewing this topic.

Offline daveykTopic starter

  • Frequent Contributor
  • **
  • Posts: 413
  • Country: us
I am trying to work out Visual Basic Code To Download Screen Shots from TDS3000/MSO4101/TDS5054s.

I have access to a non-Tektronics TDS3000 series program that during testing, it download several screen shots in BMP format that look identical to a sub folder of the program.  I have yet to figure out how to do that other than turning on the InkSaver option - lol.

The inksaver does make the screen shot from OpenChoice Desktop better for inclusion in a Word documents.   I just think it would be nice to do the screenshot myself and save a step or two.

I do not have access to the author of the program in question to ask him how he did it.

I have been working around the SAV:IMAG commands and am not receiving errors when I tell it to dump to c:\temp\test.BMP, but I beginning to this those commands are from the perspective of the scope, not the program.  I know the TDS5054 has a "C" drive, but I really do not think the TDS3000 or MSO4104s do. 

Scope.WriteString "SAV:IMAG:INKS ON"
Scope.WriteString "SAV:IMAG:FILEF BMP"
Scope.WriteString "SAV:IMAG C:\TEMP\TEST.BMP"

Again, the scope does not know what or where my "C:" drive is, so I think that may be an issue.  The other program that I did not write does transfer the BMP from the scope to the computer.  I just don't know how it is doing that. 

Anyone else here program with these scopes? 

Dave


 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2881
  • Country: 00
Read the programming manuals for your scope for the exact commands. Having the scope save directly to your computer's disk is certainly not going to work, so unless you want to juggle usb sticks / floppies, I'd use something like this (again check the programming manuals for specifics). This is Python code I wrote over a decade ago for the TDS-3000, not Visual Basic, but should be trivial to translate to whatever flavour of Visual Basic you use (I hope something from the current millennium...):
Code: [Select]
gpib.write(scope, 'hardcopy:port gpib') (or rs232)
gpib.write(scope, 'hardcopy:layout portrait')
gpib.write(scope, 'hardcopy:format PNG')
gpib.write(scope, 'hardcopy:compression 1')
gpib.write(scope, 'hardcopy:inksaver 0')
gpib.write(scope, 'hardcopy:pallet normal')
gpib.write(scope, 'hardcopy start')
hardcopy_data = gpib.readraw(scope)
harcopy_file = open('hc.png', 'w')
hardcopy_file.write(hardcopy_data)
hardcopy_file.close()
I hope you're not using RS-232, because downloading hard copies over RS-232 was quite a hassle for me back then. RS-232 doesn't have a real concept of 'readraw', so what I ended up doing is to read 1 byte at a time, and if no data came for a number of seconds, consider this the end of the transmission.

Offline daveykTopic starter

  • Frequent Contributor
  • **
  • Posts: 413
  • Country: us
Using GPIB, or in the case of the MSO4104, USB, but I communicate with it using the exact same VISA code as with GPIB just making show my ini file shows the address (USB0::0x0699::0x0401::C000082::0::INSTR).

At this point my brain is numb - lol.   Tektronix states for the MSO4104, if you are connected to USB it will send the hard copy to the USB port.  Now, how to capture the hard copy?

I need to study your code above.
 

Offline daveykTopic starter

  • Frequent Contributor
  • **
  • Posts: 413
  • Country: us
P.S. - BTW, my utility program that I am trying to add this feature to already supports my TDS3000 scopes (have four of them) and I recently added the MSO4104.  I already had a TDS5054, that as far as I can tell pretty much responds to the same codebase of the MSO4104.  There are some differences between the code of the TDS3000 and the other two, but not huge differences.  I was able to easily (in some case, it wasn't - lol) addapt existing TDS3000 code to control and setup the MSO4104. 

Then I go the silly idea, I would like to download a tiff image (or BMP, or PNG) of the screen.  I never figured out how to do that with the TDS3000 either.  If I could figure that out, I have several programs here in the lab that could benefit from that ability.
 

Offline daveykTopic starter

  • Frequent Contributor
  • **
  • Posts: 413
  • Country: us
"
hardcopy_data = gpib.readraw(scope)
harcopy_file = open('hc.png', 'w')
hardcopy_file.write(hardcopy_data)
hardcopy_file.close()
"
This needs explained how that is intercepting the hardcopy.

I do not have a readraw option.  When I do my visa code to accept data from the scope, here is an example:
scope.ReadString    ->Scope = gpib
I have an: Scope.ReadIEEEBlock, which I have no idea what that is about
and there is Scope.ReadNumber

Typically data from the scope is read in to a variable.  Anyway, without the structure and the "hardcopy_file" definition or function, or utility, I don't know to make of that.

Anyway, it's time to give this a rest for the night, but I do want to continue this tomorrow after church. 

Dave



 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2881
  • Country: 00
"
hardcopy_data = gpib.readraw(scope)
harcopy_file = open('hc.png', 'w')
hardcopy_file.write(hardcopy_data)
hardcopy_file.close()
"
This needs explained how that is intercepting the hardcopy.
The first line retrieves the binary data (PNG file) from the scope via GPIB. The three lines after that open a file on the local system, write the binary data as read from the scope to this file, and close the file. Writing data to a file should be a very basic operation in most programming languages.

I do not have a readraw option.  When I do my visa code to accept data from the scope, here is an example:
Search for a way to read binary data via the interface you are using. Try starting with a simple read, and see if that works. readraw() was a function of the specific GPIB library I was using.

Offline daveykTopic starter

  • Frequent Contributor
  • **
  • Posts: 413
  • Country: us
I'm still working on it.  The Visa Library I am using is VISA-COM 5.12 Type Library, which is from IVI and/or NI. 

In some example with Keysight VISA, they show a VI_WRITETOFILE command.  That was promising, but I kept going in circles.  Addressing and starting a visa session is different than I am used to.

So, I am trying to find better documentation of the IVI VISA-COM abilities and defined pre-defines variable structures.
 

Offline daveykTopic starter

  • Frequent Contributor
  • **
  • Posts: 413
  • Country: us
I do have myself confused.  I do reference IVI VisaCom as stated in the last message.  I have downloaded NI-VISA documentation.

The way I access VISA is like this:
Global ioMgr As VisaComLib.ResourceManager
Global Scope As VisaComLib.FormattedIO488
'
Function tdsOpenScope()
    '
    Set ioMgr = New VisaComLib.ResourceManager
    Set Scope = New VisaComLib.FormattedIO488
    '
    ' Address
    Set Scope.IO = ioMgr.Open(Trim(TDSAdr))
    Exit Function
End Function

When I google a statement such as " ioMgr = New VisaComLib.ResourceManager", I am directed to a Keysight web location.  None of the way I access the VISA-COM library is in the NI documentation, although I am referencing their GLOBMGR.DLL file.

I have been using this methodology so long, since the mid-2000s, I do not remember where I learned it from (probably Agilent).  Thinking that I was using KeySight Visa, I removed the reference from the VB program and the program doesn't run, so I do need to reference GLOBMGR.DLL, which is IVI/NI.

What I had been trying to find was command iterface, or reference .BAS files for GLOBMGR.DLL, and I get referenced to the NI VISA-COM documentation and back to the beginning of the circle again. - lol
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2881
  • Country: 00
In some example with Keysight VISA, they show a VI_WRITETOFILE command.  That was promising, but I kept going in circles.  Addressing and starting a visa session is different than I am used to.
Don't worry about writing to the file. That's standard VB6 functionality and I'm sure searching for something like VB6 write binary data to file, you find an example. Just worry about getting the data from the scope into a VB6 variable.

I can't help you with how to interface VB6 to VISA. I could imagine NI no longer had documentation on their website on how to use their software with a 20+ year old platform that was discontinued many years ago. Maybe there's documentation or code samples included with the ancient version of NI/Agilent VISA that was released when VB6 was still current?

Offline Jwalling

  • Supporter
  • ****
  • Posts: 1517
  • Country: us
  • This is work?
Then I go the silly idea, I would like to download a tiff image (or BMP, or PNG) of the screen.  I never figured out how to do that with the TDS3000 either.  If I could figure that out, I have several programs here in the lab that could benefit from that ability.

If you have a "B" or "C" scope (Or an ethernet module on a TDS3000), you can connect the ethernet port and use a browser for screen captures.
Note that Chrome does not work, but Firefox or IE does.
Jay

System error. Strike any user to continue.
 

Offline daveykTopic starter

  • Frequent Contributor
  • **
  • Posts: 413
  • Country: us
SUCCESS !!!!

'===================================================================================
Sub tdsSnapShot()
Dim SrnImage As Image
Dim pngFilePart As Byte
Dim strTest As String
Dim FF As Integer
Dim binData As Byte
Dim binData1 As Variant
Dim EndPNG As String * 4
Dim EndPNGLoop As Integer
Dim PNGEnd As String * 4
Dim txtTemp As String
Dim EndCounter As Integer
'
PNGEnd = "IEND"
Set ioMgr = New VisaComLib.ResourceManager
Set Scope = New VisaComLib.FormattedIO488
' Address
Set Scope.IO = ioMgr.Open(Trim(TDSAdr))
'

If Dir("C:\temp\test.png") = "test.png" Then
    Kill "C:\temp\test.png"
End If
FF = FreeFile
Open "C:\temp\test.png" For Output As #FF
'
looptimes = 0: EndPNG = "": EndPNGLoop = 0: EndCounter = 0
On Error GoTo CloseFile
'
Scope.IO.timeout = 5000
Scope.WriteString ("HARDCOPY:port gpib")
Scope.WriteString ("HARDCOPY:layout portrait")
Scope.WriteString ("HARDCOPY:format PNG")
Scope.WriteString ("HARDCOPY:compression OFF")
Scope.WriteString ("HARDCOPY:inksaver ON")
Scope.WriteString ("HARDCOPY:pallet normal")
Scope.WriteString ("WAV:STR OFF")
Scope.WriteString ("HARDCOPY START")
'
Do
    binData1 = Scope.IO.Read(1)
    Print #FF, Chr$(binData1(0));
    'Print #FF, Chr$(binData);
    EndPNGLoop = EndPNGLoop + 1
    '
    If EndPNGLoop = 5 Then
        txtTemp = Right(txtTemp, 3)
        EndPNGLoop = 4
    End If
    txtTemp = txtTemp + Chr$(binData1(0))
   
    If InStr(txtTemp, PNGEnd) > 0 Or EndCounter > 0 Then
        EndCounter = EndCounter + 1
    End If
    looptimes = looptimes + 1
    If EndCounter = 4 Then
        Exit Do
    End If
    '
Loop
'
CloseFile:
EndFile:
Close #FF
'
Scope.FlushRead
Scope.IO.Close
Set Scope.IO = Nothing
Set Scope = Nothing
On Error GoTo 0
Exit Sub
End Sub
 
The following users thanked this post: coromonadalix, Champal


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf