Yuyuchao - I was thinking about this all before I went to bed, last night. This is the code [not working yet].
const NCCS = 20
@ctypedef tcflag_t Culong
@ctypedef cc_t Cuchar
@ctypedef speed_t Clong
mutable struct termios
c_iflag::tcflag_t #input flags
c_oflag::tcflag_t #output flags
c_cflag::tcflag_t #control flags
c_lflag::tcflag_t #local flags
c_cc::NTuple{NCCS,cc_t} #control chars
c_ispeed::speed_t #input speed
c_ospeed::speed_t #output speed
end
function set_interface_attribs(fd::Int, speed::Int, parity::Int)
tty = termios(0,0,0,0,(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),0,0)
ret = ccall((:tcgetattr, "libc"), Int32, (Int32, Ref{termios}), fd, tty)
if (ret != 0)
println("error from tcgetattr")
return -1
end
ccall((:cfsetospeed, "libc"), Void, (Ref{termios}, Int32), tty, speed)
ccall((:cfsetispeed, "libc"), Void, (Ref{termios}, Int32), tty, speed)
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8 # 8-bit chars
# disable IGNBRK for mismatched speed tests otherwise receive break
# as \000 chars
tty.c_iflag &= ~IGNBRK # disable break processing
tty.c_lflag = 0 # no signaling chars, no echo,
# no canonical processing
tty.c_oflag = 0 # no remapping, no delays
tty.c_cc[VMIN] = 0 # read doesn't block
tty.c_cc[VTIME] = 5 # 0.5 seconds read timeout
tty.c_iflag &= ~(IXON | IXOFF | IXANY) # shut off xon/xoff ctrl
tty.c_cflag |= (CLOCAL | CREAD)# ignore modem controls,
# enable reading
tty.c_cflag &= ~(PARENB | PARODD) # shut off parity
tty.c_cflag |= parity
tty.c_cflag &= ~CSTOPB
tty.c_cflag &= ~CRTSCTS
ret = ccall((:tcsetattr, "libc"), Int32, (Int32, Int32, Ref{termios}), fd, TCSANOW, tty)
if (ret != 0)
println("error from tcsetattr")
return -1
end
return 0
end
If part of struct that is getting passed in to the routines above [tcgetattrib and tcsetattrib] is an immutabe NTuple - then how does the C library calls make modifications to that part of the struct? This is all very confusing compared to making system calls from other languages. Can you explain a little better what is going on in my calls to tcgetattrib and tcsetattrib and is there a better way of doing what I’m trying to accomplish?
BTW - the goal of this code is so I can do away with two C programs that I wrote that I am calling from Julia that allow me to interact with a serial port [connected to an Arduino]. The serial libraries don’t work because I am using 32-bit versions of Julia on several development boards [RPi, Beaglebone, Udoo x86] on a Beowulf cluster.
Frank