OSDN Git Service

123123
[psychlops/cpp.git] / psychlops / platform / win32 / psychlops_devices_parallelport_Win32.cpp
1 /*
2  *  psychlops_devices_nidaqmxbase.cpp
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2009/04/14 by Kenchi HOSOKAWA
6  *  (C) 2009 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9
10 #include <windows.h>
11 #include "../../core/math/psychlops_m_util.h"
12 #include "../../extension/devices/psychlops_devices_parallelport.h"
13
14
15 namespace Psychlops {
16 namespace Devices {
17 \r
18         //http://support.microsoft.com/kb/413279/JA\r
19         //https://msdn.microsoft.com/ja-jp/library/cc429198.aspx\r
20         //http://support.microsoft.com/kb/823179/ja
21
22         GenericParallelPort::GenericParallelPort(std::string port_name, size_t pin) : pins(pin) {\r
23                 if (!(handle = CreateDC(NULL , port_name.c_str() , NULL , NULL))) {\r
24                         handle = 0;\r
25                         throw new Exception("Parallel port was not found.");\r
26                 }\r
27         }
28         GenericParallelPort::~GenericParallelPort() {\r
29                 if(handle!=0) {\r
30                         DeleteDC((HDC)handle);\r
31                 }\r
32         }\r
33
34         void GenericParallelPort::trigger() {\r
35                 DOCINFO diInfo = {0};\r
36                 diInfo.cbSize = sizeof (DOCINFO);\r
37                 diInfo.lpszDocName = "";\r
38                 if (StartDoc((HDC)handle , &diInfo) > 0) {\r
39                         TextOut((HDC)handle , 0 , 0 , &pins , 1);\r
40                         EndDoc((HDC)handle);\r
41                 }\r
42         }
43
44         void GenericParallelPort::trigger(int dn) {\r
45                 int n=1;\r
46                 if(dn>0) { n=dn; }\r
47                 DOCINFO diInfo = {0};\r
48                 diInfo.cbSize = sizeof (DOCINFO);\r
49                 diInfo.lpszDocName = "";\r
50                 if (StartDoc((HDC)handle , &diInfo) > 0) {\r
51                         for(int i=0; i<n; i++) { TextOut((HDC)handle , 0 , 0 , &pins , 1); }\r
52                         EndDoc((HDC)handle);\r
53                 }\r
54         }\r
55
56         void GenericParallelPort::trigger(const char *data, size_t length) {\r
57                 DOCINFO diInfo = {0};\r
58                 diInfo.cbSize = sizeof (DOCINFO);\r
59                 diInfo.lpszDocName = "";\r
60                 if (StartDoc((HDC)handle , &diInfo) > 0) {\r
61                         TextOut((HDC)handle , 0 , 0 , data, length);\r
62                         EndDoc((HDC)handle);\r
63                 }\r
64         }
65
66         void GenericParallelPort::trigger(std::string data) {\r
67                 DOCINFO diInfo = {0};\r
68                 diInfo.cbSize = sizeof (DOCINFO);\r
69                 diInfo.lpszDocName = "";\r
70                 if (StartDoc((HDC)handle , &diInfo) > 0) {\r
71                         TextOut((HDC)handle , 0 , 0 , data.c_str(), data.length());\r
72                         EndDoc((HDC)handle);\r
73                 }\r
74         }
75
76 }
77 }       /*      <- namespace Psycholops         */\r
78