Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] pyVISA backend #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 57 additions & 17 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# This file is machine-generated - editing it directly is not advised

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[BinDeps]]
deps = ["Compat", "Libdl", "SHA", "URIParser"]
git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9"
uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee"
version = "0.8.10"
[[CSTParser]]
deps = ["LibGit2", "Test", "Tokenize"]
git-tree-sha1 = "437c93bc191cd55957b3f8dee7794b6131997c56"
uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
version = "0.5.2"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "195a3ffcb8b0762684b6821de18f83a16455c6ea"
git-tree-sha1 = "84aa74986c5b9b898b0d1acaf3258741ee64754f"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "2.0.0"
version = "2.1.0"

[[Conda]]
deps = ["Compat", "JSON", "VersionParsing"]
git-tree-sha1 = "b625d802587c2150c279a40a646fba63f9bd8187"
uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d"
version = "1.2.0"

[[DataStructures]]
deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"]
git-tree-sha1 = "ca971f03e146cf144a9e2f2ce59674f5bf0e8038"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.15.0"

[[Dates]]
deps = ["Printf"]
Expand All @@ -24,13 +34,19 @@ deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[InteractiveUtils]]
deps = ["Markdown"]
deps = ["LinearAlgebra", "Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[JSON]]
deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"]
git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.20.0"

[[LibGit2]]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

Expand All @@ -44,13 +60,25 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[MacroTools]]
deps = ["CSTParser", "Compat", "DataStructures", "Test"]
git-tree-sha1 = "daecd9e452f38297c686eba90dba2a6d5da52162"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.0"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[OrderedCollections]]
deps = ["Random", "Serialization", "Test"]
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.1.0"

[[Pkg]]
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand All @@ -59,6 +87,12 @@ uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[PyCall]]
deps = ["Conda", "Dates", "Libdl", "LinearAlgebra", "MacroTools", "Pkg", "Serialization", "Statistics", "Test", "VersionParsing"]
git-tree-sha1 = "6e5bac1b1faf3575731a6a5b76f638f2389561d3"
uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
version = "1.91.2"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Expand Down Expand Up @@ -92,15 +126,21 @@ uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[URIParser]]
deps = ["Test", "Unicode"]
git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69"
uuid = "30578b45-9adc-5946-b283-645ec420af67"
version = "0.4.0"
[[Tokenize]]
deps = ["Printf", "Test"]
git-tree-sha1 = "3e83f60b74911d3042d3550884ca2776386a02b8"
uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624"
version = "0.5.3"

[[UUIDs]]
deps = ["Random", "SHA"]
deps = ["Random"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[VersionParsing]]
deps = ["Compat"]
git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669"
uuid = "81def892-9a0e-5fdd-b105-ffc91e053289"
version = "1.1.3"
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name = "Instruments"
uuid = "2c6aeda0-45f5-11e9-10ba-f7b3d6416888"
authors = ["Alex Porter <aporter@blueorigin.com>"]
version = "0.1.0"
authors = ["CoherenceController coherencecontrol@bbn.com"]
version = "0.2.0"

[deps]
BinDeps = "9e28174c-4ba2-5203-b857-d8d62c4213ee"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
VersionParsing = "81def892-9a0e-5fdd-b105-ffc91e053289"
2 changes: 2 additions & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
julia 0.7
PyCall 1.90.0
VersionParsing
6 changes: 0 additions & 6 deletions deps/build.jl

This file was deleted.

17 changes: 6 additions & 11 deletions src/Instruments.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
__precompile__()
module Instruments

using PyCall

export Instrument, GenericInstrument, connect!, disconnect!, write, read, query
export ResourceManager
export find_resources
Expand All @@ -8,22 +11,14 @@ export @scpibool

import Base: write, read, readavailable

# load the binary dependency path
if isfile(joinpath(dirname(dirname(@__FILE__)),"deps","deps.jl"))
include("../deps/deps.jl")
else
error("Instruments.jl not properly installed. Please run Pkg.build(\"Instruments\")")
end

include("init.jl")
include("visa/VISA.jl")

include("instrument.jl")

include("scpi.jl")

ResourceManager() = viOpenDefaultRM()
ResourceManager() = @check_status visalib.open_default_resource_manager()

# Helper functions to find instruments
find_resources(rm, expr::AbstractString="?*::INSTR") = Instruments.viFindRsrc(rm, expr)
find_resources(rm, expr::AbstractString="?*::INSTR") = visalib.list_resources(rm, expr)

end # module
18 changes: 18 additions & 0 deletions src/init.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using VersionParsing

const pyvisa = PyNULL()
const visalib = PyNULL()

function __init__()
#Import pyvisa from Conda.jl
copy!(pyvisa, pyimport_conda("pyvisa-py", "pyvisa-py", "conda-forge"))
copy!(visalib, pyvisa.PyVisaLibrary())

pyvers = pyvisa.__version__
global pyvisa_version = try
vparse(pyvers)
catch
v"0.0.0"
end

end
12 changes: 6 additions & 6 deletions src/instrument.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
abstract type Instrument end

mutable struct GenericInstrument <: Instrument
handle::ViObject
handle::PyObject
connected::Bool
bufSize::UInt32
end
GenericInstrument() = GenericInstrument(0, false, 1024)
GenericInstrument() = GenericInstrument(PyNULL(), false, 1024)

function connect!(rm, instr::Instrument, address::AbstractString)
if !instr.connected
instr.handle = viOpen(rm, address)
instr.handle = @check_status visalib.open(rm, address)
instr.connected = true
end
end

function disconnect!(instr::Instrument)
if instr.connected
viClose(instr.handle)
check_status(visalib.close(instr.handle))
instr.connected = false
end
end
Expand All @@ -35,9 +35,9 @@ macro check_connected(ex)
return Expr(:function, esc(funcproto), esc(checkbody))
end

@check_connected write(instr::Instrument, msg::AbstractString) = viWrite(instr.handle, msg)
@check_connected write(instr::Instrument, msg::AbstractString) = @check_status visalib.write(instr.handle, msg)

@check_connected read(instr::Instrument) = rstrip(viRead(instr.handle; bufSize=instr.bufSize), ['\r', '\n'])
@check_connected read(instr::Instrument) = rstrip(@check_status visalib.read(instr.handle; bufSize=instr.bufSize), ['\r', '\n'])

@check_connected readavailable(instr::Instrument) = readavailable(instr.handle)

Expand Down
Loading