comparison kk-data-provider.c @ 185:bc980095a24d

Add scrambler option to KK data provider. Report KK counter version.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 24 Feb 2014 13:16:52 +0100
parents c96f5f64c946
children f105ac22da05
comparison
equal deleted inserted replaced
184:12df3a2b18de 185:bc980095a24d
18 18
19 int CVICALLBACK KKDataProvider (void *functionData) 19 int CVICALLBACK KKDataProvider (void *functionData)
20 { 20 {
21 int mainThreadId; 21 int mainThreadId;
22 int rv; 22 int rv;
23 char *resp; 23 char *cmd, *resp;
24 struct event event; 24 struct event event;
25 int nchan; 25 int nchan;
26 int scrambler;
26 char port[256]; 27 char port[256];
27 28
28 /* get main thread id to post messages to it */ 29 /* get main thread id to post messages to it */
29 mainThreadId = CmtGetMainThreadID(); 30 mainThreadId = CmtGetMainThreadID();
30 31
44 /* channel number */ 45 /* channel number */
45 rv = Ini_GetInt(configuration, "KK", "nchan", &nchan); 46 rv = Ini_GetInt(configuration, "KK", "nchan", &nchan);
46 if (! rv) 47 if (! rv)
47 nchan = DEFAULT_NCHAN; 48 nchan = DEFAULT_NCHAN;
48 49
50 /* enable scrambler */
51 rv = Ini_GetInt(configuration, "KK", "scrambler", &scrambler);
52 if (! rv)
53 scrambler = FALSE;
54
49 /* free */ 55 /* free */
50 Ini_Dispose(configuration); 56 Ini_Dispose(configuration);
51 57
52 /* initialize library */ 58 /* initialize library */
53 FX_Init(); 59 FX_Init();
69 if (! rv) { 75 if (! rv) {
70 SendMessage(mainThreadId, FX_Error()); 76 SendMessage(mainThreadId, FX_Error());
71 goto error; 77 goto error;
72 } 78 }
73 79
80 /* get counter hardware version string */
81 rv = FX_Send("\x81");
82 if (! rv) {
83 SendMessage(mainThreadId, FX_Error());
84 goto error;
85 }
86 rv = FX_Recv(&resp, TIMEOUT);
87 if (! rv) {
88 SendMessage(mainThreadId, FX_Error());
89 goto error;
90 }
91 /* wait for response */
92 while (strneq(resp, "7000", 4)) {
93 rv = FX_Recv(&resp, TIMEOUT);
94 if (! rv) {
95 SendMessage(mainThreadId, FX_Error());
96 goto error;
97 }
98 }
99 if (strneq(resp, "7001", 4))
100 SendMessage(mainThreadId, "KK Counter version: %s", resp + 4);
101
74 /* set report interval 1sec */ 102 /* set report interval 1sec */
75 rv = FX_Send("\x29"); 103 rv = FX_Send("\x29");
76 if (! rv) { 104 if (! rv) {
77 SendMessage(mainThreadId, FX_Error()); 105 SendMessage(mainThreadId, FX_Error());
78 goto error; 106 goto error;
82 SendMessage(mainThreadId, FX_Error()); 110 SendMessage(mainThreadId, FX_Error());
83 goto error; 111 goto error;
84 } 112 }
85 113
86 /* read nchan channels */ 114 /* read nchan channels */
87 char *cmd = "\x30"; 115 cmd = "\x30";
88 cmd[0] += nchan; 116 cmd[0] += nchan;
89 rv = FX_Send(cmd); 117 rv = FX_Send(cmd);
90 if (! rv) { 118 if (! rv) {
91 SendMessage(mainThreadId, FX_Error()); 119 SendMessage(mainThreadId, FX_Error());
92 goto error; 120 goto error;
107 if (! rv) { 135 if (! rv) {
108 SendMessage(mainThreadId, FX_Error()); 136 SendMessage(mainThreadId, FX_Error());
109 goto error; 137 goto error;
110 } 138 }
111 139
112 /* switch scrambler off */ 140 /* scrambler */
141 cmd = "\x50";
142 cmd[0] += scrambler;
113 rv = FX_Send("\x50"); 143 rv = FX_Send("\x50");
114 if (! rv) { 144 if (! rv) {
115 SendMessage(mainThreadId, FX_Error()); 145 SendMessage(mainThreadId, FX_Error());
116 goto error; 146 goto error;
117 } 147 }