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

Table des Matières

Publicité

import java.io.InputStreamReader;
public class
Demo
public static
{
try {
// setup the API to use local VirtualHub
YAPI.RegisterHub("127.0.0.1");
} catch
(YAPI_Exception
System.out.println("Cannot contact VirtualHub on 127.0.0.1 ("
ex.getLocalizedMessage() + ")");
System.out.println("Ensure that the VirtualHub application is
System.exit(1);
}
YSerialPort
if
(args.length
String
serialPort
} else {
serialPort
if
(serialPort
System.out.println("No module connected (check USB
System.exit(1);
}
}
System.out.println("****************************");
System.out.println("* make sure voltage levels
System.out.println("* are properly configured
System.out.println("****************************");
InputStreamReader
BufferedReader
try {
serialPort.set_serialMode("9600,8N1");
serialPort.set_protocol("Line");
serialPort.reset();
String
do {
YAPI.Sleep(500);
do {
} while (!line.equals(""));
System.out.println("Type line to send, or Ctrl-C to
line
serialPort.writeLine(line);
} while (!line.equals(""));
} catch
(Exception
ex.printStackTrace();
}
YAPI.FreeAPI();
}
}
18.3. 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.
import com.yoctopuce.YoctoAPI.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class
Demo
public static
www.yoctopuce.com
{
void
main(String[] args)
ex) {
serialPort;
> 0) {
target
= args[0];
=
YSerialPort.FindSerialPort(target
= YSerialPort.FirstSerialPort();
== null) {
inputStreamReader
console
= new BufferedReader(inputStreamReader);
line;
line
= serialPort.readLine();
if (!line.equals("")) {
System.out.println("Received: "
}
= console.readLine();
ex) {
{
void
main(String[] args)
+ ".serialPort");
*");
*");
= new InputStreamReader(System.in);
+ line);
18. Utilisation du Yocto-Serial en Java
+
running");
cable)");
exit:");
129

Publicité

Table des Matières
loading

Table des Matières