comparison kk-data-provider.c @ 94:b7ae2d947617

Change default KK port to COM4. Make port configurable via .ini file
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 22 Mar 2013 18:46:13 +0100
parents 4102fe614df2
children 4a11331eacbf
comparison
equal deleted inserted replaced
93:72c46cdfb808 94:b7ae2d947617
2 2
3 #include <ansi_c.h> 3 #include <ansi_c.h>
4 #include <userint.h> 4 #include <userint.h>
5 #include <formatio.h> 5 #include <formatio.h>
6 #include <utility.h> 6 #include <utility.h>
7 #include <inifile.h>
7 8
8 #include "data-provider.h" 9 #include "data-provider.h"
9 #include "KKFX80E.h" 10 #include "KKFX80E.h"
10 11
11 #define SERIAL "COM1:115200" 12 #define CONFIGFILE "FXAnalise.ini"
13 #define DEFAULTPORT "COM4:115200"
12 14
13 int CVICALLBACK KKDataProvider (void *functionData) 15 int CVICALLBACK KKDataProvider (void *functionData)
14 { 16 {
15 int mainThreadId; 17 int mainThreadId;
16 char *resp; 18 char *resp;
17 struct event event; 19 struct event event;
20 char port[256];
18 21
19 /* get main thread id to post messages to it */ 22 /* get main thread id to post messages to it */
20 mainThreadId = CmtGetMainThreadID(); 23 mainThreadId = CmtGetMainThreadID();
21 24
25 /* path for the configuration file */
26 char pathname[MAX_PATHNAME_LEN];
27 char project[MAX_PATHNAME_LEN];
28 GetProjectDir(project);
29 MakePathname(project, CONFIGFILE, pathname);
30
31 /* load configuration file */
32 IniText configuration = Ini_New(TRUE);
33 Ini_ReadFromFile(configuration, pathname);
34
35 /* get serial port name configuration */
36 int rv = Ini_GetStringIntoBuffer(configuration, "KK", "port", port, sizeof(port));
37 if (rv == 0)
38 strncpy(port, DEFAULTPORT, sizeof(port));
39
40 /* free */
41 Ini_Dispose(configuration);
42
22 /* initialize library */ 43 /* initialize library */
23 FX_Init(); 44 FX_Init();
24 /* connect to KK FX80E counter */ 45 /* connect to KK FX80E counter */
25 FX_Open(SERIAL); 46 FX_Open(port);
26 47
27 /* clear transmit buffer */ 48 /* clear transmit buffer */
28 FX_Send("\x80"); 49 FX_Send("\x80");
29 FX_Recv(&resp); 50 FX_Recv(&resp);
30 /* set report interval 1sec */ 51 /* set report interval 1sec */