Go Down

Topic: Cofiguration of serial port (Read 1 time) previous topic - next topic

sabrine

Mar 17, 2012, 08:42 am Last Edit: Mar 17, 2012, 09:20 am by Coding Badly Reason: 1
Hello,
I'am a student , i am begginer in programmaion Arduino.I should configure my serial port with net beans in order to know what can i send and what i recieve.
So I used com0com and rxtx to write a little java program to intercept the bytes between avrdude and my usual com port (COM3) to see what exactly was being sent and received.

My code is:
Code: [Select]
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;


public class ComProxy {
public static final String applicationComPort = "COM7";
public static final String deviceComport = "COM3";
   public static final int baud=19200;


static InputStream input1;
static OutputStream output1;

static InputStream input2;
static OutputStream output2;

static OutputStream out;

public static void main(String[] args) throws Exception {
// out=new FileOutputStream("/comproxy.log");
out=System.out;

CommPortIdentifier portId1 = CommPortIdentifier
.getPortIdentifier(applicationComPort);

CommPortIdentifier portId2 = CommPortIdentifier
.getPortIdentifier(deviceComport);

System.out.println("Serial Proxy Starting");
System.out.println("Serial application port: " + portId1.getName());
System.out.println("Serial proxied to device port: " + portId2.getName());


SerialPort port1 = (SerialPort) portId1.open("serial madness1", 4000);
input1 = port1.getInputStream();
output1 = port1.getOutputStream();
port1.setSerialPortParams(baud,
SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
//this assumes the application starts the serial conversation
  while(input1.available() > 0){ input1.read();};
 System.out.println("waiting for "+applicationComPort+" activity...");
  while(input1.available() ==0);


SerialPort port2 = (SerialPort) portId2.open("serial madness2", 4001);
input2 = port2.getInputStream();
output2 = port2.getOutputStream();
port2.setSerialPortParams(baud,
SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
  while(input2.available() > 0){ input2.read();};



 System.out.println("proxy started");

while (true) {
 int c;
 if(input1.available() > 0){
 c=input1.read();
 out.write(("I"+hexval(c)+"\n").getBytes());
 output2.write(c);
 }
 if(input2.available() > 0){
 c=input2.read();
 out.write(("O"+hexval(c)+"\n").getBytes());
 output1.write(c);
 }
}
}
public static void waitfor(int w) throws Exception{
int c;
do{
while(input2.available() == 0);
c=input2.read();
System.out.println((char)c + " " + (int) c);
}while(c != w);
}


static String hexvals[] = {
"0", "1","2","3","4","5","6","7","8","9", "A", "B", "C", "D", "E","F"};

static String hexval(int i){
return hexvals[i/16] + hexvals[i%16];
}
}


But in compilation i have this error message :
*
Java lib Version   = RXTX-2.1-7
WARNING:  RXTX Version mismatch
   Jar version = RXTX-2.1-7
   native lib Version = RXTX-2.1-7pre16
Exception in thread "main" gnu.io.NoSuchPortException
   at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:218)
   at test.Test.main(Test.java:28)
Java Result: 1
BUILD SUCCESSFUL (total time: 15 seconds)

I don't know really what's the error.

Can you help me please.
Thank you for advance!


Moderator edit: changed to [code] [/code] tags.

robtillaart


To see the bytes actually send it is easier to press the SHIFT key while uploading.
most/all of the communication will appear in the debugging window.

(to see this allways you can set    build.verbose=true   and    upload.verbose=true    in the preferences.txt file before starting the IDE.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

sabrine

hi,
First thank you very much for your reply
Where can i found the file preferences.txt please???
thanks for advance!!!


robtillaart


Start the Arduino IDE
File menu ==> Preferences     somewhere bottom of the window is a link to the file.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up