Hi John here
I just bought a new v2 ssc32 and now I’m trying to piece together a program in Java which sends just the string which should turn the servos.
But when i have successfully opened a write stream towards my COM-port and send the string to the SSC nothing happens and i can’t figure out why
Also to note is that Java no longer support serial communications by default in its JDK package so you would have to download Java communications from Sun by your self another note is that i develop this program in a Windows environment but it should when it is done be run in a Linux environment thats why i imported the gnu.io from Rxtx project for serial communications in Java in a Windows environment.
When i run this program i get a blink from my usb-serial converter so I’m pretty sure that it received data, also if i print a command to the SSC it receives it but not until i just start Lynxterm it executes the command. so I think that it has to be something wrong with my carriage return.
I appreciate the help thanks
Greets from Sweden
Here is the code which is an example for Java communications which I’ve modified to work in Windows:
import java.io.*;
import gnu.io.*;
import java.util.*;
public class serial {
public static void main (String]args) {
System.out.println("1");
//
// Platform specific port name, here a Unix name
//
// NOTE: On at least one Unix JavaComm implementation JavaComm
// enumerates the ports as "COM1" ... "COMx", too, and not
// by their Unix device names "/dev/tty...".
// Yet another good reason to not hard-code the wanted
// port, but instead make it user configurable.
//
String wantedPortName = "COM9";
//
// Get an enumeration of all ports known to JavaComm
//
Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
System.out.println("2");
//
// Check each port identifier if
// (a) it indicates a serial (not a parallel) port, and
// (b) matches the desired name.
//
CommPortIdentifier portId = null; // will be set if port found
System.out.println("3");
while (portIdentifiers.hasMoreElements())
{
CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();
if(pid.getPortType() == CommPortIdentifier.PORT_SERIAL &&
pid.getName().equals(wantedPortName))
{
portId = pid;
break;
}
}
if(portId == null)
{
System.err.println("Could not find serial port " + wantedPortName);
System.exit(1);
}
//
// Use port identifier for acquiring the port
//
SerialPort port = null;
try {
port = (SerialPort) portId.open(
"robot", // Name of the application asking for the port
10000 // Wait max. 10 sec. to acquire port
);
} catch(PortInUseException e) {
System.err.println("Port already in use: " + e);
System.exit(1);
}
//
// Set all the params.
// This may need to go in a try/catch block which throws UnsupportedCommOperationException
//
try {
port.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
}
catch (UnsupportedCommOperationException e){
System.err.println("failed to initiate port");
}
//
// Open the input Reader and output stream. The choice of a
// Reader and Stream are arbitrary and need to be adapted to
// the actual application. Typically one would use Streams in
// both directions, since they allow for binary data transfer,
// not only character data transfer.
//
BufferedReader is = null;
PrintStream os = null;
try {
is = new BufferedReader(new InputStreamReader(port.getInputStream()));
} catch (IOException e) {
System.err.println("Can't open output stream");
is = null;
}
//
// New Linux systems rely on Unicode, so it might be necessary to
// specify the encoding scheme to be used. Typically this should
// be US-ASCII (7 bit communication), or ISO Latin 1 (8 bit
// communication), as there is likely no modem out there accepting
// Unicode for its commands. An example to specify the encoding
// would look like:
//
// os = new PrintStream(port.getOutputStream(), true, "ISO-8859-1");
//
try{
os = new PrintStream(port.getOutputStream(), true);
}
catch (IOException e) {
System.err.println("can not open write-stream");
}
//
// Actual data communication would happen here
// performReadWriteCode();
//
os.print("#00 P500 S1000 <cr>");
System.out.println("#00 P500 S1000 <cr>");
//
// It is very important to close input and output streams as well
// as the port. Otherwise Java, driver and OS resources are not released.
//
try{
is.close();
os.close();
port.close();
}
catch (IOException e) {
System.err.println("meatspin!");
}
}
}
[/code]