Hi,
I could write to an /dev/pty, but i could not read datas on same tty,
receive message Bad File Descriptor ?
Anyone has na idea ?
Regards
Philippe
im****t java.io.*;
public class Class15
{
String ****tName=null;
FileOutputStream fos2 = null;
FileInputStream fis2 = null;
public byte[] toBytes(char[] from) {
byte[] result = new byte[from.length];
for (int i = 0; i < from.length; i++) {
result[i] = (byte)from[i];
}
return result;
}
public Class15(String m****tName) throws Exception
{
****tName=m****tName;
System.out.println("cl01 ****tName "+****tName);
fos2 = new FileOutputStream(****tName);
System.out.println("cl02 ****tName "+****tName);
// fis2 = new FileInputStream(****tName); // Ne
fonctionne pas
FileDescriptor fd = fos2.getFD();
fis2 = new FileInputStream(fd);
//fis2 = new FileInputStream(fd.in);
System.out.println("cl03 ****tName "+****tName);
System.out.println("cl04 ****tName fis2
"+fis2.available());
}
public void go(String xx)
{
try{
fos2.write(toBytes(xx.toCharArray()));
fos2.write('\n');
fos2.flush();
// fos2.close();
} catch(Exception e)
{
System.out.println("Erreur1 "+e.getMessage());
}
}
public String read(){
String rt=null;
try{
System.out.println("r01 *"+****tName+"*");
System.out.println("r03 available
*"+fis2.available());
System.out.println("r04 valid
*"+fis2.getFD().valid());
while (true) {
System.out.println("r05 *"+****tName+"*");
byte b[] = new byte[100];
// Read some data from the modem.
int nbytes = fis2.read(b);
System.out.println("r06 *"+nbytes+"*");
System.out.println (new String (b, 0, nbytes));
}
}
catch(Exception e1){
System.out.println(e1.getMessage());
}
return rt;
}
public void close() {
try{
fos2.close();
fis2.close();
}catch(Exception e1){}
}
/**
*
* @[EMAIL PROTECTED]
args
*/
public static void main(String[] args)
{
String ****tName=new String("/dev/ptyqf");
String xx=new String("COUCOU DE JAVA"); // Demande de l'Heure
if(args.length>0)
****tName = args[0]; // ex /dev/ttyq0
try{
Class15 x=new Class15(****tName);
System.out.println("****T OUVERT, lancer le BASIC avant de
Valider!");
System.out.println("APPUYER SUR ENTREE pour l'envoi");
System.out.println("fis2 "+x.fis2.available());
//Lecture du clavier
BufferedReader entree=new BufferedReader(new
InputStreamReader(System.in));
while(entree.readLine()!=null &&
!entree.readLine().equalsIgnoreCase("f"))
{
System.out.println("GO");
System.out.println("fis2B "+x.fis2.available());
x.go(xx);
System.out.println("fis2c "+x.fis2.available());
//Test de lecture depuis le BASIC sur le pty
String lu=x.read();
System.out.println("LU depuis le BASIC "+lu);
}
System.out.println("FERMETURE DU FLUX!");
x.close();
}
catch(Exception e1){System.out.println(e1.getMessage());}
}
}