View difference between Paste ID: wiP8Jdak and 9ENabEqF
SHOW: | | - or go back to the newest paste.
1
package testPack;
2
3
import gnu.io.CommPort;
4
import gnu.io.CommPortIdentifier;
5
import gnu.io.SerialPort;
6
7
8
9
public class CommExp 
10
{
11
	
12
13
	SerialPort serialPort;
14
	
15
	
16
	 public CommExp()
17
	    {
18
	        super();
19
	    }
20
	    
21
	 
22
	 void changeDTR(boolean b)
23
	 {
24
		 
25
		 serialPort.setDTR(b);
26
		 
27
		 
28
	 }
29
	 
30
	 // START OF METHOD connect(String)
31
	    void connect ( String portName ) throws Exception
32
	    {
33
	        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
34
	        if ( portIdentifier.isCurrentlyOwned() )
35
	        {
36
	            System.out.println("Error: Port is currently in use");
37
	        }
38
	        else
39
	        {
40
	            CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
41
	            
42
	            if ( commPort instanceof SerialPort )
43
	            {
44
	                serialPort = (SerialPort) commPort;
45
	                serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
46
	                
47
	    
48
	            }
49
	            else
50
	            {
51
	                System.out.println("Error: Only serial ports are handled by this example.");
52
	            }
53
	        }     
54
	    }
55
	    
56
	    // END OF METHOD connect(String)
57
	    
58
	    
59
	        
60
	        	    
61
62
		private boolean getDTRStatus() 
63
		{
64
			
65
			
66
			return serialPort.isDTR();
67
		}
68
69-
		public void blinkDtr()
69+
		
70
71-
			changeDTR(true);
71+
72-
			try {
72+
73-
				//Thread.sleep(1);
73+
74-
				Thread.sleep(1);
74+
75-
			} catch (InterruptedException e) {
75+
76-
				// TODO Auto-generated catch block
76+
77-
				e.printStackTrace();
77+
78-
			}
78+
79
}