我目前正在实现gotmc / VISA软件包,以将SCPI命令发送到万用表。
但是每次我尝试连接到设备时,都会收到相同的消息:
libusb:设备或资源繁忙[代码-6]。
有没有办法解决这个问题? 从我读过的一本书中,我需要将内核与设备分离,但是可以从此软件包中分离吗?
如果还有另一个通过USB支持SCPI命令的软件包,我将不胜感激。
这是我的示例代码:
package main
import (
"fmt"
"io"
"log"
"time"
_ "github.com/gotmc/usbtmc/driver/google"
"github.com/gotmc/visa"
_ "github.com/gotmc/visa/driver/usbtmc"
)
const (
usbAddress string = "USB0::10893::4610::MY58130019::INSTR"
)
func main() {
fg, err := visa.NewResource(usbAddress)
usbtmc.De
if err != nil {
log.Fatal("Couldn't open the resource for the function generator")
}
}
答案 0 :(得分:1)
以下是一些可以尝试的事情:
usbtmc.De
行似乎不完整或有错字。您能提供完整的行吗?go.mod
中使用v0.4.0或更高版本。NewDeviceByVIDPID()
而不是NewDevice()
。$ ./myprogram -d=4
module github.com/myproj/myrepo
go 1.12
github.com/gotmc/usbtmc v0.4.0
package main
import (
"flag"
"log"
"time"
"github.com/gotmc/usbtmc"
_ "github.com/gotmc/usbtmc/driver/google"
)
var (
debugLevel uint
)
func init() {
const (
defaultLevel = 1
debugUsage = "USB debug level"
)
flag.UintVar(&debugLevel, "debug", defaultLevel, debugUsage)
flag.UintVar(&debugLevel, "d", defaultLevel, debugUsage+" (shorthand)")
}
func main() {
// Parse the config flags to determine the config JSON filename
flag.Parse()
// Create new USBTMC context and new device.
start := time.Now()
ctx, err := usbtmc.NewContext()
if err != nil {
log.Fatalf("Error creating new USB context: %s", err)
}
ctx.SetDebugLevel(int(debugLevel))
mm, err := ctx.NewDevice("USB0::10893::4610::MY58130019::INSTR")
// You could try the following instead:
// mm, err := ctx.NewDeviceByVIDPID(10893, 4610)
if err != nil {
log.Fatalf("NewDevice error: %s", err)
}
log.Printf("%.2fs to create new device.", time.Since(start).Seconds())
// Send a SCPI command to the multimeter.
mm.WriteString("*CLS\n")
// Close the multimeter and USBTMC context and check for errors.
err = mm.Close()
if err != nil {
log.Printf("error closing mm: %s", err)
}
err = ctx.Close()
if err != nil {
log.Printf("Error closing context: %s", err)
}
}