View Javadoc
1   package net.sf.atmodem4j.spsw;
2   
3   /*
4    * #%L
5    * SPSW Java
6    * %%
7    * Copyright (C) 2009 - 2014 atmodem4j
8    * %%
9    * atmodem4j - A serial port socket wrapper- http://atmodem4j.sourceforge.net/
10   * Copyright (C) 2009-2014, atmodem4j.sf.net, and individual contributors as indicated
11   * by the @authors tag. See the copyright.txt in the distribution for a
12   * full listing of individual contributors.
13   * 
14   * This is free software; you can redistribute it and/or modify it
15   * under the terms of the GNU General Public License as
16   * published by the Free Software Foundation; either version 3 of
17   * the License, or (at your option) any later version.
18   * 
19   * This software is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22   * Lesser General Public License for more details.
23   * 
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this software; if not, write to the Free
26   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
28   * #L%
29   */
30  
31  import java.io.Closeable;
32  import java.io.IOException;
33  import java.io.InputStream;
34  import java.io.OutputStream;
35  import java.util.Set;
36  
37  /**
38   *
39   * @author scream3r
40   */
41  public interface SerialPortSocket extends Closeable {
42  
43      public class SerialPortSocketFactory {
44  
45          public SerialPortSocket createSerialPortSocket(String portName) {
46              switch (System.getProperty("os.name")) {
47                  case "Linux":
48                      return new GenericTermiosSerialPortSocket(portName);
49                  case "Mac OS":
50                      throw new UnsupportedOperationException("Mac OS is currently not supported yet");
51                  case "Mac OS X":
52                      throw new UnsupportedOperationException("Mac OS X is currently not supported yet");
53                  case "Windows 95":
54                      return new GenericWinSerialPortSocket(portName);
55                  case "Windows 98":
56                      return new GenericWinSerialPortSocket(portName);
57                  case "Windows Me":
58                      return new GenericWinSerialPortSocket(portName);
59                  case "Windows NT":
60                      return new GenericWinSerialPortSocket(portName);
61                  case "Windows 2000":
62                      return new GenericWinSerialPortSocket(portName);
63                  case "Windows XP":
64                      return new GenericWinSerialPortSocket(portName);
65                  case "Windows 2003":
66                      return new GenericWinSerialPortSocket(portName);
67                  case "Windows Vista":
68                      return new GenericWinSerialPortSocket(portName);
69                  case "Windows 2008":
70                      return new GenericWinSerialPortSocket(portName);
71                  case "Windows 7":
72                      return new GenericWinSerialPortSocket(portName);
73                  case "Windows 8":
74                      return new GenericWinSerialPortSocket(portName);
75                  case "Windows 2012":
76                      return new GenericWinSerialPortSocket(portName);
77                  case "Windows CE":
78                      throw new UnsupportedOperationException("Windows CE is currently not supported yet");
79                  case "OS/2":
80                      throw new UnsupportedOperationException("OS/2 is currently not supported yet");
81                  case "MPE/iX":
82                      throw new UnsupportedOperationException("MPE/iX is currently not supported yet");
83                  case "HP-UX":
84                      throw new UnsupportedOperationException("HP-UX is currently not supported yet");
85                  case "AIX":
86                      throw new UnsupportedOperationException("AIX is currently not supported yet");
87                  case "OS/390":
88                      throw new UnsupportedOperationException("OS/390 is currently not supported yet");
89                  case "FreeBSD":
90                      throw new UnsupportedOperationException("FreeBSD is currently not supported yet");
91                  case "Irix":
92                      throw new UnsupportedOperationException("Irix is currently not supported yet");
93                  case "Digital Unix":
94                      throw new UnsupportedOperationException("Digital Unix is currently not supported yet");
95                  case "NetWare 4.11":
96                      throw new UnsupportedOperationException("NetWare 4.11 is currently not supported yet");
97                  case "OSF1":
98                      throw new UnsupportedOperationException("OSF1 is currently not supported yet");
99                  case "OpenVMS":
100                     throw new UnsupportedOperationException("OpenVMS is currently not supported yet");
101                 default:
102                     throw new RuntimeException("Can't figure out OS: " + System.getProperty("os.name"));
103             }
104         }
105     }
106 
107     static SerialPortSocketFactory FACTORY = new SerialPortSocketFactory();
108 
109     boolean isClosed();
110 
111     boolean isCTS();
112 
113     boolean isDSR();
114 
115     boolean isIncommingRI();
116     
117     InputStream getInputStream() throws IOException;
118 
119     OutputStream getOutputStream() throws IOException;
120 
121     /**
122      * Getting port name under operation
123      *
124      * @return Method returns port name under operation as a String
125      */
126     String getPortName();
127 
128     /**
129      * Getting port state
130      *
131      * @return Method returns true if port is open, otherwise false
132      */
133     boolean isOpen();
134 
135     /**
136      * Port opening
137      * <br><br>
138      * <b>Note: </b>If port busy <b>TYPE_PORT_BUSY</b> exception will be thrown.
139      * If port not found <b>TYPE_PORT_NOT_FOUND</b> exception will be thrown.
140      *
141      * @throws SerialPortException
142      */
143     void openAsIs() throws IOException;
144 
145     void openRaw() throws IOException;
146 
147     void openTerminal() throws IOException;
148 
149     void openModem() throws IOException;
150 
151     /**
152      * Setting the parameters of port
153      *
154      * @param baudRate data transfer rate
155      * @param dataBits number of data bits
156      * @param stopBits number of stop bits
157      * @param parity parity
158      * @param flowControls
159      * @throws java.io.IOException
160      *
161      *
162      * @since 0.8
163      */
164     void openRaw(Baudrate baudRate, DataBits dataBits, StopBits stopBits, Parity parity, Set<FlowControl> flowControls) throws IOException;
165 
166     /**
167      * Close port. This method deletes event listener first, then closes the
168      * port
169      *
170      * @throws java.io.IOException
171      */
172     @Override
173     void close() throws IOException;
174 
175     /**
176      * Change RTS line state
177      *
178      * @param value <b>true - ON</b>, <b>false - OFF</b>
179      * @throws java.io.IOException
180      *
181      */
182     void setRTS(boolean value) throws IOException;
183 
184     /**
185      * Change DTR line state
186      *
187      * @param value <b>true - ON</b>, <b>false - OFF</b>
188      * @throws java.io.IOException
189      *
190      */
191     void setDTR(boolean value) throws IOException;
192 
193     
194     void setXONChar(char c) throws IOException;
195 
196     void setXOFFChar(char c) throws IOException;
197     
198     char getXONChar() throws IOException;
199 
200     char getXOFFChar() throws IOException;
201     
202     void sendXON() throws IOException;
203 
204     void sendXOFF() throws IOException;
205   /**
206      * Get bytes count in in buffer of port
207      *
208      * @return Method returns the array that contains info about bytes count in
209      * buffers:
210      * @throws java.io.IOException
211      *
212      */
213     int getInBufferBytesCount() throws IOException;
214 
215     /**
216      * Get bytes count out inbuffer of port
217      *
218      * @return Method returns the array that contains info about bytes count in
219      * buffers:
220      * @throws java.io.IOException
221      *
222      */
223     int getOutBufferBytesCount() throws IOException;
224 
225     /**
226      * Set Break singnal
227      *
228      * @param value the value
229      * @throws java.io.IOException
230      */
231     void setBreak(boolean value) throws IOException;
232 
233     void setFlowControl(Set<FlowControl> flowControls) throws IOException;
234 
235     void setBaudrate(Baudrate baudrate) throws IOException;
236 
237     void setDataBits(DataBits dataBits) throws IOException;
238 
239     void setStopBits(StopBits stopBits) throws IOException;
240 
241     void setParity(Parity parity) throws IOException;
242 
243     Baudrate getBaudrate() throws IOException;
244 
245     DataBits getDatatBits() throws IOException;
246 
247     StopBits getStopBits() throws IOException;
248 
249     Parity getParity() throws IOException;
250 
251     Set<FlowControl> getFlowControl() throws IOException;
252 
253 }