diff --git a/adaptors/julia/AnalogIn.jl b/adaptors/julia/AnalogIn.jl index ac4d4a140885f3bbf98ad91611184ea5522ab1a3..3b24b3a7ba7325dc18968a982d885ccb1dd3ecb1 100644 --- a/adaptors/julia/AnalogIn.jl +++ b/adaptors/julia/AnalogIn.jl @@ -7,16 +7,16 @@ mutable struct AnalogIn moberg::Moberg index::UInt32 channel::AnalogInChannel - AnalogIn(moberg::Moberg, index::Unsigned) = ( - channel = AnalogInChannel(0,0); + function AnalogIn(moberg::Moberg, index::Unsigned) + channel = AnalogInChannel(0,0) checkOK(ccall((:moberg_analog_in_open, "libmoberg"), Status, (Moberg, Cint, Ref{AnalogInChannel}), - moberg, index, channel)); - self = new(moberg, index, channel); - finalizer(close, self); + moberg, index, channel)) + self = new(moberg, index, channel) + finalizer(close, self) self - ) + end end function close(ain::AnalogIn) @@ -35,4 +35,3 @@ function read(ain::AnalogIn) ain.channel.context, result)) return result[] end - diff --git a/adaptors/julia/AnalogOut.jl b/adaptors/julia/AnalogOut.jl index 534960ff0f85f7ddbf6a0774e66f07ab07e58ffb..f526862fafd83ef5fc1c683acaaf9bbd70a3a547 100644 --- a/adaptors/julia/AnalogOut.jl +++ b/adaptors/julia/AnalogOut.jl @@ -7,16 +7,16 @@ mutable struct AnalogOut moberg::Moberg index::UInt32 channel::AnalogOutChannel - AnalogOut(moberg::Moberg, index::Unsigned) = ( - channel = AnalogOutChannel(0,0); + function AnalogOut(moberg::Moberg, index::Unsigned) + channel = AnalogOutChannel(0,0) checkOK(ccall((:moberg_analog_out_open, "libmoberg"), Status, (Moberg, Cint, Ref{AnalogOutChannel}), moberg, index, channel)); - self = new(moberg, index, channel); - finalizer(close, self); + self = new(moberg, index, channel) + finalizer(close, self) self - ) + end end function close(aout::AnalogOut) @@ -25,7 +25,7 @@ function close(aout::AnalogOut) Status, (Moberg, Cint, AnalogOutChannel), aout.moberg, aout.index, aout.channel)) -end; +end function write(aout::AnalogOut, value::Cdouble) checkOK(ccall(aout.channel.write, diff --git a/adaptors/julia/DigitalIn.jl b/adaptors/julia/DigitalIn.jl index 74c455d4968dff9c5e594a45db9318ee53c3149f..66695e6012aca6c5871f5a1a0d758dbfef563871 100644 --- a/adaptors/julia/DigitalIn.jl +++ b/adaptors/julia/DigitalIn.jl @@ -7,16 +7,16 @@ mutable struct DigitalIn moberg::Moberg index::UInt32 channel::DigitalInChannel - DigitalIn(moberg::Moberg, index::Unsigned) = ( - channel = DigitalInChannel(0,0); + function DigitalIn(moberg::Moberg, index::Unsigned) + channel = DigitalInChannel(0,0) checkOK(ccall((:moberg_digital_in_open, "libmoberg"), Status, (Moberg, Cint, Ref{DigitalInChannel}), moberg, index, channel)); - self = new(moberg, index, channel); - finalizer(close, self); + self = new(moberg, index, channel) + finalizer(close, self) self - ) + end end function close(din::DigitalIn) @@ -35,4 +35,3 @@ function read(din::DigitalIn) din.channel.context, result)) return result[] != 0 end - diff --git a/adaptors/julia/DigitalOut.jl b/adaptors/julia/DigitalOut.jl index 7dc18b7f939b894ef4514e59f6eacebbc3c2d978..f23d118083407159226cd886f1cc34f46cea2dbe 100644 --- a/adaptors/julia/DigitalOut.jl +++ b/adaptors/julia/DigitalOut.jl @@ -7,16 +7,16 @@ mutable struct DigitalOut moberg::Moberg index::UInt32 channel::DigitalOutChannel - DigitalOut(moberg::Moberg, index::Unsigned) = ( - channel = DigitalOutChannel(0,0); + function DigitalOut(moberg::Moberg, index::Unsigned) + channel = DigitalOutChannel(0,0) checkOK(ccall((:moberg_digital_out_open, "libmoberg"), Status, (Moberg, Cint, Ref{DigitalOutChannel}), - moberg, index, channel)); - self = new(moberg, index, channel); - finalizer(close, self); + moberg, index, channel)) + self = new(moberg, index, channel) + finalizer(close, self) self - ) + end end function close(dout::DigitalOut) @@ -25,7 +25,7 @@ function close(dout::DigitalOut) Status, (Moberg, Cint, DigitalOutChannel), dout.moberg, dout.index, dout.channel)) -end; +end function write(dout::DigitalOut, value::Bool) checkOK(ccall(dout.channel.write, diff --git a/adaptors/julia/EncoderIn.jl b/adaptors/julia/EncoderIn.jl index b45046f5b1f258c30476442db36be2137a044c61..fd60f686d3ae3a81cf0a78c3f76cb02e9710138c 100644 --- a/adaptors/julia/EncoderIn.jl +++ b/adaptors/julia/EncoderIn.jl @@ -7,16 +7,16 @@ mutable struct EncoderIn moberg::Moberg index::UInt32 channel::EncoderInChannel - EncoderIn(moberg::Moberg, index::Unsigned) = ( - channel = EncoderInChannel(0,0); + function EncoderIn(moberg::Moberg, index::Unsigned) + channel = EncoderInChannel(0,0) checkOK(ccall((:moberg_encoder_in_open, "libmoberg"), Status, (Moberg, Cint, Ref{EncoderInChannel}), - moberg, index, channel)); - self = new(moberg, index, channel); - finalizer(close, self); + moberg, index, channel)) + self = new(moberg, index, channel) + finalizer(close, self) self - ) + end end function close(ein::EncoderIn) @@ -35,4 +35,3 @@ function read(ein::EncoderIn) ein.channel.context, result)) return result[] end - diff --git a/adaptors/julia/moberg.jl b/adaptors/julia/moberg.jl index e45888a2b7d500e01666cb0b0e43d23bd4431c2f..176ded28d1edb313b6e48a2887b67ac264bb0711 100755 --- a/adaptors/julia/moberg.jl +++ b/adaptors/julia/moberg.jl @@ -14,7 +14,7 @@ mutable struct moberg handle::Ptr{Nothing} end -function moberg() +function moberg() handle = ccall((:moberg_new, "libmoberg"), Ptr{Nothing}, ()) println(handle) m = moberg(handle) @@ -31,46 +31,46 @@ mutable struct moberg_analog_in context::Ptr{Nothing} do_read::Ptr{Nothing} handle::moberg - moberg_analog_in(m::moberg, index::Unsigned) = ( - self = new(); + function moberg_analog_in(m::moberg, index::Unsigned) + self = new() check_OK(ccall((:moberg_analog_in_open, "libmoberg"), moberg_status, (Ptr{Nothing}, Cint, Ref{moberg_analog_in}), - m.handle, index, self)); - self.handle = m; + m.handle, index, self)) + self.handle = m function close(channel::moberg_analog_in) println(channel) ccall((:moberg_analog_in_close, "libmoberg"), moberg_status, (Ptr{Nothing}, Cint, moberg_analog_in), channel.handle.handle, index, self) - end; - finalizer(close, self); + end + finalizer(close, self) self - ) + end end mutable struct moberg_analog_out context::Ptr{Nothing} do_write::Ptr{Nothing} handle::moberg - moberg_analog_out(m::moberg, index::Unsigned) = ( - self = new(); + function moberg_analog_out(m::moberg, index::Unsigned) + self = new() check_OK(ccall((:moberg_analog_out_open, "libmoberg"), moberg_status, (Ptr{Nothing}, Cint, Ref{moberg_analog_out}), - m.handle, index, self)); - self.handle = m; + m.handle, index, self)) + self.handle = m function close(channel::moberg_analog_out) println(channel) ccall((:moberg_analog_out_close, "libmoberg"), moberg_status, (Ptr{Nothing}, Cint, moberg_analog_out), channel.handle.handle, index, self) - end; - finalizer(close, self); + end + finalizer(close, self) self - ) + end end function read(ain::moberg_analog_in) @@ -92,12 +92,12 @@ end function test() m = moberg() println(m) - - for v in -10.0:2.0:10 + + for v in -10.0:2.0:10 for i in 30:31 try aout = moberg_analog_out(m, Unsigned(i)) - value = v + i - 32; + value = v + i - 32 write(aout, value) print("$value ") catch @@ -123,4 +123,5 @@ test() println("DONE") GC.gc() +GC.gc() # See https://github.com/JuliaCI/BenchmarkTools.jl/blob/af35d0513fe1e336ad0d8b9a35f924e8461aefa2/src/execution.jl#L1 println("Really DONE") diff --git a/adaptors/julia/test_moberg.jl b/adaptors/julia/test_moberg.jl index 3f3a22dcb0fe9a9e74cabe7cbb18749d5180689c..5e3ad8b3a633c2dc7c84b6a8004096551a3b9068 100644 --- a/adaptors/julia/test_moberg.jl +++ b/adaptors/julia/test_moberg.jl @@ -8,12 +8,12 @@ import MobergIO: read, write function test() m = MobergIO.Moberg() println(m) - - for v in -10.0:2.0:10 + + for v in -10.0:2.0:10 for i in 30:31 try aout = MobergIO.AnalogOut(m, Unsigned(i)) - value = v + i - 32; + value = v + i - 32 write(aout, value) print("$value ") catch ex