Jump to content

Skeggy88

Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by Skeggy88

  1. I modified the VI and also the code.

    http://bayimg.com/EAgiGAAeI

    In labview I can choose between little endian and big endian and I either tried, but I obtained values like 1.1319598827449316E-72 instead of, for example, 0,0145643.

    However thanks because is really fast :)

    
    import java.io.*;
    
    import java.net.*;
    
    import java.nio.ByteBuffer;
    
    import java.nio.ByteOrder;
    
    public class ServerThread extends Thread {
    
     
    
       public ServerThread() {  
    
       }
    
      
    
    	@Override
    
       public void run(){
    
      	ServerSocket welcomeSocket;
    
      	InputStream myInputStream;
    
      	byte[] array = new byte[8];
    
      	int i=0;
    
      	try {
    
          	welcomeSocket = new ServerSocket(2056);
    
          	Socket connectionSocket = welcomeSocket.accept();
    
          	System.out.println(connectionSocket);
    
          	myInputStream=connectionSocket.getInputStream();
    
          	Double num;
    
          	int b;
    
          	while ((b = myInputStream.read()) != -1) {
    
              	array[i]= (byte) b;
    
              	if(i==7){
    
                  	num = toDouble(array);
    
                  	System.out.println(num);
    
                  	i=0;
    
              	}
    
                  	else {
    
                  	i++;
    
              	}
    
          	}
    
      	} catch (IOException ex) {
    
      	}
    
       }
    
    public static double toDouble(byte[] bytes) {
    
    	return ByteBuffer.wrap(bytes).getDouble();
    
    }
    
    }
    
    [/CODE]

    I know that there are italian forums, but I prefer american forums because members are more active. And I also know that my english is terrible :P I hope you understand me!

  2. Thanks for replays.

    This is my VI:

    2iq4hf.png

    And this is the related java code... I know that I shoudn't use int to read from the socket, but if I use a BufferedReader the program doesn't work (no output).

    
    import java.io.*;
    
    import java.net.*;
    
    import java.nio.ByteBuffer;
    
    import java.nio.ByteOrder;
    
    
    
    public class ServerThread extends Thread {
    
     
    
       public ServerThread() {   
    
       }
    
     
    
    	@Override
    
       public void run(){
    
      	ServerSocket welcomeSocket;
    
      	InputStream myInputStream;
    
      	try {
    
          	welcomeSocket = new ServerSocket(2056);
    
          	Socket connectionSocket = welcomeSocket.accept();
    
          	System.out.println(connectionSocket);
    
          	myInputStream=connectionSocket.getInputStream();
    
          	int b;
    
          	while ((b = myInputStream.read()) != -1) {
    
              	System.out.println(b);
    
          	}
    
      	} catch (IOException ex) {
    
      	}
    
       }
    
    [/CODE]

  3. Hi,

    I'm building an application that allow to control a DAQ.

    This DAQ acquires data and turn on and off a light.

    Labview and Java communicates, but I read wrong data.

    The DAQ acquires double samples that are converted in String format and sent via tcp. Numbers are like 0,00006 ; 1, 50000043 etc...

    In Java i receive data like 54; 42 etc...

    What's wrong? I also tried the big-endian/little-endian conversione without results.

    Can someone help me? In labview I can write only Strings, but if I try to use a buffered reader with the instrucion br.readLine() the program doesn't work.

    Thanks and sorry for my english,

    Veronica

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.