Add a driver for the Omron ZS-HLDC Laser Displacement device

This commit is contained in:
Douglas Clowes
2014-06-16 17:37:20 +10:00
parent fa3154bdcd
commit fce610a142
3 changed files with 366 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
# Simple driver generator for the Omron ZS-HLDC Laser Displacement
# vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent
#
driver omron_hldc = {
debug_threshold = 5;
vendor = Omron; device = 'ZS-HDLC'; protocol = std;
class = environment;
simulation_group = environment_simulation;
group = {
readable = 1;
var id = {
type = text
read_function = read_id; read_command = '0501';
}
var distance = {
type = float
read_function = read_mm; read_command = '0201C02030008001'; }
}
code getValue = {%%
set cmd "00000${cmd}"
%%}
code read_id = {%%
if {[string length ${data}] < 14} {
sct geterror "read_id short response ${data}"
} else {
set data [string range ${data} 14 end]
}
%%}
code read_mm = {%%
if {[string length "${data}"] < 34} {
sct geterror "read_mm short response ${data}"
} else {
set hex [string range ${data} 26 end]
debug_log ${tc_root} 1 "hex = ${hex}"
set n [scan "${hex}" "%x" val]
if {${n} == 1} {
set data [expr {0.000001 * ${val}}]
} else {
sct geterror "read_mm n = ${n} for hex = ${hex}"
}
}
%%}
}