Thank you very much. You are quite correct. An unbuffered file is ideal, and 
yes, linux only (OpenWrt). Thank you for pointing me to the posix module (and 
getFileHandle()). I am trying to decipher the most elegant way of accomplishing 
this, but am failing miserably. this is what I have (UsbDevice.devicePaths[0] 
is a string containing the path of the device file): 
    
    
    proc readDevice(dev: UsbDevice): DeviceReading =
      
      let devfd = posix.open(dev.devicePaths[0], posix.O_RDWR)
      # Close the file object when we are done with it
      defer: discard posix.close(devfd)
      
      #write trigger data to the device file
      let writepack = [0x01'u8, 0x86'u8, 0xff'u8, 0x01'u8, 0'u8, 0'u8, 0'u8, 
0'u8]
      let written = posix.write(devfd, cast [ptr uint8](unsafeAddr(writepack)), 
writepack.len)
      
      #now read until there is no more data for 100ms
      while true:
        var selector = newSelector[int]() # I don't need user data, so is int 
correct for T?
        selector.registerHandle(cast[int](devfd), {Read}, 0)
        var ready = selector.select(100)
        echo(ready)  # this is just to check that my selector is working.
        break
        #more code to come after the selector is working...........
    
    
    Run

But it won't compile: 
    
    
    $ sudo nim c -r temper.nim
    Hint: used config file '/etc/nim/nim.cfg' [Conf]
    Hint: system [Processing]
    Hint: temper [Processing]
    Hint: strutils [Processing]
    Hint: parseutils [Processing]
    Hint: math [Processing]
    Hint: bitops [Processing]
    Hint: algorithm [Processing]
    Hint: unicode [Processing]
    Hint: sets [Processing]
    Hint: hashes [Processing]
    Hint: os [Processing]
    Hint: times [Processing]
    Hint: options [Processing]
    Hint: typetraits [Processing]
    Hint: strformat [Processing]
    Hint: macros [Processing]
    Hint: posix [Processing]
    Hint: ospaths [Processing]
    Hint: re [Processing]
    Hint: pcre [Processing]
    Hint: rtarrays [Processing]
    Hint: tables [Processing]
    Hint: selectors [Processing]
    Hint: nativesockets [Processing]
    Hint: epoll [Processing]
    Hint: sequtils [Processing]
    temper.nim(105, 25) template/generic instantiation from here
    ../../../../usr/lib/nim/pure/ioselects/ioselectors_epoll.nim(475, 25) 
template/generic instantiation from here
    ../../../../usr/lib/nim/pure/ioselects/ioselectors_epoll.nim(390, 35) 
Error: undeclared field: 'SockLen'
    
    
    
    Run

Reply via email to