1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
| '''
A Python module created to interact with the Velleman K8055 kit
Created By Fergus Leahy a.k.a. Fergul Magurgul
(https://sourceforge.net/projects/pyk8055/)
Copyright (C) 2010 Fergus Leahy (http://py-hole.blogspot.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
# - Requires K8055D.dll to be in the same directory/folder.
from ctypes import *
class device():
def __init__(self,port=0):
print "Loading K8055 dll...",
try:
print "a"
self.lib = WinDLL("K8055D.dll")
print "done."
except:
print "pas trouver"
return
print "Accessing the device on port %d..." % port,
self.lib.OpenDevice(port)
print "done."
def disconnect(self):
print "Diconnecting the device...",
self.lib.CloseDevice()
print "done."
def analog_in(self,channel):
print "Checking analogue channel %d..." % channel,
status = self.lib.ReadAnalogChannel(channel)
print "done."
return status
def analog_all_in(self):
data1,data2 = c_int(),c_int()
print "Checking all analogue channels...",
self.lib.ReadAllAnalog(byref(data1), byref(data2))
print "done."
return data1.value, data2.value
def analog_clear(self,channel):
print "Clearing analogue channel %d..." % channel,
self.lib.ClearAnalogChannel(channel)
print "done."
def analog_all_clear(self):
print "Clearing both analogue channels...",
self.lib.ClearAllAnalog()
print "done."
def analog_out(self,channel, value):
print "Changing the value of analogue channel %d to %d..." % (channel,value),
if 0 <= value <= 255:
self.lib.OutputAnalogChannel(channel,value)
print "done."
else:
print
print "Value must be between (inclusive) 0 and 255"
def analog_all_out(self,data1,data2):
print "Changing the value of both analogue channels...",
if 0 <= data1 <= 255 and 0 <= data2 <= 255:
self.lib.OutputAllAnalog(data1,data2)
print "done."
else:
print
print "Value must be between (inclusive) 0 and 255"
def digital_write(self, data):
print "Writing %d to digital channels..." %data,
self.lib.WriteAllDigital(data)
print "done."
def digital_off(self,channel):
print "Turning digital channel %d OFF..." % channel,
self.lib.ClearDigitalChannel(channel)
print "done."
def digital_all_off(self):
print "Turning all digital channels OFF...",
self.lib.ClearAllDigital()
print "done."
def digital_on(self,channel):
print "Turning digital channel %d ON..." % channel,
self.lib.SetDigitalChannel(channel)
print "done."
def digital_all_on(self):
print "Turning all digital channels ON...",
self.lib.SetAllDigital()
print "done."
def digital_in(self,channel):
print "Checking digital channel %d..." % channel,
status = self.lib.ReadDigitalChannel(channel)
print "done."
return status
def digital_all_in(self):
print "Checking all digital channels..." ,
status = self.lib.ReadAllDigital()
print "done."
return status
def counter_reset(self,channel):
print "Reseting Counter value...",
self.lib.ResetCounter(channel)
print "done,"
def counter_read(self,channel):
print "Reading Counter value from counter %d..." % channel,
status = self.lib.ReadCounter(channel)
print "done."
return status
def counter_set_debounce(self,channel,time):
if 0<= time <= 5000:
print "Setting Counter %d's debounce time to %dms..." % (channel,time),
self.lib.SetCounterDebounceTime(channel,time)
print "done."
else:
print "Time must be between 0 and 5000ms (inclusive)."
device() |
Partager