title: gousb - not an OUT endpoint
body: <p>I'm new to the go programming language. Trying to use <a href="https://github.com/kylelemons/gousb" rel="nofollow noreferrer">gousb</a> to access an epson receipt printer. </p>
  
  <p>So I took some example code from the repo and repurposed it a bit just to validate that I could access the printer. </p>
  
  <p>I can see the printer and enumerate the endpoints. I receive this output:</p>
  
  <pre><code>Printer found: 020.005 Receipt Printer M129C/TM-T70 (Seiko Epson Corp.)
  Length of device array: 1
  [0] 020.005 04b8 - 0202
    [0] Config 01 [1]
      [0]--------------[0]
      [0] Interface 00 Setup 00 [0]
        Vendor Specific Class (Vendor Specific Subclass)
        [0] [1] Endpoint #1 OUT bulk - unsynchronized data [64 0] [OUT]
        [1] [130] Endpoint #2 IN  bulk - unsynchronized data [64 0] [IN]
  </code></pre>
  
  <p>My understanding is that if I want to write something to the printer, I would open the endpoint that corresponds to [OUT]. Aand this is where my trouble begins.</p>
  
  <p>If I use <code>outEP, err := thePrinter.OpenEndpoint(1,0,0,0)</code>, I receive a seg fault. If I pass a 1, gousb assumes I'm trying to access endpoint 130 [IN].</p>
  
  <p>So.. What do I pass as the endpoint ID to access the OUT endpoint?</p>
  
  <p>Code:</p>
  
  <pre><code>package main
  
  import (
          "fmt"
          "strings"
  
          "github.com/kylelemons/gousb/usb"
          "github.com/kylelemons/gousb/usbid"
  
          "C"
  )
  
  func main() {
    ctx := usb.NewContext()
    defer ctx.Close()
  
  
    ctx.Debug(3)
  
    var thePrinter *usb.Device
  
    devs, _ := ctx.ListDevices(func(desc *usb.Descriptor) bool {
      if strings.Contains(usbid.Describe(desc), "Seiko Epson Corp") {
        fmt.Printf("Printer found: %03d.%03d %s\n", desc.Bus, desc.Address, usbid.Describe(desc))
        return true
      } else {
        return false
      }
  
    })
  
    fmt.Printf("Length of device array: %d\n", len(devs))
  
    for x, dev := range devs {
      fmt.Printf("[%d] %03d.%03d %s - %s\n", x, dev.Bus, dev.Address, dev.Vendor, dev.Product)
  
      for i, cfg := range dev.Configs {
        // This loop just uses more of the built-in and usbid pretty printing to list
        // the USB devices.
        fmt.Printf("  [%d] %s [%d]\n", i, cfg, cfg.Config)
        for j, alt := range cfg.Interfaces {
          fmt.Printf("    [%d]--------------[%d]\n", j, alt.Number)
          for k, iface := range alt.Setups {
            fmt.Printf("    [%d] %s [%d]\n", k, iface, iface.Number)
            fmt.Printf("      %s\n", usbid.Classify(iface))
            for l, end := range iface.Endpoints {
              fmt.Printf("      [%d] [%d] %s [%s]\n", l, end.Address, end, end.Direction() )
            }
          }
        }
        fmt.Printf("    --------------\n")
      }
  
  
  
      thePrinter=dev
    }
  
    outEP, err := thePrinter.OpenEndpoint(1,0,0,1)
  
    fmt.Printf("OpenEndpoint Err: [%s]\n", err)
  
    fmt.Printf("direction: [%s] %d\n", outEP.Info().Direction(), outEP.Info().Address)
  
    message := []byte("hi there!\n")
  
    _, outerr := outEP.Write(message)
  
    fmt.Printf("write Err: [%s]", outerr)
  
  }
  </code></pre>
  
  <p>EDIT: I was asked to examine the error returned by OpenEndpoint prior to looking at the value of the endpoint. Here is what was returned (it was nil)</p>
  
  <pre><code>OpenEndpoint Err: [%!s(&lt;nil&gt;)]
  direction: [IN] 130
  OpenEndpoint Err: [%!s(&lt;nil&gt;)]
  libusb: warning [libusb_exit] application left some devices open
  write Err: [usb: write: not an OUT endpoint]
  [Finished in 1.512s]
  </code></pre>
  
  <p>This is what I receive when I send an endpoint number of zero:</p>
  
  <pre><code>OpenEndpoint Err: [usb: unknown endpoint 00]
  libusb: warning [libusb_exit] application left some devices open
  panic: runtime error: invalid memory address or nil pointer dereference
  [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x41e94c4]
  
  goroutine 1 [running]:
  main.main()
      /Users/.../go/src/github.com/deltasonic/epson/main.go:63 +0xcb4
  exit status 2
  [Finished in 0.817s]
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I'm attempting this on a mac, Mac OS 10.12.</p>