Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - sun919

Pages: [1]
1
Technical support / java with plc
« on: March 12, 2002, 07:38:51 PM »
hi there,
  is there a way in which allow the communication between java (from pc) and plc . I needed plc to be able to communicate (sending/recieving) with java comm . at the moment it is not possible for me to communicate.. below are my source code for java
public class ReadPorts implements SerialPortEventListener
{
      private SerialPort  serialp = null;
      private static CommPortIdentifier comportiden ;
      private InputStream inp ;
      private CommPort comp ;
      private Enumeration enum ;
      private InputStream  input = null;
  private OutputStream output;
      private int invalue, portnum, inputport ;
  private DisplayPict2 display ;
  private GetScan scan ;
      
      
      
//    SerialPort serialPort = null;
      
      
      public ReadPorts()
      {
                  try
                  {
                        String portName = "COM2" ;
                        
                        comportiden =CommPortIdentifier.getPortIdentifier(portName);       
                  //      System.out.println( comportiden.getCurrentOwner()) ;
                        serialp = (SerialPort)comportiden.open("Download", 1000);             
                        serialp.setSerialPortParams(9600, SerialPort.DATABITS_8,
        SerialPort.STOPBITS_1,SerialPort.PARITY_NONE );
        
        serialp.addEventListener(this) ;
        
        //scan = new GetScan();
        //before need to have getscan class ready
       // display = new DisplayPict2("save.jpg") ;
        portnum = display.getPortNumber() ;
        
        System.out.println("Port number" + portnum);
        System.out.println(serialp.getBaudRate());
        System.out.println(serialp.isDSR());

        
        
        
                  }
                  catch (Exception e)
                  {
                        System.out.println("ERROR");
                  }
//                  testRead();
                  
      }
                  
                  public void testRead()
                  {
                        try
                        {
                              input = serialp.getInputStream();
                              invalue = input.read() ;
                              
                              checkDecision() ;
                        }
                        
                        catch(Exception e)
                        {
                              System.out.println("ERROR WITH INPUT");
                        }
                        
                        
                  }
                  
                  public void checkDecision()
                  {
                        if (invalue ==0 )
                        {
                              //break ;
                        }
                        else if (invalue ==1)
                        {
                              display = new DisplayPict2("picture name");
                          portnum =      display.getPortNumber();
                          sendData(portnum) ;
                        }
                              
                  
                  }
                  
                  public void sendData(int i)
                  {
                    try
                    {
                              output.write(i) ;
                    }
                    catch( IOException e)
                    {
                          System.out.println("Error writing");
                    }
                        
                        
                        
                  }
                  
                  public void closePorts()
                  {
                        try
                        {
                              input.close();
                      output.close();                                                                                    
                        }
                        catch( IOException e)
                        {
                              System.out.println(" Error closing port");
                        }
          }                                    


                  public void serialEvent(SerialPortEvent event)
                  {
         if(event.getEventType()==SerialPortEvent.DATA_AVAILABLE);//DSR)//DATA_AVAILABLE)      
         {
               try
               {System.out.println("In the serial");

                inputport = input.read();
                System.out.println("In the serial");
               }
                     catch(IOException e)
                     {
                           System.out.println("error with input data");
                     }
         }
                  }
          
          
          
      
      
      public static void main(String args[])
      {
                  ReadPorts e = new ReadPorts();
      }
}

2
Technical support / sending series of String or ascii from pc to plc
« on: April 02, 2002, 09:07:14 PM »
hi there,
I'm currently using mitsubishi fx1s-20dr plc. The problem that i m facing is sending a series of string or ascii to control the gate output to plc. I'm doing a mango project which consist of weighting and detect the size of mango. Then the computer will calculate the output channel for mango (varies from 1 to 8 since there are eight types of mango is using). I've manage to send the series of data to plc (ie. 4,3,2 & just a series of string) but the problem is that i do not how to write this in ladder format.For example if data 4 is sent then ladder format will have a function where it is waiting for the data input 4 then it calculate the delay time and the open the gate after the delay time.. Also if the data sent is 4,3,2 then the mango should be sent at output 4,3,2 at the same time(since 4 is coming first but time delay is different for each one).
many thanks
sun  :)

Pages: [1]