From ae2b35fb56307b3741a0e3ac7a910fe14e52ed7b Mon Sep 17 00:00:00 2001 From: JSwelland <150476909+JSwelland@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:35:14 -0800 Subject: [PATCH 1/4] Add files via upload --- .../MidrangeScopes/src/save_hardcopy_c++.c | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Examples/Oscilloscopes/MidrangeScopes/src/save_hardcopy_c++.c diff --git a/Examples/Oscilloscopes/MidrangeScopes/src/save_hardcopy_c++.c b/Examples/Oscilloscopes/MidrangeScopes/src/save_hardcopy_c++.c new file mode 100644 index 0000000..5cb6a0f --- /dev/null +++ b/Examples/Oscilloscopes/MidrangeScopes/src/save_hardcopy_c++.c @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------- +// Name: Save Hardcopy with C++ using VISA for 2/3/4/5/6 Series Scopes +// Purpose : This example demonstrates how to save a hard copy screen image from +// the scope to the PC. +// +// Created: 10/4/2023 +// +// Compatible Instruments : 2/3/4/5/6 Series Riddick Based Oscilloscopes +// +// Compatible Interfaces : USB, Ethernet, GPIB +// +// Tektronix provides the following example "AS IS" with no support or warranty. +// +//------------------------------------------------------------------------------- +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include +#include + +int main() { + + ViStatus status; + ViSession defaultRM, instr; + ViUInt32 retCount; + ViChar buffer[80000]; + + // Modify the following line to configure this script for your instrument + char resourceString[] = "TCPIP::10.233.70.92::INSTR"; + ViBuf scpi; + + // Where to save (PC side) + char target_path[] = "C:\\tempx\\"; + char target_name[] = "scope_screenshot.png"; + char full_path[256]; + + // Initialize VISA session + status = viOpenDefaultRM(&defaultRM);; + if (status < VI_SUCCESS) { + printf("Failed to initialize\n"); + return -1; + } + + // Open instrument connection + status = viOpen(defaultRM, resourceString, VI_NULL, VI_NULL, &instr); + if (status < VI_SUCCESS) { + printf("Error connecting to instrument\n"); + viStatusDesc(defaultRM, status, buffer); + printf("%s\n", buffer); + return 0; + } + + // Set timeout + status = viSetAttribute(instr, VI_ATTR_TMO_VALUE, 10000); + + // Configure scope for screenshot, see programmers manual for scope-specific syntax + // Setting where to save screenshot on scope + scpi = "SAVE:IMAGE \"C:\\screenshots\\tek.png\"\n"; + status = viWrite(instr, scpi, (ViUInt32)strlen(scpi), &retCount); + if (status < VI_SUCCESS) { + printf("Error writing to instrument\n"); + viStatusDesc(defaultRM, status, buffer); + printf("%s\n", buffer); + return 0; + } + + // Transfer screenshot to PC + status = viWrite(instr, "FILESystem:READFile \"C:\\screenshots\\tek.png\"\n", 45, &retCount); + if (status < VI_SUCCESS) { + printf("Error writing to instrument\n"); + viStatusDesc(defaultRM, status, buffer); + printf("%s\n", buffer); + return 0; + } + status = viRead(instr, buffer, sizeof(buffer), &retCount); + if (status < VI_SUCCESS) { + printf("Error reading from instrument\n"); + viStatusDesc(defaultRM, status, buffer); + printf("%s\n", buffer); + return 0; + } + + snprintf(full_path, sizeof(full_path), "%s%s", target_path, target_name); + FILE* file = fopen(full_path, "wb"); + if (file == NULL) { + printf("Failed to open file for writing.\n"); + return -1; + } + + size_t bytesWritten = fwrite(buffer, 1, retCount, file); + + // Check if the write operation was successful + if (bytesWritten != buffer) { + perror("Error writing to the file"); + fclose(file); + return 1; // Exit with an error code + } + + fclose(file); + + viClose(instr); + viClose(defaultRM); + return 0; +} \ No newline at end of file From 09de2e7be9519762adc271b02732e13f1e06e40c Mon Sep 17 00:00:00 2001 From: JSwelland <150476909+JSwelland@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:36:52 -0800 Subject: [PATCH 2/4] Delete Examples/Oscilloscopes/MidrangeScopes/src/save_hardcopy_c++.c --- .../MidrangeScopes/src/save_hardcopy_c++.c | 105 ------------------ 1 file changed, 105 deletions(-) delete mode 100644 Examples/Oscilloscopes/MidrangeScopes/src/save_hardcopy_c++.c diff --git a/Examples/Oscilloscopes/MidrangeScopes/src/save_hardcopy_c++.c b/Examples/Oscilloscopes/MidrangeScopes/src/save_hardcopy_c++.c deleted file mode 100644 index 5cb6a0f..0000000 --- a/Examples/Oscilloscopes/MidrangeScopes/src/save_hardcopy_c++.c +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------- -// Name: Save Hardcopy with C++ using VISA for 2/3/4/5/6 Series Scopes -// Purpose : This example demonstrates how to save a hard copy screen image from -// the scope to the PC. -// -// Created: 10/4/2023 -// -// Compatible Instruments : 2/3/4/5/6 Series Riddick Based Oscilloscopes -// -// Compatible Interfaces : USB, Ethernet, GPIB -// -// Tektronix provides the following example "AS IS" with no support or warranty. -// -//------------------------------------------------------------------------------- -#define _CRT_SECURE_NO_WARNINGS - -#include -#include -#include -#include - -int main() { - - ViStatus status; - ViSession defaultRM, instr; - ViUInt32 retCount; - ViChar buffer[80000]; - - // Modify the following line to configure this script for your instrument - char resourceString[] = "TCPIP::10.233.70.92::INSTR"; - ViBuf scpi; - - // Where to save (PC side) - char target_path[] = "C:\\tempx\\"; - char target_name[] = "scope_screenshot.png"; - char full_path[256]; - - // Initialize VISA session - status = viOpenDefaultRM(&defaultRM);; - if (status < VI_SUCCESS) { - printf("Failed to initialize\n"); - return -1; - } - - // Open instrument connection - status = viOpen(defaultRM, resourceString, VI_NULL, VI_NULL, &instr); - if (status < VI_SUCCESS) { - printf("Error connecting to instrument\n"); - viStatusDesc(defaultRM, status, buffer); - printf("%s\n", buffer); - return 0; - } - - // Set timeout - status = viSetAttribute(instr, VI_ATTR_TMO_VALUE, 10000); - - // Configure scope for screenshot, see programmers manual for scope-specific syntax - // Setting where to save screenshot on scope - scpi = "SAVE:IMAGE \"C:\\screenshots\\tek.png\"\n"; - status = viWrite(instr, scpi, (ViUInt32)strlen(scpi), &retCount); - if (status < VI_SUCCESS) { - printf("Error writing to instrument\n"); - viStatusDesc(defaultRM, status, buffer); - printf("%s\n", buffer); - return 0; - } - - // Transfer screenshot to PC - status = viWrite(instr, "FILESystem:READFile \"C:\\screenshots\\tek.png\"\n", 45, &retCount); - if (status < VI_SUCCESS) { - printf("Error writing to instrument\n"); - viStatusDesc(defaultRM, status, buffer); - printf("%s\n", buffer); - return 0; - } - status = viRead(instr, buffer, sizeof(buffer), &retCount); - if (status < VI_SUCCESS) { - printf("Error reading from instrument\n"); - viStatusDesc(defaultRM, status, buffer); - printf("%s\n", buffer); - return 0; - } - - snprintf(full_path, sizeof(full_path), "%s%s", target_path, target_name); - FILE* file = fopen(full_path, "wb"); - if (file == NULL) { - printf("Failed to open file for writing.\n"); - return -1; - } - - size_t bytesWritten = fwrite(buffer, 1, retCount, file); - - // Check if the write operation was successful - if (bytesWritten != buffer) { - perror("Error writing to the file"); - fclose(file); - return 1; // Exit with an error code - } - - fclose(file); - - viClose(instr); - viClose(defaultRM); - return 0; -} \ No newline at end of file From 2f9346c1535dfc2a9e2000e6bede53436d118fa8 Mon Sep 17 00:00:00 2001 From: JSwelland <150476909+JSwelland@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:39:35 -0800 Subject: [PATCH 3/4] Update README.md --- .../MidrangeScopes/src/SaveHardcopyExample/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Examples/Oscilloscopes/MidrangeScopes/src/SaveHardcopyExample/README.md b/Examples/Oscilloscopes/MidrangeScopes/src/SaveHardcopyExample/README.md index 6a0c98b..d6ee199 100644 --- a/Examples/Oscilloscopes/MidrangeScopes/src/SaveHardcopyExample/README.md +++ b/Examples/Oscilloscopes/MidrangeScopes/src/SaveHardcopyExample/README.md @@ -1,4 +1,4 @@ -# Save Hardcopy to PC +# Save Hardcopy to PC (Python) Original Attribution: Dave W - Tektronix Applications This example demonstrates how to use Python along with PyVISA to save hard copy screen images to the PC from MSO/DPO/MDO 2000, 3000 and 4000 Series Scopes. @@ -7,3 +7,9 @@ Resources --------- Original Discussion: https://forum.tek.com/viewtopic.php?f=580&t=138613 + +# Save Hardcopy to PC (C++) +Original Attribution: Joe S - Tektronix Applications + +This example demonstrates how to use C++ along with VISA to save hard copy screen images to the PC from 2/3/4/5/6 Series Riddick based oscilloscopes. + From dd53e3b8f85c148f027f789c6d08611c1e06b1d1 Mon Sep 17 00:00:00 2001 From: JSwelland <150476909+JSwelland@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:40:57 -0800 Subject: [PATCH 4/4] Add files via upload --- .../SaveHardcopyExample/save_hardcopy_c++.c | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Examples/Oscilloscopes/MidrangeScopes/src/SaveHardcopyExample/save_hardcopy_c++.c diff --git a/Examples/Oscilloscopes/MidrangeScopes/src/SaveHardcopyExample/save_hardcopy_c++.c b/Examples/Oscilloscopes/MidrangeScopes/src/SaveHardcopyExample/save_hardcopy_c++.c new file mode 100644 index 0000000..5cb6a0f --- /dev/null +++ b/Examples/Oscilloscopes/MidrangeScopes/src/SaveHardcopyExample/save_hardcopy_c++.c @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------- +// Name: Save Hardcopy with C++ using VISA for 2/3/4/5/6 Series Scopes +// Purpose : This example demonstrates how to save a hard copy screen image from +// the scope to the PC. +// +// Created: 10/4/2023 +// +// Compatible Instruments : 2/3/4/5/6 Series Riddick Based Oscilloscopes +// +// Compatible Interfaces : USB, Ethernet, GPIB +// +// Tektronix provides the following example "AS IS" with no support or warranty. +// +//------------------------------------------------------------------------------- +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include +#include + +int main() { + + ViStatus status; + ViSession defaultRM, instr; + ViUInt32 retCount; + ViChar buffer[80000]; + + // Modify the following line to configure this script for your instrument + char resourceString[] = "TCPIP::10.233.70.92::INSTR"; + ViBuf scpi; + + // Where to save (PC side) + char target_path[] = "C:\\tempx\\"; + char target_name[] = "scope_screenshot.png"; + char full_path[256]; + + // Initialize VISA session + status = viOpenDefaultRM(&defaultRM);; + if (status < VI_SUCCESS) { + printf("Failed to initialize\n"); + return -1; + } + + // Open instrument connection + status = viOpen(defaultRM, resourceString, VI_NULL, VI_NULL, &instr); + if (status < VI_SUCCESS) { + printf("Error connecting to instrument\n"); + viStatusDesc(defaultRM, status, buffer); + printf("%s\n", buffer); + return 0; + } + + // Set timeout + status = viSetAttribute(instr, VI_ATTR_TMO_VALUE, 10000); + + // Configure scope for screenshot, see programmers manual for scope-specific syntax + // Setting where to save screenshot on scope + scpi = "SAVE:IMAGE \"C:\\screenshots\\tek.png\"\n"; + status = viWrite(instr, scpi, (ViUInt32)strlen(scpi), &retCount); + if (status < VI_SUCCESS) { + printf("Error writing to instrument\n"); + viStatusDesc(defaultRM, status, buffer); + printf("%s\n", buffer); + return 0; + } + + // Transfer screenshot to PC + status = viWrite(instr, "FILESystem:READFile \"C:\\screenshots\\tek.png\"\n", 45, &retCount); + if (status < VI_SUCCESS) { + printf("Error writing to instrument\n"); + viStatusDesc(defaultRM, status, buffer); + printf("%s\n", buffer); + return 0; + } + status = viRead(instr, buffer, sizeof(buffer), &retCount); + if (status < VI_SUCCESS) { + printf("Error reading from instrument\n"); + viStatusDesc(defaultRM, status, buffer); + printf("%s\n", buffer); + return 0; + } + + snprintf(full_path, sizeof(full_path), "%s%s", target_path, target_name); + FILE* file = fopen(full_path, "wb"); + if (file == NULL) { + printf("Failed to open file for writing.\n"); + return -1; + } + + size_t bytesWritten = fwrite(buffer, 1, retCount, file); + + // Check if the write operation was successful + if (bytesWritten != buffer) { + perror("Error writing to the file"); + fclose(file); + return 1; // Exit with an error code + } + + fclose(file); + + viClose(instr); + viClose(defaultRM); + return 0; +} \ No newline at end of file