Source Code Cross Referenced for NexStar.java in  » Science » JSci » JSci » astro » telescope » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » JSci » JSci.astro.telescope 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * The NexStar class encapsulates a NexStar telescope.
003:         * Copyright (C) 1999-2001  Mark Hale
004:         * @author Mark Hale
005:         */package JSci.astro.telescope;
006:
007:        import java.io.*;
008:        import javax.comm.*;
009:
010:        public final class NexStar extends Object {
011:            private SerialPort serial;
012:            private InputStreamReader in;
013:            private OutputStreamWriter out;
014:
015:            /**
016:             * Convert RA from a string to a number.
017:             */
018:            public static int raToInt(String ra) {
019:                final int hrs = Integer.valueOf(ra.substring(0, 2)).intValue();
020:                final int mins = Integer.valueOf(ra.substring(3, 5)).intValue();
021:                final int secs = Integer.valueOf(ra.substring(6, 8)).intValue();
022:                return hrs * 600 + mins * 10 + secs;
023:            }
024:
025:            /**
026:             * Convert dec from a string to a number.
027:             */
028:            public static int decToInt(String dec) {
029:                final int degs = Integer.valueOf(dec.substring(0, 3))
030:                        .intValue();
031:                final int mins = Integer.valueOf(dec.substring(4, 6))
032:                        .intValue();
033:                final int secs = Integer.valueOf(dec.substring(7, 9))
034:                        .intValue();
035:                if (degs >= 0)
036:                    return degs * 600 + mins * 10 + secs;
037:                else
038:                    return degs * 600 - mins * 10 - secs;
039:            }
040:
041:            /**
042:             * Convert alt from a string to a number.
043:             */
044:            public static int altToInt(String alt) {
045:                final int degs = Integer.valueOf(alt.substring(0, 3))
046:                        .intValue();
047:                final int mins = Integer.valueOf(alt.substring(4, 6))
048:                        .intValue();
049:                final int secs = Integer.valueOf(alt.substring(7, 9))
050:                        .intValue();
051:                if (degs >= 0)
052:                    return degs * 600 + mins * 10 + secs;
053:                else
054:                    return degs * 600 - mins * 10 - secs;
055:            }
056:
057:            /**
058:             * Convert az from a string to a number.
059:             */
060:            public static int azToInt(String az) {
061:                final int degs = Integer.valueOf(az.substring(0, 3)).intValue();
062:                final int mins = Integer.valueOf(az.substring(4, 6)).intValue();
063:                final int secs = Integer.valueOf(az.substring(7, 9)).intValue();
064:                return degs * 600 + mins * 10 + secs;
065:            }
066:
067:            /**
068:             * Constructs a NexStar object.
069:             */
070:            public NexStar(String port) {
071:                try {
072:                    CommPortIdentifier portID = CommPortIdentifier
073:                            .getPortIdentifier(port);
074:                    serial = (SerialPort) portID.open("NexStar", 10);
075:                    serial.setSerialPortParams(9600, SerialPort.DATABITS_8,
076:                            SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
077:                    in = new InputStreamReader(serial.getInputStream());
078:                    out = new OutputStreamWriter(serial.getOutputStream());
079:                } catch (NoSuchPortException e) {
080:                    System.err
081:                            .println("Port does not exist: " + e.getMessage());
082:                    e.printStackTrace();
083:                } catch (PortInUseException e) {
084:                    System.err.println("Port is in use by another process: "
085:                            + e.getMessage());
086:                    e.printStackTrace();
087:                } catch (UnsupportedCommOperationException e) {
088:                } catch (IOException e) {
089:                }
090:            }
091:
092:            /**
093:             * Returns the current RA and dec.
094:             */
095:            public synchronized String getRADec() throws IOException {
096:                sendCmd("E");
097:                return readString();
098:            }
099:
100:            /**
101:             * Returns the current az and alt.
102:             */
103:            public synchronized String getAzAlt() throws IOException {
104:                sendCmd("Z");
105:                return readString();
106:            }
107:
108:            /**
109:             * Goto the coordinates.
110:             */
111:            public synchronized void gotoRADec(String ra, String dec)
112:                    throws IOException {
113:                final int raBytes = raToInt(ra);
114:                final int decBytes = decToInt(dec);
115:                out.write('R');
116:                out.write((byte) (raBytes >> 8));
117:                out.write((byte) (raBytes));
118:                out.write(',');
119:                out.write((byte) (decBytes >> 8));
120:                out.write((byte) (decBytes));
121:                out.flush();
122:            }
123:
124:            /**
125:             * Goto the coordinates.
126:             */
127:            public synchronized void gotoAzAlt(String az, String alt)
128:                    throws IOException {
129:                final int azBytes = azToInt(az);
130:                final int altBytes = altToInt(alt);
131:                out.write('A');
132:                out.write((byte) (azBytes >> 8));
133:                out.write((byte) (azBytes));
134:                out.write(',');
135:                out.write((byte) (altBytes >> 8));
136:                out.write((byte) (altBytes));
137:                out.flush();
138:            }
139:
140:            /**
141:             * Check whether the scope is moving.
142:             */
143:            public synchronized boolean isMoving() throws IOException {
144:                sendCmd("L");
145:                return readString().equals("1");
146:            }
147:
148:            /**
149:             * Sends a command to the scope.
150:             */
151:            private void sendCmd(String cmd) throws IOException {
152:                out.write(cmd);
153:                out.flush();
154:            }
155:
156:            /**
157:             * Reads a string from the scope, dropping the terminating #.
158:             */
159:            private String readString() throws IOException {
160:                StringBuffer msg = new StringBuffer();
161:                int ch = in.read();
162:                while (ch != '#') {
163:                    msg.append(ch);
164:                    ch = in.read();
165:                }
166:                return msg.toString();
167:            }
168:
169:            /**
170:             * Closes the connection to the scope.
171:             */
172:            public synchronized void close() throws IOException {
173:                in.close();
174:                out.close();
175:                serial.close();
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.