Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Anders Blomdell
moberg
Commits
ee5e8457
Commit
ee5e8457
authored
Mar 27, 2019
by
Fredrik Bagge Carlson
Browse files
Style changes
parent
00c1ec6c
Changes
2
Show whitespace changes
Inline
Side-by-side
adaptors/julia/moberg.jl
View file @
ee5e8457
#!/usr/bin/julia
struct
m
oberg
_s
tatus
struct
M
oberg
S
tatus
result
::
Clong
end
function
check
_
OK
(
status
::
m
oberg
_s
tatus
)
function
checkOK
(
status
::
M
oberg
S
tatus
)
if
status
.
result
!=
0
error
(
"Moberg call failed with errno
$
(status.result)"
)
end
end
mutable struct
m
oberg
mutable struct
M
oberg
handle
::
Ptr
{
Nothing
}
end
function
m
oberg
()
function
M
oberg
()
handle
=
ccall
((
:
moberg_new
,
"libmoberg"
),
Ptr
{
Nothing
},
())
println
(
handle
)
m
=
m
oberg
(
handle
)
f
unction
close
(
h
::
moberg
)
m
=
M
oberg
(
handle
)
f
inalizer
(
m
)
do
h
println
(
h
)
ccall
((
:
moberg_free
,
"libmoberg"
),
Nothing
,
(
Ptr
{
Nothing
},),
h
.
handle
)
end
finalizer
(
close
,
m
)
m
end
mutable struct
m
oberg
_a
nalog
_i
n
mutable struct
M
oberg
A
nalog
I
n
context
::
Ptr
{
Nothing
}
do_read
::
Ptr
{
Nothing
}
handle
::
m
oberg
function
m
oberg
_a
nalog
_i
n
(
m
::
m
oberg
,
index
::
Unsigned
)
handle
::
M
oberg
function
M
oberg
A
nalog
I
n
(
m
::
M
oberg
,
index
::
Unsigned
)
self
=
new
()
check
_
OK
(
ccall
((
:
moberg_analog_in_open
,
"libmoberg"
),
m
oberg
_s
tatus
,
(
Ptr
{
Nothing
},
Cint
,
Ref
{
m
oberg
_a
nalog
_i
n
}),
checkOK
(
ccall
((
:
moberg_analog_in_open
,
"libmoberg"
),
M
oberg
S
tatus
,
(
Ptr
{
Nothing
},
Cint
,
Ref
{
M
oberg
A
nalog
I
n
}),
m
.
handle
,
index
,
self
))
self
.
handle
=
m
f
unction
close
(
channel
::
moberg_analog_in
)
f
inalizer
(
self
)
do
channel
println
(
channel
)
ccall
((
:
moberg_analog_in_close
,
"libmoberg"
),
m
oberg
_s
tatus
,
(
Ptr
{
Nothing
},
Cint
,
m
oberg
_a
nalog
_i
n
),
M
oberg
S
tatus
,
(
Ptr
{
Nothing
},
Cint
,
M
oberg
A
nalog
I
n
),
channel
.
handle
.
handle
,
index
,
self
)
end
finalizer
(
close
,
self
)
self
end
end
mutable struct
m
oberg
_a
nalog
_o
ut
mutable struct
M
oberg
A
nalog
O
ut
context
::
Ptr
{
Nothing
}
do_write
::
Ptr
{
Nothing
}
handle
::
m
oberg
function
m
oberg
_a
nalog
_o
ut
(
m
::
m
oberg
,
index
::
Unsigned
)
handle
::
M
oberg
function
M
oberg
A
nalog
O
ut
(
m
::
M
oberg
,
index
::
Unsigned
)
self
=
new
()
check
_
OK
(
ccall
((
:
moberg_analog_out_open
,
"libmoberg"
),
m
oberg
_s
tatus
,
(
Ptr
{
Nothing
},
Cint
,
Ref
{
m
oberg
_a
nalog
_o
ut
}),
checkOK
(
ccall
((
:
moberg_analog_out_open
,
"libmoberg"
),
M
oberg
S
tatus
,
(
Ptr
{
Nothing
},
Cint
,
Ref
{
M
oberg
A
nalog
O
ut
}),
m
.
handle
,
index
,
self
))
self
.
handle
=
m
f
unction
close
(
channel
::
moberg_analog_out
)
f
inalizer
(
self
)
do
channel
println
(
channel
)
ccall
((
:
moberg_analog_out_close
,
"libmoberg"
),
m
oberg
_s
tatus
,
(
Ptr
{
Nothing
},
Cint
,
m
oberg
_a
nalog
_o
ut
),
M
oberg
S
tatus
,
(
Ptr
{
Nothing
},
Cint
,
M
oberg
A
nalog
O
ut
),
channel
.
handle
.
handle
,
index
,
self
)
end
finalizer
(
close
,
self
)
self
end
end
function
read
(
ain
::
m
oberg
_a
nalog
_i
n
)
function
read
(
ain
::
M
oberg
A
nalog
I
n
)
result
=
Ref
{
Cdouble
}(
0.0
)
check
_
OK
(
ccall
(
ain
.
do_read
,
m
oberg
_s
tatus
,
checkOK
(
ccall
(
ain
.
do_read
,
M
oberg
S
tatus
,
(
Ptr
{
Nothing
},
Ptr
{
Cdouble
}),
ain
.
context
,
result
))
return
result
[]
end
function
write
(
aout
::
m
oberg
_a
nalog
_o
ut
,
value
::
Cdouble
)
check
_
OK
(
ccall
(
aout
.
do_write
,
m
oberg
_s
tatus
,
function
write
(
aout
::
M
oberg
A
nalog
O
ut
,
value
::
Cdouble
)
checkOK
(
ccall
(
aout
.
do_write
,
M
oberg
S
tatus
,
(
Ptr
{
Nothing
},
Cdouble
),
aout
.
context
,
value
))
end
function
test
()
m
=
m
oberg
()
m
=
M
oberg
()
println
(
m
)
for
v
in
-
10.0
:
2.0
:
10
for
i
in
30
:
31
try
aout
=
m
oberg
_a
nalog
_o
ut
(
m
,
Unsigned
(
i
))
aout
=
M
oberg
A
nalog
O
ut
(
m
,
Unsigned
(
i
))
value
=
v
+
i
-
32
write
(
aout
,
value
)
print
(
"
$
value "
)
...
...
@@ -108,7 +105,7 @@ function test()
sleep
(
0.1
)
for
j
in
30
:
33
try
ain
=
m
oberg
_a
nalog
_i
n
(
m
,
Unsigned
(
j
))
ain
=
M
oberg
A
nalog
I
n
(
m
,
Unsigned
(
j
))
println
(
read
(
ain
))
catch
println
(
"analog_in
$
j does not exist"
)
...
...
adaptors/julia/test_moberg.jl
View file @
ee5e8457
...
...
@@ -63,4 +63,5 @@ test()
println
(
"DONE"
)
GC
.
gc
()
GC
.
gc
()
# See https://github.com/JuliaCI/BenchmarkTools.jl/blob/af35d0513fe1e336ad0d8b9a35f924e8461aefa2/src/execution.jl#L1
println
(
"Really DONE"
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment