diff KKFX80E.c @ 89:c9e4f63c2033

Implement data acquisition through direct communication with the KK counter
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 21 Mar 2013 19:00:22 +0100
parents
children 4f1f353e84f5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KKFX80E.c	Thu Mar 21 19:00:22 2013 +0100
@@ -0,0 +1,110 @@
+#include <ctype.h>
+#include <windows.h>
+
+int (_stdcall *FX_OpenPort)(char **Port) = NULL;
+void (_stdcall *FX_ClosePort)(void) = NULL;
+int (_stdcall *FX_SendCommand)(char **Command) = NULL;
+int (_stdcall *FX_GetReport)(char **Data) = NULL;
+void (_stdcall *FX_Debug)(BOOL DbgFlag) = NULL;
+// int (_stdcall *GetFXM)(char **Data) = NULL;
+// void (_stdcall *Log)(int DbgNum) = NULL;
+// int (_stdcall *ReadMonitor)(char **Data) = NULL;
+// BOOL (_stdcall *EnumeratePorts)(char **PortName, char *PortNamePrefix) = NULL;
+
+static HMODULE module;
+
+
+int FX_Init(void)
+{
+	FARPROC funcp;
+	
+	module = LoadLibrary("KK_FX80E.dll");
+	if (! module)
+		return 0;
+	
+	funcp = GetProcAddress(module, "FX_OpenPort");
+  	if (! funcp)
+		goto error;
+	FX_OpenPort = (void *)funcp;
+	
+	funcp = GetProcAddress(module, "FX_ClosePort");
+  	if (! funcp)
+		goto error;
+	FX_ClosePort = (void *)funcp;
+	
+	funcp = GetProcAddress(module, "FX_SendCommand");
+  	if (! funcp)
+		goto error;
+	FX_SendCommand = (void *)funcp;
+	
+	funcp = GetProcAddress(module, "FX_GetReport");
+  	if (! funcp)
+		goto error;
+	FX_GetReport = (void *)funcp;
+	
+	funcp = GetProcAddress(module, "FX_Debug");
+  	if (! funcp)
+		goto error;
+	FX_Debug = (void *)funcp;
+	
+	return 1;
+	
+error:
+	FreeLibrary(module);
+	return 0;
+}
+
+
+void FX_Free(void)
+{
+	FreeLibrary(module);	
+}
+
+
+int FX_Open(char *port)
+{
+	int rv = FX_OpenPort(&port);
+#ifdef DEBUG
+	if (! rv)
+		fprintf(stderr, "%s\n", *port);
+#endif
+	return rv;
+}
+
+
+void FX_Close(void)
+{
+	FX_ClosePort();
+}
+
+
+int FX_Send(char *cmd)
+{
+	int rv = FX_SendCommand(&cmd);
+#ifdef DEBUG
+	if (! rv)
+		fprintf(stderr, "%s\n", cmd);
+#endif
+	return rv;
+}
+
+
+char * FX_Recv(char **ret)
+{
+	int rv;
+	char *data;
+	do {
+		data = ".";
+		rv = FX_GetReport(&data);
+	} while (! data);
+#ifdef DEBUG
+	if (! rv)
+		fprintf(stderr, "%s\n", data);
+#endif
+	if (! rv)
+		return NULL;
+	if (ret)
+		*ret = data;
+	
+	return data;
+}