Contrôle De La Partie Module - Yoctopuce Yocto-RS485-V2 Mode D'emploi

Table des Matières

Publicité

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,
sys
from
yocto_api
import
from
yocto_serialport
# Setup the API to use local USB devices. You can
# use an IP address instead of 'usb' if the device
# is connected to a network.
errmsg
= YRefParam()
if YAPI.RegisterHub("usb", errmsg) !=
sys.exit("init error"
if len(sys.argv) >
serialPort
= YSerialPort.FindSerialPort(sys.argv[1])
else:
serialPort
= YSerialPort.FirstSerialPort()
if
serialPort
sys.exit('No module connected (check
print("Please enter the MODBUS slave address
slave
=
0
while
(slave
< 1) or
slave
=
int(input("slave:
reg
=
0
while
(reg
< 1) or
print("Please select a Coil No (>=1), Input Bit No
print("Input Register No (>=30001) or Register No
reg
=
int(input("No:
while
serialPort.isOnline():
if
reg
>=
40001:
val
= serialPort.modbusReadRegisters(slave,
elif
reg
>=
30001:
val
= serialPort.modbusReadInputRegisters(slave,
elif
reg
>=
10001:
val
= serialPort.modbusReadInputBits(slave,
else:
val
= serialPort.modbusReadBits(slave,
print("Current value: "
print("Press ENTER to read again, Q to
if
(reg %
30000) <
print(" or enter a new
cmd
=
input(":
if
(cmd
== "q") or
sys.exit()
if
cmd
!=
""
and
val
= int(cmd)
if
reg
>=
serialPort.modbusWriteRegister(slave,
else:
serialPort.modbusWriteBit(slave,
YAPI.FreeAPI()
9.4. Contrôle de la partie module
Chaque module peut-être contrôlé d'une manière similaire, vous trouverez ci-dessous un simple
programme d'exemple affichant les principaux paramètres d'un module et permettant d'activer la
balise de localisation.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,
sys
from
yocto_api
import
def
usage():
www.yoctopuce.com
*
import
*
YAPI.SUCCESS:
+
errmsg.value)
1:
is
None:
(slave
>
255):
"))
# use raw_input in python 2.x
(reg
>= 50000) or
(reg %
"))
# use raw_input in python 2.x
+
str(val))
10000:
value")
")
# use raw_input in python 2.x
(cmd
==
"Q"):
((reg %
30000) <
10000):
30001:
*
9. Utilisation du Yocto-RS485-V2 en Python
cable)')
(1...255)")
10000) ==
0:
(>=10001+),")
(>=40001)")
reg -
40001, 1)[0]
reg -
30001, 1)[0]
reg -
10001, 1)[0]
reg -
1, 1)[0]
quit")
reg -
30001, val)
reg -
1, val)
55

Publicité

Table des Matières
loading

Ce manuel est également adapté pour:

Yocto-rs232

Table des Matières