Visual Basic Code Example To Download Screen Shot from TDS3000/MSO4101/TDS5054s - Page 1
Forum section: electronics / testgear

author: daveyk
author_rank: Frequent Contributor
timestamp: August 13, 2022, 10:43:12 pm
content: 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

author: alm
author_rank: Super Contributor
timestamp: August 13, 2022, 11:20:46 pm
content: 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: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.

author: daveyk
author_rank: Frequent Contributor
timestamp: August 13, 2022, 11:42:42 pm
content: 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.

author: daveyk
author_rank: Frequent Contributor
timestamp: August 13, 2022, 11:48:58 pm
content: 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.

author: daveyk
author_rank: Frequent Contributor
timestamp: August 13, 2022, 11:56:27 pm
content: "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 = gpibI have an: Scope.ReadIEEEBlock, which I have no idea what that is aboutand there is Scope.ReadNumberTypically 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

author: alm
author_rank: Super Contributor
timestamp: August 14, 2022, 12:07:16 am
content: Quote from: daveyk on August 13, 2022, 11:56:27 pmThe 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.Quote from: daveyk on August 13, 2022, 11:56:27 pmSearch 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.

author: daveyk
author_rank: Frequent Contributor
timestamp: August 14, 2022, 02:53:02 pm
content: 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.

author: daveyk
author_rank: Frequent Contributor
timestamp: August 14, 2022, 03:10:59 pm
content: 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.ResourceManagerGlobal Scope As VisaComLib.FormattedIO488'Function tdsOpenScope()'Set ioMgr = New VisaComLib.ResourceManagerSet Scope = New VisaComLib.FormattedIO488'' AddressSet Scope.IO = ioMgr.Open(Trim(TDSAdr))Exit FunctionEnd FunctionWhen 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

author: alm
author_rank: Super Contributor
timestamp: August 15, 2022, 03:09:45 pm
content: Quote from: daveyk on August 14, 2022, 02:53:02 pmDon'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?

author: Jwalling
author_rank: Unknown
timestamp: August 16, 2022, 08:02:50 am
content: Quote from: daveyk on August 13, 2022, 11:48:58 pmIf 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.

author: daveyk
author_rank: Frequent Contributor
timestamp: September 01, 2022, 01:09:58 am
content: SUCCESS !!!!'===================================================================================Sub tdsSnapShot()Dim SrnImage As ImageDim pngFilePart As ByteDim strTest As StringDim FF As IntegerDim binData As ByteDim binData1 As VariantDim EndPNG As String * 4Dim EndPNGLoop As IntegerDim PNGEnd As String * 4Dim txtTemp As StringDim EndCounter As Integer'PNGEnd = "IEND"Set ioMgr = New VisaComLib.ResourceManagerSet Scope = New VisaComLib.FormattedIO488' AddressSet Scope.IO = ioMgr.Open(Trim(TDSAdr))'If Dir("C:\temp\test.png") = "test.png" ThenKill "C:\temp\test.png"End IfFF = FreeFileOpen "C:\temp\test.png" For Output As #FF'looptimes = 0: EndPNG = "": EndPNGLoop = 0: EndCounter = 0On Error GoTo CloseFile'Scope.IO.timeout = 5000Scope.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")'DobinData1 = Scope.IO.Read(1)Print #FF, Chr$(binData1(0));'Print #FF, Chr$(binData);EndPNGLoop = EndPNGLoop + 1'If EndPNGLoop = 5 ThentxtTemp = Right(txtTemp, 3)EndPNGLoop = 4End IftxtTemp = txtTemp + Chr$(binData1(0))If InStr(txtTemp, PNGEnd) > 0 Or EndCounter > 0 ThenEndCounter = EndCounter + 1End Iflooptimes = looptimes + 1If EndCounter = 4 ThenExit DoEnd If'Loop'CloseFile:EndFile:Close #FF'Scope.FlushReadScope.IO.CloseSet Scope.IO = NothingSet Scope = NothingOn Error GoTo 0Exit SubEnd Sub