summaryrefslogtreecommitdiff
path: root/trunk/software/host/src/org/reprap/Device.java
blob: 63c646da14552427602332b7120c8c425d03a075 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package org.reprap;

import org.reprap.Printer;
import org.reprap.comms.Address;
import org.reprap.comms.Communicator;

/**
 * Class implements an abstract device containing the basic properties and methods.
 * An "implemented" device refers to for example a UCB/Stepper motor combination, 
 * extruder or other. 
 */
public class Device {

	/**
	 * Adress of the device. Identifier returned by the firmware in the device
	 */
	private Address address;
	
	/**
	 * Result of the last call to isAvailable (which we don't want to call in loops
	 * etc as it does real comms)
	 */
//	private boolean wasAlive = false; // commented out as isAvailable is commented
	
	/**
	 * Communicator
	 * 
	 */
	private Communicator communicator = org.reprap.Main.getCommunicator();
	
	/**
	 * To whom (grammar) do I belong?
	 * if null, device is a brain in a bottle 
	 * (i.e. just working alone on the bench).
	 */
	public Printer printer = null;

	/**
	 * Basic constructor for a device.
	 * @param communicator communicator used by the device
	 * @param address address of the device
	 */
	public Device(Communicator communicator, Address address) {
		this.communicator = communicator;
		this.address = address;
		//isAvailable();
	}
	
	public Device(Address address)
	{
		this.address = address;
		//isAvailable();		
	}

	/**
	 * @return the adress of the device
	 */
	public Address getAddress() {
		return address;
	}


	
	/**
	 * Check if the device is alive
	 * @return
	 */
//	public boolean isAvailable()
//	{		
//	       try {
//	            getVersion();
//	        } catch (Exception ex) {
//	        	wasAlive = false;
//	            return false;
//	        }
//	        wasAlive = true;
//	        return true;
//	}
	
	/**
	 * Result of last call to isAvailable(), which we don't want to
	 * call repeatedly as each call polls the device.
	 * @return
	 */
//	public boolean wasAvailable()
//	{		
//		return wasAlive;
//	}
	
	//*****************************************************************
	
	/**
	 * @return the communicator
	 */
	public Communicator getCommunicator() {
		return communicator;
	}
//
//	/**
//	 * @return Version ID of the firmware the device is running  
//	 * @throws IOException
//	 * @throws InvalidPayloadException
//	 */
//	public int getVersion() throws IOException, InvalidPayloadException {
//		VersionRequestMessage request = new VersionRequestMessage();
//		IncomingContext replyContext = sendMessage(request);
//		VersionResponseMessage reply = new VersionResponseMessage(replyContext);
//		return reply.getVersion(); 
//	}
//	
//	/**
//	 * @param message 
//	 * @return incoming context
//	 * @throws IOException
//	 */
//	public IncomingContext sendMessage(OutgoingMessage message) throws IOException {
//		return communicator.sendMessage(this, message);
//	}
//	
//	/**
//	 * Method to lock communication to this device. 
//	 * <p>TODO: when called?</P> 
//	 */
//	public void lock() {
//		communicator.lock();
//	}
//	
//	/**
//	 * Method to unlock communication to this device
//	 * <p>TODO: when called?</P> 
//	 *  
//	 */
//	public void unlock() {
//		communicator.unlock();
//	}
//	
	//******************************************************************
	
	public void setPrinter(Printer p)
	{
		printer = p;
	}
	public Printer getPrinter()
	{
		return printer;
	}	
}