Help required for Lynx 6

Hi everyone,

I am in dire need of some help with my honours project. I am trying to connect my Lynx 6 arm to the serial port on a Taylec TutorIO board. The aim of the project is to write an application to control the robotic arm. This application will then be FTP’d onto the board and will be run from there.

I am having a few problems and I am not sure if I am writing the correct sequence to the arm or if it ia problem with the serial port on the board.

This is the code I have so far in java and it seems that I am able to open and initialise the port but when I am passing the strings to the port the arm does not move. Could anyone tell me if I am passing the correct strings and if there is anything glaringly wrong with my code.

Thanks.

import javax.comm.;
import java.util.
;
import java.io.*;

public class Serial {

static SerialPort fCurrentPort__; 
CommPortIdentifier mPortId = null;
static SerialPort mPort = null;
int move = 0;
int i = 0;
byte servo = 0;
int t = 0;
int i_T1 = 127;
int i_T2 = 130;
int i_T3 = 122;
int i_T4 = 130;
int i_T5 = 138;
int i_T6 = 130;

int POS1 = 0;
int POS2 = 0;
int POS3 = 0;
int POS4 = 0;
int POS5 = 0;
int POS6 = 0;

int speed1 = 15;

int BAUD_RATE = 9600;


  // The input and output streams over the port
  DataInputStream fPortInStream;
  PrintStream     fPortOutStream;
  
  public Serial(){
		//Constructor
	}
  
  /**
   * Open the Port
   * @param serial1
   * @return none
   * @exception NoSuchPortException when a port request is not present in the system
   * @exception PortInUseException when the port requested has been opened by another application
   * 
   */
  public void openPort(String portName)throws NoSuchPortException, PortInUseException {
		System.out.println("Opening port..." + portName);
		mPortId = CommPortIdentifier.getPortIdentifier(portName);
		mPort = (SerialPort) mPortId.open(portName, 30000);
		}

	public void closePort(){
		System.out.println("Closing port...");
		mPort.close();
	}
	

	public void initPort(int baud) throws UnsupportedCommOperationException{
		System.out.println("Initializing port...");
		mPort.setSerialPortParams(baud, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, 			SerialPort.PARITY_NONE);
		mPort.setFlowControlMode(javax.comm.SerialPort.FLOWCONTROL_NONE);
	}
	OutputStream getOutputStream() throws IOException{
		return mPort.getOutputStream();
	}
	InputStream getInputStream() throws IOException{
		return mPort.getInputStream();
	}
  
  public static void main (String ] args) {
	  Serial serial = new Serial();
  

	  Enumeration port_list = CommPortIdentifier.getPortIdentifiers ();

	    while (port_list.hasMoreElements ()) {
	      // Get the list of ports
	      CommPortIdentifier port_id = 
	        (CommPortIdentifier) port_list.nextElement ();

	      // Find each ports type and name
	      if (port_id.getPortType () == CommPortIdentifier.PORT_SERIAL) {
	          System.out.println ("Serial port: " + port_id.getName ()+"\t"+ 			port_id.getCurrentOwner());

	      } else if (port_id.getPortType () == 
	                 CommPortIdentifier.PORT_PARALLEL) {
	          System.out.println ("Parallel port: " + port_id.getName ());

	      } else
	          System.out.println ("Other port: " + port_id.getName ());

	      // Attempt to open it


	      try{
	    	  //serial.closePort();
	    	  serial.openPort("serial1");
	    	  //serial.closePort();
	    	  //System.out.println("Closing port");
	    	  //mPort.close();
	      }
	      catch(NoSuchPortException e){
				System.out.println("No such port"+ args[0]);
				//serial.usage();
				System.exit(1);
				
			} catch (PortInUseException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
				//serial.closePort();
				System.out.println(e.getMessage());
		}

			//System.out.println("Baud.."+ mPort.getBaudRate());
			//System.out.println("Databits.."+ mPort.getDataBits());
			//System.out.println("Name.."+ mPort.getName());
			
	      int baudRate =9600;
	      
			try{

				serial.initPort(baudRate);
				System.out.println("You got this far");
				System.out.println("Port initialized");
				System.out.println("Baud.."+ mPort.getBaudRate());
				System.out.println("Databits.."+ mPort.getDataBits());
				System.out.println("Name.."+ mPort.getName());
				
			}
			catch(UnsupportedCommOperationException e){
				System.out.println(e.getMessage());
				System.out.println("It is the init that has caused this");
				//serial.usage();
				System.exit(1);
			}
			OutputStream os = null;
			InputStream is = null;
			try{
				os = serial.getOutputStream();
			}catch (IOException e){
				serial.closePort();
				System.out.println(e.getMessage());
			}
				
				byte servo = 0;
			try{
				int i = 0;
				int i_P1 = serial.i_T1;
				
				//servo = 0;
				for(i = 0; i<254;i++){
					os.write((byte)255);
					os.write((byte)servo);
					os.write((byte)i);
					//serial.POS1 = i_P1;
				}
				for(i = 254;i>=0;i--){
					os.write((byte)255);
					os.write((byte)servo);
					os.write((byte)i);
				}
			
				
	
				//System.out.println(is);
				//System.out.println(os);
				//System.out.println(servo);
			}
			catch (IOException e){
				//serial.closePort();
				//System.out.println("It is this one");
				System.out.println("Closing port");
		    	serial.closePort();
				System.out.println(e.getMessage());
								
			}

			int move =20;
			
			try{
				while(serial.move>0){
					int i = 0;
					byte servo = 0;
					int i_P2 = serial.i_T2;
					int i_P3 = serial.i_T3;
					int i_P4 = serial.i_T4;
					int i_P5 = serial.i_T5;
					int i_P6 = serial.i_T6;
					
					byte servo = 0;
					
					if(serial.move ==20){
						servo = 0;
						os.write((byte)255);
						os.write((byte)servo);
						os.write((byte)i_P1);
						serial.POS1 = i_P1;
						
						servo = 1;
						os.write((byte)255);
						os.write((byte)servo);
						os.write((byte)i_P2);
						serial.POS2 = i_P2;
						
						servo = 2;
						os.write((byte)255);
						os.write((byte)servo);
						os.write((byte)i_P3);
						serial.POS3 = i_P3;
						
						servo = 3;
						os.write((byte)255);
						os.write((byte)servo);
						os.write((byte)i_P4);
						serial.POS4 = i_P4;
						
						servo = 4;
						os.write((byte)255);
						os.write((byte)servo);
						os.write((byte)i_P5);
						serial.POS5 = i_P5;
						
						servo = 5;
						os.write((byte)255);
						os.write((byte)servo);
						os.write((byte)i_P6);
						serial.POS6 = i_P6;			
						
					}move = 1;
					serial.t = 1;
					if(serial.move==1){
						servo = 0;
						if(serial.POS1>0){
							for(i = serial.POS1;i<254;i++){
								if(serial.t==1){
									System.out.println(i);
									serial.POS1 = i;
									System.out.println(serial.POS1);
									break;
								}else{
									os.write((byte)255);
									os.write((byte)servo);
									os.write((byte)i);
									Thread.sleep(serial.speed1);
								}
							}
						}
					}else{
						for(i = i_P1;i<254;i++){
							if(serial.t==1){
								System.out.println(i);
								serial.POS1 = i;
								System.out.println(serial.POS1);
								break;
							}else{
								os.write((byte)255);
								os.write((byte)servo);
								os.write((byte)i);
								Thread.sleep(serial.speed1);
							}
						}
					}
					
				}
			}
			catch(IOException ioe){
				System.out.println(ioe);
			}
			catch(Exception e){
				System.out.println(e);
			}
	    }
	  } //main
	} // PortListOpen