 import java.io.*;
import java.util.*;
import gnu.io.CommPortIdentifier; 
import gnu.io.SerialPort;
import gnu.io.SerialPortEvent; 
import gnu.io.SerialPortEventListener; 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.*;
public class Monitor8 implements Runnable
{   String s2="[\\x00-\\x20]*[+-]?(((((\\p{Digit}+)(\\.)?((\\p{Digit}+)?)([eE][+-]?(\\p{Digit}+))?)|(\\.((\\p{Digit}+))([eE][+-]?(\\p{Digit}+))?)|(((0[xX](\\p{XDigit}+)(\\.)?)|(0[xX](\\p{XDigit}+)?(\\.)(\\p{XDigit}+)))[pP][+-]?(\\p{Digit}+)))[fFdD]?))[\\x00-\\x20]*";              
	private static final long serialVersionUID = 8257386587L; 
	public Thread readThread;             // zaman içinde çal??ma de?i?keni
    public  CommPortIdentifier portId;    // seri ba?lant? kanal? numaras?
    public  SerialPort serialPort;        // seri kanal
    public  OutputStream outputStream;    // ç?kt? kanal?
    public  InputStream inputStream;      // girdi kanal?
    public  int sleep1;                   // readThread bekleme zaman? milisaniye
    public buttonP d1;
    public Monitor8(String s)
    { portId=portId(s);
    System.out.println("portID is read");
      try { serialPort = (SerialPort)
            portId.open(s, 2000);
                    } catch (gnu.io.PortInUseException e) {}
                    try {
                        outputStream = serialPort.getOutputStream();
                    } catch (IOException e) {}
                    try {
                        serialPort.setSerialPortParams(9600,
                            SerialPort.DATABITS_8,
                            SerialPort.STOPBITS_1,
                            SerialPort.PARITY_NONE);
                    } catch (gnu.io.UnsupportedCommOperationException e) {}
                    button();                   }

    //seri iletişim kanalı açılmas?
    public  CommPortIdentifier portId(String s)
    {    portId = PortChooser.select_port(null);            
                    try {
                        serialPort = (SerialPort)
                            portId.open(s, 2000);
                    } catch (gnu.io.PortInUseException e) {}
    return portId;
    } 
    public  void start() 
    {readThread = new Thread(this);
    readThread.start();
    }
    public void run() 
     {  
      int k=0;
	  while(true)
	  {	  
      try{
	  k++;	 	 
      Thread.sleep(200); 
      try { 
	                if(d1.signal==1)
	                    {outputStream.write(d1.signal); d1.setBackground(Color.yellow);d1.jtf.setText("ışık  yanıyor");} 
	                else
	                   {outputStream.write(d1.signal);d1.setBackground(Color.blue);d1.jtf.setText("ışık  söndü");  }
      } catch (IOException e) {}
      } catch (InterruptedException e) {System.out.println("InterruptedException 1");}
      }
      }
public void button()
{d1=new buttonP();
 FrameGraphic.plot("ARDUINO relay sensor",d1);
}
      public static void main(String arg[])
      { Monitor8 m=new Monitor8("ARDUNIO");
       m.start();
       }
}
