J'essaye de programmer un séquencer, autrement dit choisir d'émettre un courant électrique en fonction du temps dans 8 sorties au choix. (le matériel : BV4111 relay controller)
j'utilise un port usb.
Voici la documentation
http://doc.byvac.com/index.php5?title=Product_BV4111

j'ai donc mis les modules nécessaires qui sont en tout en bas de la page ci dessus.

Problème j'ai testé BV4111_demo.py simplement en éditant ce programme dans eclipse et en faisant run message : "Com port needed as part of input"

en fait je veux simplement actionner une sortie puis l'éteindre après un certain temps, c'est ce que faisait me semble-t-il le programme BV4111_demo_py ...

voici le code de BV4111_demo_py
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
# Python 2.7 demonstration using the bv4109 class
 
from time import sleep
import sys
import BV4111
 
# ******************************************************************************
# D E M O for BV4111 - relay controller
# ******************************************************************************
def main():
    # input com port on start
    if len(sys.argv) < 2:
        print "Com port needed as part of input"
    else:
        # connect to serial port, this can be done in any maner but the 
        # connect in sv3cl is convenient
        sp = BV4111.sv3clV2_2.Connect(sys.argv[1],115200)
        # class instance for sv3 device, assume address 'a' and
        # default ack
        Devd = BV4111.bv4111(sp,'d')
        d = Devd.Discover()
        print "Discover() reports ",d
        if Devd.Active() !=0:
            print "Switching relay 1"
            for j in range(1,5):
                Devd.Rly(1,1,0)
                sleep(0.2) 
                Devd.Rly(1,0,0)
                sleep(0.2) 
            print "Switching relay 2"
            for j in range(1,5):
                Devd.Rly(2,1,0)
                sleep(0.2) 
                Devd.Rly(2,0,0)
                sleep(0.2) 
        else:
            print "Device address d not found"
            print "This may be because the device is not connected properly"
            print "If discover reports device d then increase the timeout"
            print "in the connect function in file sv3clV2_2.py"
        sp.close()    
 
if __name__ == "__main__":
    main()
Voici les deux autres codes des modules nécessaires : BV4111
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
 
# Device BV4111
# Serial relay driver for up to 8 relays, relays are designated
# 'a' throug 'g'
#
#
import sv3clV2_2
 
class bv4111(sv3clV2_2.sv3):
    # ******************************************************************************
    # R E L A Y  S E C T I O N
    # ******************************************************************************
 
    # ------------------------------------------------------------------------------
    # For convenience the relay 'a' throug 'g' is translated to a number 1 to 8
    # example for use:
    # Rly(3,1,50) # turns on relay 'c' in 50mS
    # returns 0 on sucess
    # ------------------------------------------------------------------------------
    def Rly(self,rly,onn,when):
        #rly+96 convert 1 to 'a' etc.
        cmd = chr(rly+96)+str(onn)+","+str(when)+"\r"
        self.Send(cmd)
        return self.Wack()
 
    # ------------------------------------------------------------------------------
    # returns timer value (integer) for specified relay
    # this time relay is specifed 1 to 8
    # ------------------------------------------------------------------------------
    def Val(self,rly):
        self.Send("r"+str(rly)+"\r")
        return self.Read()
 
    # ------------------------------------------------------------------------------
    # all relays off
    # ------------------------------------------------------------------------------
    def Alloff():
        self.Send("o\r")
        return self.Wack()
pour finir
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
 
# sv3clV2_2.py
#
# Verion 2.0  Implemented as a class separate from the serial connection
#   2.1 16/2/13: Changed how Wack works
#   2.2 23/7/13: Changes to the SV3 protocol
#       SV3 now default to 115200 Baud not autobaud 
#       Added 'H' command to discover devices.
#
# sv3 protocol for ByVac SV3 serial devices. This code can be imported for
# the required device. It contains the common commands and also has a small
# program for setting up the eeprom values.
#
# The serial communication in Python is by defualt text, text is sent and text
# is recieved so in the following code chr() and ord() is used to do the
# conversions
#
# To keep the code simple and easy to read, no range checking is done, you may
# want to add this later.
#
# Only connect 1 device when using the eeprom and some other commands.
#
import serial
from time import sleep
BAUD_RATES = { 2400:1, 4800:2, 9600:3, 14400:4, 19200:5, 38400:6, 115200:7 } 
 
# ------------------------------------------------------------------------------
# returns the comport connector for use with class. Can only open one instance
# of a serial connection so this has to be used accross classes when there
# is more than one device on the serial bus
# ------------------------------------------------------------------------------
def Connect(port,baud):
    return serial.Serial(port, baud, timeout=.05, stopbits=1, parity='N' )
 
 
# ------------------------------------------------------------------------------
# The class does not contain the serial connection but must be passed it. This
# enables more than one device on any serial bus
# ------------------------------------------------------------------------------
class   sv3:
    """SV3 Device Protocol ByVac Version 2.2"""
    sp = None   # sp is set to communication device by Init()
    adr = None # address is the address of the device this instance is addressing
    def __init__(self,com,address,ack='\006'):
        self.sp = com # communication instance
        self.adr = ord(address) # address of device for this instance
        self.ack = ack 
 
    # --------------------------------------------------------------------------
    # commands always start with address, this will send the address followed
    # by the string. NOTE it is up to the caller to supply the \r and Wack
    # --------------------------------------------------------------------------
    def Send(self,str):
        self.sp.flushInput()
        self.sp.write(chr(self.adr))
        self.sp.write(str)
 
    # --------------------------------------------------------------------------
    # nearly all commands ACK when finished
    # Will wait for ACK and return 0 if not received
    # --------------------------------------------------------------------------
    def Wack(self):
        k = None
        while k != '':
            k = self.sp.read(1)
            if k == '':
                return 0
            elif k == self.ack:
                return 1
 
    # --------------------------------------------------------------------------
    # reads characters up to ACK and returns them
    # note will return a string
    # --------------------------------------------------------------------------
    def Read(self):
        k = ''
        v = ''
        timeout = 100
        while k != self.ack:
            k = self.sp.read(1)
            if len(k) == 0: # timeout
                timeout-=1
                if timeout <= 0:
                    break
                else:
                    continue
            if k != self.ack:
                v = v + k
        return v
 
    # --------------------------------------------------------------------------
    # returns device ID as an integer
    # --------------------------------------------------------------------------
    def ID(self):
        self.Send('D')
        self.sp.write('\r')
        return self.Read()
 
    # --------------------------------------------------------------------------
    # returns firmware value as a string in the form "h.l"
    # --------------------------------------------------------------------------
    def Firmware(self):
        self.Send('V')
        self.sp.write('\r')
        return self.Read()
 
    # --------------------------------------------------------------------------
    # reset, will need initialising again
    # --------------------------------------------------------------------------
    def Reset(self):
        self.Send('c')
        self.sp.write('\r')
        sleep(0.5)
 
    # --------------------------------------------------------------------------
    # Returns 1 if the device is listening, can also be called a few times
    # Command H introduced 23 July 2013
    # --------------------------------------------------------------------------
    def Active(self):
        self.Send('H')
        self.sp.write('\r')
        return self.Wack()
 
    # ------------------------------------------------------------------------------
    # EEPROM utilities
    # ------------------------------------------------------------------------------
    # --------------------------------------------------------------------------
    # reads the eeprom from eeprom address to eprom address
    # --------------------------------------------------------------------------
    def ReadEE(self,bfrom,bto):
        self.Send('R')
        self.sp.write(str(bfrom)+',') # comma delimiter
        self.sp.write(str(bto))
        self.sp.write('\r')
        rv = self.Read()
        return rv.split(',')
 
    # --------------------------------------------------------------------------
    # write a single value to eeprom
    # location is the address of the eeprom that
    # will have the range 0 to 255 - no checking is done.
    # all integers
    # returns 1 on sucesws
    # --------------------------------------------------------------------------
    def WriteEE(self,location,value):
        cmd = "W"+str(location)+","+str(value)+"\r"
        print cmd
        self.Send(cmd)
        return self.Wack()
 
    # --------------------------------------------------------------------------
    # change device address
    # address is an integer
    # --------------------------------------------------------------------------
    def ChangeAddress(self,adr):
        return self.WriteEE(1,adr)
 
    # --------------------------------------------------------------------------
    # change ACK
    # ACK is an integer
    # --------------------------------------------------------------------------
    def ChangeAck(self,ack):
        self.WriteEE(2,ack)
        self.ack = ack
        sleep(0.5)
 
    # --------------------------------------------------------------------------
    # change Baud rate 2400 to 115200 or 0
    # returns 1 on sucess
    # --------------------------------------------------------------------------
    def ChangeBaud(self,baud):
        if baud == 0:
            self.WriteEE(4,0)
        else:
            try:
                br = BAUD_RATES[baud]
                self.WriteEE(4,br)
                self.Wack()
                return 1
            except:
                return 0
 
    # --------------------------------------------------------------------------
    # discover devices on bus
    # --------------------------------------------------------------------------
    def Discover(self):
        devices = []
        self.sp.flushInput()
        for j in range(97,120):
            self.sp.write(chr(j)+"H\r")
            if self.Wack() != 0:
                devices.append(chr(j))
                # get ID
                self.sp.flushInput()
                self.sp.write(chr(j)+"D\r") # device id
                tmp = self.Read()
                devices.append(tmp)
                # get firmware
                self.sp.flushInput()
                self.sp.write(chr(j)+"V\r") # firmware version
                tmp = self.Read()
                devices.append(tmp)
        return devices
Merci d'avoir pris soin de lire et merci de vos réponses.
Patrick