Lancez Microsoft Visualbasic Et Ouvrez Le Projet Exemple Correspondant, Fourni Dans Le Répertoire - Yoctopuce Yocto-RS485-V2 Mode D'emploi

Table des Matières

Publicité

serialport
= YSerialPort.FindSerialPort("MaFonction")
YSerialPort.FindSerialPort
contrôler le port série.
isOnline
La méthode
isOnline()
savoir si le module correspondant est présent et en état de marche.
modbusWrite* et modbusRead*
Les
méthodes
YFindSerialPort
Un exemple réel
Lancez Microsoft VisualBasic et ouvrez le projet exemple correspondant, fourni dans le répertoire
Examples/Doc-GettingStarted-Yocto-RS485-V2 de la librairie Yoctopuce.
Vous reconnaîtrez dans cet exemple l'utilisation des fonctions expliquées ci-dessus, cette fois
utilisées avec le décorum nécessaire à en faire un petit programme d'exemple concret.
Imports
System.IO
Imports
System.Environment
Module
Module1
Sub Main()
Dim argv() As
Dim
serialPort
Dim
errmsg
=
""
Dim
cmd
As
String
Dim
slave, reg, val
REM
Setup the API
REM
use an IP address instead
REM is
connected
If
(YAPI.RegisterHub("usb",
Console.WriteLine("yInitAPI failed: "
End
End If
If
(argv.Length
serialPort
= YSerialPort.FindSerialPort(argv(1))
Else
serialPort
= YSerialPort.FirstSerialPort()
If
serialPort
Console.WriteLine("No module connected (check USB
End
End If
End If
Console.WriteLine("Please enter the MODBUS slave address
Console.WriteLine("Slave:
slave
= Convert.ToInt32(Console.ReadLine())
Console.WriteLine("Please select a Coil No (>=1), Input Bit No
Console.WriteLine("
Console.WriteLine("No:
reg
= Convert.ToInt32(Console.ReadLine())
While (serialPort.isOnline())
If
reg
>=
40001
val
=
serialPort.modbusReadRegisters(slave, reg
ElseIf
(reg
val
=
serialPort.modbusReadInputRegisters(slave, reg
ElseIf
(reg
val
=
serialPort.modbusReadInputBits(slave, reg
Else
val
=
serialPort.modbusReadBits(slave, reg
End If
Console.WriteLine("Current value: "
www.yoctopuce.com
renvoie un objet que vous pouvez ensuite utiliser à loisir pour
de l'objet renvoyé par
modbusWrite*()
permettent de communiquer en MODDUS sur la liaison RS485.
String
= System.Environment.GetCommandLineArgs()
As
YSerialPort
As
Integer
to
use local USB
of
'usb' if the device
to
a
network.
errmsg) <> YAPI.SUCCESS) Then
>
1
And argv(1) <> "any") Then
Is Nothing Then
")
Input Register No (>=30001) or Register No
")
Then
>= 30001) Then
>= 10001) Then
18. Utilisation du Yocto-RS485-V2 en VisualBasic .NET
YSerialPort.FindSerialPort
et
modbusRead*()
devices.
You
can
+ errmsg)
cable)")
-
40001,
-
10001,
-
1,
1)(0)
+ Convert.ToString(val))
de
l'objet
renvoyé
(1...255)")
(>=10001+),")
(>=40001)")
1)(0)
-
30001,
1)(0)
1)(0)
permet de
par
145

Publicité

Table des Matières
loading

Ce manuel est également adapté pour:

Yocto-rs232

Table des Matières