1 | abstract | |
2 | [This program is handling the Minolta spectocolorimeter] | |
3 | ||
4 | module "/pliant/language/unsafe.pli" | |
5 | module "/pliant/language/context.pli" | |
6 | module "/pliant/language/stream.pli" | |
7 | module "/pliant/language/stream/serial.pli" | |
8 | if os_api="linux" | |
9 | module "/pliant/admin/execute.pli" | |
10 | module "/pliant/linux/kernel/module.pli" | |
11 | module "/pliant/linux/kernel/device.pli" | |
12 | module "spectrum.pli" | |
13 | ||
14 | constant trace false | |
15 | constant model "spectrolino" # "minolta" | |
16 | ||
17 | gvar Stream spectro | |
18 | gvar DateTime spectro_datetime | |
19 | gvar Int spectro_counter := 0 | |
20 | ||
21 | function spectro_line -> s | |
22 | arg Str s | |
23 | s := spectro readline | |
24 | if trace | |
25 | console s eol | |
26 | if (s 0 1)="." | |
27 | s := "0"+s | |
28 | ||
29 | function spectro_command s cmd -> a | |
30 | arg_rw Stream s ; arg Str cmd a | |
31 | s writeline "; "+cmd | |
32 | a := s readline | |
33 | console "; " cmd " -> " a eol | |
34 | ||
35 | ||
36 | function spectro_init | |
37 | if os_api="linux" | |
38 | kernel_load_module "8250_pci" | |
39 | kernel_make_device "device:/ttyS0" | |
40 | spectro open "serial:"+(shunt os_api="linux" "0" "1") "speed 9600 flowcontrol [dq]none[dq]" in+out+safe+cr+lf | |
41 | spectro configure "timeout 30" | |
42 | if model="spectrolino" | |
43 | if not ((spectro_command spectro "208 36") parse ": 209" any) # output status | |
44 | spectro open "" in+out+safe | |
45 | return | |
46 | if ((spectro_command spectro "208 5 0") parse ":" "209" "129" "0" "0" (var Int ix) (var Int iy) (var Int iz)) # query position | |
47 | spectro_command spectro "208 10" # set device online | |
48 | spectro_command spectro "208 12" # hold paper | |
49 | spectro_command spectro "208 11" # init spectrolino connection | |
50 | spectro_command spectro "90 1 4 5" # reset the spectrolino | |
51 | spectro_command spectro "77 155" # reflectance measure | |
52 | spectro_command spectro "22 0 1 3 0" # colorimetric parameters: white base is absolute | |
53 | spectro_command spectro "208 6 0" # move to white reference | |
54 | spectro_command spectro "208 4" # move down | |
55 | if (spectro_command spectro "34 9 7")<>": 37 19" # white calibration | |
56 | spectro open "" in+out+safe | |
57 | return | |
58 | spectro_command spectro "0" # query parameters: last should be 1 = no filter | |
59 | spectro_command spectro "208 3" # move up | |
60 | spectro_command spectro "208 0 0 "+string:ix+" "+string:iy # move | |
61 | spectro_command spectro "208 13" # release paper | |
62 | spectro_command spectro "208 11" # set device offline | |
63 | else | |
64 | spectro open "" in+out+safe | |
65 | ||
66 | function spectro_spectrum -> cs | |
67 | arg ColorSpectrum cs | |
68 | cs := var ColorSpectrum no_spectrum | |
69 | if spectro:name="" | |
70 | if os_api="linux" | |
71 | kernel_load_module "8250_pci" | |
72 | kernel_make_device "device:/ttyS0" | |
73 | spectro open "serial:"+(shunt os_api="linux" "0" "1") "speed 9600 flowcontrol [dq]none[dq]" in+out+safe+cr+lf | |
74 | spectro configure "timeout 30" | |
75 | if model="minolta" | |
76 | spectro writeline "MSC" | |
77 | cs set_step 10 | |
78 | var Int w := 400 | |
79 | var Str listing := "" | |
80 | while { var Str l := spectro_line ; listing += "[lf]"+l ; l<>"" } | |
81 | if (l parse (var Float f)) | |
82 | cs set_measure w f*0.01 | |
83 | w += 10 | |
84 | if w<>710 or { var Str l := spectro_line ; listing += "[lf]"+l ; l<>"Yxy" } | |
85 | cs := var ColorSpectrum undefined_color_spectrum | |
86 | error error_id_unexpected "Unexpected answer from the spectrocolorimeter:"+listing | |
87 | spectro_line parse (var Float Y) | |
88 | spectro_line parse (var Float x) | |
89 | spectro_line parse (var Float y) | |
90 | if trace | |
91 | console " Yxy fourni = " Y " " x " " y eol | |
92 | var ColorXYZn xyzn := cs XYZn illuminant | |
93 | var Float X2 := xyzn:Xn*illuminant:X/100 | |
94 | var Float Y2 := xyzn:Yn*illuminant:Y/100 | |
95 | var Float Z2 := xyzn:Zn*illuminant:Z/100 | |
96 | var Float x2 := X2/(X2+Y2+Z2) | |
97 | var Float y2 := Y2/(X2+Y2+Z2) | |
98 | console " Yxy calcul頽 " Y2 " " x2 " " y2 eol | |
99 | eif model="spectrolino" | |
100 | if spectro_counter=0 or datetime:seconds-spectro_datetime:seconds>3600 | |
101 | if ((spectro_command spectro "208 36") parse ": 209" any) # output status | |
102 | if ((spectro_command spectro "208 5 0") parse ":" "209" "129" "0" "0" (var Int ix) (var Int iy) (var Int iz)) # query position | |
103 | spectro_command spectro "208 16" # set device online | |
104 | spectro_command spectro "208 18" # hold paper | |
105 | spectro_command spectro "208 11" # init spectrolino connection | |
106 | spectro_command spectro "90 1 4 5" # reset the spectrolino | |
107 | spectro_command spectro "77 155" # reflectance measure | |
108 | spectro_command spectro "22 0 1 3 0" # colorimetric parameters: white base is absolute | |
109 | spectro_command spectro "208 6 0" # move to white reference | |
110 | spectro_command spectro "208 4" # move down | |
111 | if (spectro_command spectro "34 9 7")=": 37 19" # white calibration | |
112 | spectro_datetime := datetime | |
113 | spectro_counter := 30 | |
114 | spectro_command spectro "0" # query parameters: last should be 1 = no filter | |
115 | spectro_command spectro "208 3" # move up | |
116 | spectro_command spectro "208 0 0 "+string:ix+" "+string:iy # move | |
117 | spectro_command spectro "208 19" # release paper | |
118 | spectro_command spectro "208 17" # set device offline | |
119 | if spectro_counter>0 and ((spectro_command spectro "208 5 0") parse ":" "209" "129" "0" "0" (var Int ix) (var Int iy) (var Int iz)) # query position | |
120 | spectro_command spectro "208 16" # set device online | |
121 | spectro_command spectro "208 18" # hold paper | |
122 | if ((spectro_command spectro "208 7 "+string:ix+" "+(string iy+230)) parse ":" "16" "9" "0" any:(var Str spec)) # move, down, measure, up | |
123 | cs set_step 10 | |
124 | var Int w := 380 | |
125 | while (spec parse (var Float d) any:(var Str remain)) and w<=730 | |
126 | cs set_measure w d | |
127 | w += 10 ; spec := remain | |
128 | spectro_command spectro "208 0 0 "+string:ix+" "+string:iy # move | |
129 | spectro_command spectro "208 19" # release paper | |
130 | spectro_command spectro "208 17" # set device offline | |
131 | spectro flush anytime | |
132 | spectro_counter -= 1 | |
133 | ||
134 | ||
135 | export spectro_init spectro_spectrum | |