namespace eval pfeiffermulti {} {
}

proc stdConfig::pfeiffermulti {} {
  variable node

  controller std "" 5 
  prop read pfeiffermulti::read
  prop update pfeiffermulti::update

  obj TPGM rd
  prop cmd PR1
  prop @errorcnt 0

  kids TPG {
    node p2 rd
    prop cmd PR2

    node p3 rd
    prop cmd PR3

    node p4 rd
    prop cmd PR4

    node p5 rd
    prop cmd PR5

    node p6 rd
    prop cmd PR6

    # node prx rd -text
    # prop cmd PRX

    # node sp1 rd -text
    # prop cmd SP1

    # node sp2 rd -text
    # prop cmd SP2

    # node sps rd -text
    # prop cmd SPS
  }
}

proc pfeiffermulti::read {} {
  sct send "[sct cmd]\r\n"
  return update
}

proc pfeiffermulti::update {} {
  scan [sct result] %c ack
  if {$ack == 6} {
    sct send "\005"
    return pfeiffermulti::update2
  }
  if {$ack == 21} {
    error "NAK received on [sct cmd]"
  }
  return [pfeiffermulti::read]
}

proc pfeiffermulti::update2 {} {
  if {[string match "PR*" [sct cmd]]} {
    sct update [lindex [split [sct result] ,] 1]
  } else {
    sct update [sct result]
  }
  sct @errorcnt 0
  return idle
}

