# ASM340 RS232 interface.
# Setup: >EINSTELLUNGEN>Extras>Seriell Schnittstelle#1
#   Typ: Seriell
#   >Konfiguration
#      Betriebsart: Tabelle
#      Zeitintervall: 1 s
#      Handshake: None
#      Versor.pin9: 5 Volt (not relevant)
#

namespace eval asm340 {} {
}

proc stdConfig::asm340 {} {
  controller std timeout=10

  # pollperiod 1 1
  obj ASM340 rd
  prop read asm340::read
  kids "ASM 340" {
    node p upd
    node text -text upd
  }
}


proc asm340::read {} {
  sct send "@@NOSEND@@"
  return asm340::update
}

proc asm340::update {} {
  if {[scan [sct result] "%s %s S=%s P=%s %s %s" x e s p t f] == 6} {
    sct update $s
    updateval [sct]/p $p
    if {$e ne "on"} {
      set tail "filament off"
    } else {
      set tail ""
    }
    updateval [sct]/text "$x $tail"
  } else {
    clientput "NO"
    sct geterror "syntax error"
    hsetprop [sct]/p geterror "syntax error"
    updateval [sct]/text [sct result]
    clientput "NO [sct result]"
  }
  return idle
}
