Posted Mon, 20 Mar 2023 05:29:10 GMT by Park, Minsu
Hi,<br> <br> I am using DPO7254C and I am making a VBA code to create automatic system.<br> <br> But I don't know how to create the code to get the screen captured from oscilloscope by VBA.<br> <br> I just want to get the screen and paste to specific cell in excel that I want.<br> <br> Please let me know the code.<br> <br> Thanks.<br> <br> &#160;
Posted Mon, 20 Mar 2023 07:11:00 GMT by Park, Minsu
My code is below, and there's error 'VI_ERROR_TME' on 'imageBytes = osc.ReadIEEEBlock(BinaryType_UI1, True)' line.<br> What should I do?<br> <br> Please Somebody Helps Me!!!<br> <br> <br> --------------------------------------------------------------------------------------------------------------------------------------------------------<br> Public Declare PtrSafe Sub Sleep Lib &quot;kernel32&quot; (ByVal dwMilliseconds As LongPtr)<br> <br> Public OSC_ioMgr As New VISAComLib.ResourceManager<br> Public osc As New VISAComLib.FormattedIO488<br> Public OSC_GPIO As String<br> <br> Public imageBytes() As Byte<br> <br> Sub CaptureScreen()<br> <br> &#160;' Connect to the oscilloscope<br> &#160; &#160; Set osc.IO = OSC_ioMgr.Open(&quot;GPIB0::15::INSTR&quot;)<br> &#160; &#160;&#160;<br> &#160; &#160; ' Set up the oscilloscope for screen capture<br> &#160; &#160; osc.WriteString &quot;HARDCOPY:FORMAT BMP&quot;<br> &#160; &#160; osc.WriteString &quot;HARDCOPY:Port FILE&quot;<br> &#160; &#160; osc.WriteString &quot;HARDCOPY:PALETTE INKSAVER&quot;<br> &#160; &#160; osc.WriteString &quot;HARDCOPY:FILENAME &quot;&quot;FILE_INKSAVER&quot;&quot;&quot;<br> &#160; &#160; osc.WriteString &quot;HARDCOPY START&quot;<br> &#160; &#160;&#160;<br> &#160; &#160; Sleep 2000 ' Wait for 2 seconds<br> &#160; &#160;&#160;<br> &#160; &#160; imageBytes = osc.ReadIEEEBlock(BinaryType_UI1, True)<br> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&#160;<br> &#160; &#160; 'Save image to a temporary file<br> &#160; &#160; fileNumber = FreeFile<br> &#160; &#160; 'Open &quot;D:\temp.jpg&quot; For Binary Lock Read Write As #fileNumber<br> &#160; &#160; Open &quot;D:\temp.jpg&quot; For Binary Lock Read Write As #fileNumber<br> &#160; &#160; Put #fileNumber, , imageBytes<br> &#160; &#160; Close #fileNumber<br> &#160; &#160;&#160;<br> &#160; &#160; 'Load the image back into Excel<br> &#160; &#160; Dim picture As Shape<br> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&#160;<br> &#160; &#160; Set picture = Sheets(&quot;Sheet1&quot;).Shapes.AddPicture(&quot;D:\temp.jpg&quot;, msoFalse, msoTrue, Sheets(&quot;Sheet1&quot;).Cells(&quot;A1&quot;).Left, Sheets(&quot;Sheet1&quot;).Cells(&quot;A1&quot;).Top, 1024 * 0.5, 768 * 0.5)<br> <br> End Sub<br> <br> &#160;
Posted Mon, 20 Mar 2023 21:17:23 GMT by Xu, Iris
Try setting the timeout to be long enough to allow the full image data to be sent. Depending on how you're connected (in this case GPIB) you may need a longer timeout.<br> <br> osc.timeout = 3000

You must be signed in to post in this forum.