-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (67 loc) · 2.68 KB
/
main.cpp
File metadata and controls
84 lines (67 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <Windows.h>
#include "visa.h"
#define _CRT_SECURE_NO_WARNINGS
#define BUFFER 255
static ViSession defaultRM, vi;
static ViStatus status;
static unsigned char strCmd[256], strReply[256];
static ViUInt32 retCnt;
int main()
{
//VISA Session Setup
status = viOpenDefaultRM(&defaultRM);
if (status < VI_SUCCESS) goto Error;
status = viOpen(defaultRM, "GPIB8::1::INSTR", VI_NULL, 100000, &vi);
if (status < VI_SUCCESS) goto Error;
//Sending Reset and Identification Commands
sprintf_s((char*)strCmd, 6, "*RST\n");
status = viWrite(vi, strCmd, strlen((char*)strCmd), &retCnt);
if (status < VI_SUCCESS) goto Error;
sprintf_s((char*)strCmd, 7, "*IDN?\n");
status = viWrite(vi, strCmd, strlen((char*)strCmd), &retCnt);
if (status < VI_SUCCESS) goto Error;
status = viRead(vi, strReply, 255, &retCnt);
if (status < VI_SUCCESS) goto Error;
// viRead() writes into the string only the data read from the instrument
// therefore you need to NULL terminate the strings manually.
strReply[retCnt] = 0;
puts((char*)strReply);
//General Setup
sprintf_s((char*)strCmd, BUFFER, "display:general:measview:new toverview\n");
status = viWrite(vi, strCmd, strlen((char*)strCmd), &retCnt);
if (status < VI_SUCCESS) goto Error;
sprintf_s((char*)strCmd, BUFFER, "display:general:measview:new avtime\n");
status = viWrite(vi, strCmd, strlen((char*)strCmd), &retCnt);
if (status < VI_SUCCESS) goto Error;
double cf = 2.4453e9;
sprintf_s((char*)strCmd, BUFFER, "spectrum:frequency:center %f\n", cf);
status = viWrite(vi, strCmd, strlen((char*)strCmd), &retCnt);
if (status < VI_SUCCESS) goto Error;
double refLevel = 0;
sprintf_s((char*)strCmd, BUFFER, "input:rlevel %f\n", refLevel);
status = viWrite(vi, strCmd, strlen((char*)strCmd), &retCnt);
if (status < VI_SUCCESS) goto Error;
double aLength = 100e-6;
sprintf_s((char*)strCmd, BUFFER, "sense:analysis:length %f\n", aLength);
status = viWrite(vi, strCmd, strlen((char*)strCmd), &retCnt);
if (status < VI_SUCCESS) goto Error;
//Start Acquisition
sprintf_s((char*)strCmd, BUFFER, "initiate:continuous off\n");
status = viWrite(vi, strCmd, strlen((char*)strCmd), &retCnt);
if (status < VI_SUCCESS) goto Error;
sprintf_s((char*)strCmd, BUFFER, "initiate:immediate\n");
status = viWrite(vi, strCmd, strlen((char*)strCmd), &retCnt);
if (status < VI_SUCCESS) goto Error;
Error:
if (status < VI_SUCCESS)
{
viStatusDesc(vi, status, (char*)strReply);
printf("VISA Error Occured:\r\n%s", strReply);
}
if (vi != VI_NULL) viClose(vi);
if (defaultRM != VI_NULL) viClose(defaultRM);
printf("\r\nPress any key to continue ...");
getchar();
return 0;
}