Example_UploadProfile.py
Example_UploadProfileFromFile.py
5.5
MATLAB Examples
The MATLAB example code must be used with MATLAB version R2014b and above in order to support native web read
functionality. It is recommended to use MATLAB version R2016b and above in order to support native JSON functionality. The
JSONLab 3rd party toolbox may be used for MATLAB versions prior to R2016b.
A complete copy of the code examples may be downloaded from within the help section of the WaveShaper Software.
import
requests
import
json
import
numpy
as
np
from
WSMethods
import
*
# Define device IP
ip
=
'169.254.6.8'
# Get device info
result
=
requests
.
get
(
'http://'
+
ip
+
'/waveshaper/devinfo'
).
json
()
# Set frequency variables from device info
s
=
result
[
'startfreq'
]
e
=
result
[
'stopfreq'
]
# Create data for wsp
wsFreq
=
np
.
linspace
(
s
,
e
,
int
((
e
-
s
)
/
0.001
+
1
))
wsAttn
=
50
*
np
.
power
(
np
.
sin
(
2
*
np
.
pi
/
0.5
*
(
wsFreq
-
193
)),
2
)
wsPhase
=
np
.
zeros
(
wsFreq
.
shape
)
wsPort
=
np
.
ones
(
wsFreq
.
shape
)
# Upload profile using created data
r
=
uploadProfile
(
ip
,
wsFreq
,
wsAttn
,
wsPhase
,
wsPort
)
import
requests
import
json
import
os
from
WSMethods
import
*
# Define device IP
ip
=
'169.254.6.8'
# Read the "wspTestFile.wsp" file from the same directory as this .py file
string
=
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'wspTestFile.wsp'
)).
read
()
# Run splitWspString() function using the WSP string from the file
wsFreq
,
wsAttn
,
wsPhase
,
wsPort
=
splitWspString
(
string
)
# Upload profile using split data
r
=
uploadProfile
(
ip
,
wsFreq
,
wsAttn
,
wsPhase
,
wsPort
)
WaveShaper A Series User Manual
39