Hi,
I’m trying to make a ccall to ioctl, but I seem to be getting the parameter types wrong. Here’s some code:
const I2C_SLAVE = 0x0703
addr = 0x1D
if ((file = open(filename,"r+")) < 0)
error("Failed to open the bus.")
# ERROR HANDLING; you can check errno to see what went wrong
return
end
ret = -1
ret = ccall((:ioctl, "libc"), Int, (Int, Int, Ptr{UInt8}), file, I2C_SLAVE, addr)
if (ret < 0)
error("Failed to acquire bus access and/or talk to slave.")
# ERROR HANDLING; you can check errno to see what went wrong
end
I get the following error:
ERROR: MethodError: no method matching unsafe_convert(::Type{Ptr{UInt8}}, ::UInt8)
Closest candidates are:
unsafe_convert(::Type{Ptr{UInt8}}, ::Symbol) at pointer.jl:35
unsafe_convert(::Type{Ptr{UInt8}}, ::String) at pointer.jl:37
unsafe_convert(::Type{T<:Ptr}, ::T<:Ptr) where T<:Ptr at essentials.jl:152
…
Stacktrace:
[1] anonymous at ./:?
Here’s the info. on iotcl():
The ioctl() function manipulates the underlying device parameters of special files. In particular, many operating characteristics of character special files (e.g. terminals) may be controlled with ioctl() requests. The argument d must be an open file descriptor.
The second argument is a device-dependent request code. The third argument is an untyped pointer to memory. It’s traditionally char *argp (from the days before void * was valid C), and will be so named for this discussion.
An ioctl() request has encoded in it whether the argument is an in parameter or out parameter, and the size of the argument argp in bytes. Macros and defines used in specifying an ioctl() request are located in the file <sys/ioctl.h>.
RETURN VALUE
Usually, on success zero is returned. A few ioctl() requests use the return value as an output parameter and return a nonnegative value on success. On error, -1 is returned, and errno is set appropriately.
Thanks.