OSDN Git Service

parallel
[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         ParallelPort::ParallelPort(size_t pin) : pins(pin) {\r
23                 handle = CreateFile("LPT1", GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);\r
24                 if(handle == INVALID_HANDLE_VALUE) {\r
25                         std::cout << "Failed to open parallel port." <<std::endl;\r
26                         handle = 0;\r
27                 }\r
28         }
29         ParallelPort::~ParallelPort() {\r
30                 if(handle!=0) {\r
31                         CloseHandle(handle);\r
32                 }\r
33         }\r
34
35         double ParallelPort::getLatency() { return -1; }
36         double ParallelPort::getJitterSD() { return -1; }
37         Interval ParallelPort::getRange() { Interval i; return 0<=i<=5; }
38         bool ParallelPort::isAnalog() { return false; }\r
39
40         double ParallelPort::get() { return 0; }
41         void ParallelPort::put(double v) { ; }
42         void ParallelPort::pulse(double v) {\r
43                 unsigned char buff[1];\r
44                 DWORD writtenbytes;\r
45                 OVERLAPPED m_write;\r
46 \r
47                 buff[0] = pins;\r
48 \r
49                 WriteFile(handle, buff, 1, &writtenbytes, &m_write);\r
50         }
51         void ParallelPort::keep(double v) { ; }
52
53 }
54 }       /*      <- namespace Psycholops         */\r
55