Example #1
0
func (jst *PinGeneral) Readonce(pin *driverlayer.DriverArg, timeout int) ([]byte, error) {
	utils.Debug("PinGeneral received Readonce request")
	s, _ := hex.DecodeString("1b49")
	t, _ := hex.DecodeString("83")
	utils.Debug("PinGeneral send readonce pi %x", s)
	b, e := driverlayer.WritePortAndReadWithTerminator(pin.Port, pin.Baud, s, []byte{0x03}, timeout, t)
	if e == nil {
		utils.Debug("begin process received data %x", b)
		b = b[1 : len(b)-1]
		utils.Debug("after process received data %x", b)
	}
	return b, e
}
Example #2
0
//向com口中写入任意数据即可
func (jst *SDMsf) Read(pin *driverlayer.DriverArg, read_type int, timeout int) ([]byte, error) {
	utils.Debug("SDMsf received read request")
	if read_type < 1 || read_type > 3 {
		utils.Error("not implementd read type %d,expected 1<=mode<=3", read_type)
		return nil, CARDNO_NOT_FORMULAED
	}
	var s []byte
	switch read_type {
	case 1:
		s, _ = hex.DecodeString("1b301b5d")
		break
	case 2:
		s, _ = hex.DecodeString("1b301b545d")
		break
	case 3:
		s, _ = hex.DecodeString("1b301b425d")
		break
	}
	b, e := driverlayer.WritePortAndReadWithTerminator(pin.Port, pin.Baud, s, []byte{0x3F}, timeout, nil)
	if e != nil {
		return nil, nil
	} else {
		var epos = 0
		if b[0] != 0x1b || b[1] != 0x73 {
			utils.Error("SDMsf data %s,left data not standard,expected %s", b, "1b73")
			return nil, CARDNO_NOT_FORMULAED
		}
		for i := 0; i < len(b); i++ {
			if b[i] == 0x41 && read_type == 3 {
				b[i] = '|'
			}
			if b[i] == 0x3f {
				epos = i
			}
		}
		b = b[2 : epos+1]

		return b, nil
	}

}