Esempio n. 1
0
//向io接口写入数据
func WritePortData(port string, baud int, writedata []byte) error {
	w, err := hardware.GetPortInstance(port, baud)
	if err != nil {
		return err
	}
	defer w.Close()
	err = WriteData(w, writedata)

	return err
}
Esempio n. 2
0
func (jst *OkiPrinter) BeginPrintJob(pin *driverlayer.DriverArg, timeout int) error {
	if jst.w != nil {
		return PR2ALREADYINJOB
	}
	w, err := hardware.GetPortInstance(pin.Port, pin.Baud)
	if err != nil {
		return err
	}
	jst.w = w
	return nil
}
Esempio n. 3
0
//往接口中写入数据,读取数据。返回条件
//1 读到ter结束符后返回.如果ter后有多余字符,将被截断
//2 流结束
//3 读取错误
//4 超时
//5 超时后执行的指令
func WritePortAndReadWithTerminator(port string, baud int, writedata []byte, ter []byte, timeout int, ains []byte) ([]byte, error) {
	utils.Trace("received WritePortAndReadWithTerminator,port is %s", port)
	w, err := hardware.GetPortInstance(port, baud)
	if err != nil {
		return nil, err
	}
	defer w.Close()
	b, s := WriteAndReadWithTer(w, writedata, ter, timeout)
	if s == ErrIOTimeOut && ains != nil && len(ains) > 0 {
		utils.Info("detected device oper exceed maxinum time,write instructon : %x", ains)
		WriteData(w, ains)
	}
	return b, s
}
Esempio n. 4
0
//获得所有硬件列表
func (p *ConfigProtocol) GetAllHardWare(r *http.Request, arg *JsonUpdateInputAgr, res *JsonResponse) error {
	utils.Debug("received ConfigProtocol GetAllHardWare request")
	//列举com口
	s := []string{"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10"}
	bs := bytes.NewBufferString("")
	for _, t := range s {

		w, err := hardware.GetPortInstance(t, 9600)

		if err == nil {
			bs.WriteString(t)
			bs.WriteString(",")
			w.Close()
		}
	}
	bs.WriteString("USB1")

	res.Code = 0
	res.ResMsg = bs.String()

	utils.Debug("end ConfigProtocol GetAllHardWare request,return data is [%s]", bs.String())
	return nil
}