IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

problème ouverture fichier pour carte relais usb k8055


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    69
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2010
    Messages : 69
    Par défaut problème ouverture fichier pour carte relais usb k8055
    bonjour, j'ai acheter une carte a relais usb k8055 de velleman que j'ai réussi a faire fonctionner dans le terminal (merci google). j'aimerais mtn développer un logiciel en python pour la gérer comme j'en ai envie.

    j'ai donc trouver du code sur internet mais j'ai un problème:

    j'ai cette ligne :

    self.lib = WinDLL("K8055D.dll")

    qui devrais ouvrir k8055d.dll mais il me dit toujours que le fichier est introuvable alors qu'il se trouve dans le mm dossier

    que faire ?
    merci


    ps, code complet:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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()

  2. #2
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 677
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 677
    Par défaut
    Salut,

    Le "même folder" est relatif au répertoire courant de l'utilisateur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    >>> sys.path.append('\src')  # je pose le truc "ailleurs"...
    >>> import pyk8055
    >>> pyk8055.device()
    Loading K8055 dll... failed!
    Failed to find K8055d.dll in local folde
    <pyk8055.device instance at 0x02384C38>
    Si vous voulez "dans le répertoire courant du script/module pyk8055.py", il faut modifier l'__init__ par exemple en:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
            print "Loading K8055 dll...",
            name = os.path.join(os.path.dirname(__file__), "K8055D.dll")
            try:
                self.lib = WinDLL(name)
                print "done."
            except:
                print "failed!"
                print "Failed to find K8055d.dll in local folder."
                return
    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    69
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2010
    Messages : 69
    Par défaut
    salut et merci pour ton aide mais maintenant il me dit que "global name 'os' is not defined" et d'ailleur il sort d'ou ce os ?

    merci

  4. #4
    Membre Expert

    Homme Profil pro
    Diverses et multiples
    Inscrit en
    Mai 2008
    Messages
    662
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Diverses et multiples

    Informations forums :
    Inscription : Mai 2008
    Messages : 662
    Par défaut
    Hem… os est un module standard de python, il faut donc faire un import os d’abord…

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    69
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2010
    Messages : 69
    Par défaut
    j'ai la mm erreur qu'avant: il ne trouve pas le fichier k8055d.dll et voici mon code actuelle:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    from ctypes import *
     
    import os
     
     
     
    class device():
     
    	def __init__(self,port=0):
     
    		print "Loading K8055 dll...",
     
    		name = os.path.join(os.path.dirname(__file__), "K8055D.dll")
     
    		try:
     
    			self.lib = WinDLL(name)
     
    			print "done."
     
    		except:
     
    			print "failed!"
     
    			print "Failed to find K8055d.dll in local folder."
     
    			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)."
    merci

  6. #6
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 677
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 677
    Par défaut
    Salut,

    Il n'y a pas de problème particulier avec le code...
    Mais plutôt sur comment vous le lancez.

    Pourriez vous nous montrer la suite de commandes que vous effectuez depuis le lancement de l'interpréteur Python?

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

Discussions similaires

  1. [EXCEL - VBA] Problème ouverture fichier suite Macro Userform
    Par Guidhy dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 26/04/2007, 09h18
  2. [Upload] Problème ouverture fichier joint
    Par vincedjs dans le forum Langage
    Réponses: 4
    Dernier message: 27/03/2006, 11h24
  3. forcer le téléchargement - problème ouverture fichier
    Par grinder59 dans le forum Langage
    Réponses: 8
    Dernier message: 09/03/2006, 15h59
  4. problème ouverture fichier texte
    Par ice-t69 dans le forum Langage
    Réponses: 4
    Dernier message: 07/11/2005, 19h29
  5. Problème ouverture fichier par double clic...
    Par sankookai dans le forum MFC
    Réponses: 4
    Dernier message: 11/05/2005, 09h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo