Hi,
I apologize for not posting a working example, but I haven’t figured out how to make it.
The problem is, I have an fpga hooked up to the usb on my Ubuntu-box. The ftdi-driver makes it look like an uart, a serial port, /dev/fpga. It works like this, I send it a short string to start it. I read output for a minute, then send a new short string to stop the output, change some parameters, and restart output, and read for another minute. And so on. Here’s the problem:
So it looks something like this:
io = open("/dev/fpga", read=true, write=true)
for i in 1:N
write(io,"p N=$i "); flush(io) # change parameter
write(io,"r"); flush(io) # resume
while <less than a minute passed>
read!(io,buffer)
process(buffer) # mainly a push! on an array
end
write(io,"s"); flush(io) # stop
<spawn some post-processing>
end
Now, the problem is that the fpga has quite some speed, and it manages to write several bytes between the final read! and the stop command at the end of the loop. This is not a problem, these bytes will be ignored by the processing routine.
However, when strace’ing reads and writes it transpires that the string “p N=$i” at the top of the loop has a few bytes prepended in the (system) write(), and it turns out to be bytes which the fpga has written to me and which I have not yet read (and which I will discard in the loop). These are then written back to the fpga. Occasionally, these bytes will be interpreted by the fpga as a command, and havoc ensues. The serial line is in raw-mode (i.e. with cfmakeraw()), verified by stty, no echo and such stuff.
It looks like the read() and write() shares a buffer. Things work fine when I replace open/read/write with ccall’s to open/read/write, i.e. when I bypass julia IO.
Is there a julia-workaround? I suppose I can use two opens, one for read and one for write, but that’s a bit awkward.