Bonjour,

Je voudrais écrire un caractère sur le port série, plus précisément un nombre 1 ou 2 etc.

J'utilise ce bout de code :

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
 
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
 
 
public class SerialWrite {
 
	/**
         * @param args
         */
	public static void main(String[] args) {
		Runtime rt = Runtime.getRuntime();
		  Process p = null;
		  String portname = "com5:";
		  // for Win95 : c:\\windows\\command.com
		  //             c:\\windows\\command\\mode.com   
		  String cmd[] = {
		   "c:\\WINDOWS\\system32\\cmd.exe", "/c",
		   "start", "/min",
		   "c:\\WINDOWS\\system32\\mode.com", portname,
		   "baud=115200", "parity=n", "data=8",
		   "stop=1", 
		   };
		  try {
		   p = rt.exec( cmd );
		   if( p.waitFor() != 0 ) {
		    System.out.println("Error executing command: " + cmd );
		    System.exit( -1 );
		    }
		   //System.out.println("Hello".getBytes());
		   byte data[] = "1".getBytes();
		   //System.out.println("0x01".getBytes());	
		   FileOutputStream fos = new FileOutputStream( portname );
		   BufferedOutputStream bos = new BufferedOutputStream( fos );
		   fos.write( data, 0, data.length );
		   fos.close();
		   }
		  catch( Exception e ) {
		   e.printStackTrace();
		   }
 
	}
 
}
mais je n'obtient pas le résultat souhaité.
lorsque j'affiche "1".getBytes(); j'ai plusieurs caractère :

[B@3e25a5