1- using ASCOM . Common . Interfaces ;
1+ using ASCOM . Common ;
2+ using ASCOM . Common . Interfaces ;
23using System ;
34using System . Diagnostics ;
45using System . Drawing ;
@@ -39,22 +40,25 @@ public class FilterWheelHardware
3940
4041 private const string m_sRegVer = "1" ; // Used to track id registry entries exist or need updating
4142
43+ internal static ILogger Logger
44+ {
45+ get ;
46+ set ;
47+ }
48+
4249
4350 //
4451 // Create some 'realistic' defaults
4552 //
4653 private static Color [ ] DefaultColors = new Color [ 8 ] { Color . Red , Color . Green , Color . Blue , Color . Gray ,
4754 Color . DarkRed , Color . Teal , Color . Violet , Color . Black } ;
4855
49- public static bool m_bLogTraffic ; // Do we log traffic?
50-
5156 //
5257 // Sync object
5358 //
5459 private static object s_objSync = new object ( ) ; // Better than lock(this) - Jeffrey Richter, MSDN Jan 2003
5560
5661 public const string g_csDriverID = "ASCOM.Simulator.FilterWheel" ;
57- private const string g_csDriverDescription = "FilterWheelSimulator FilterWheel" ;
5862 public static IProfile g_Profile ;
5963
6064 // Exception codes/messages
@@ -129,21 +133,21 @@ public static bool Connected
129133 {
130134 lock ( s_objSync )
131135 {
132- LogTraffic ( " Get Connected = " + m_bConnected ) ;
136+ Logger . LogVerbose ( "FilterWheel - Get Connected = " + m_bConnected ) ;
133137 return m_bConnected ;
134138 }
135139 }
136140 set
137141 {
138142 lock ( s_objSync )
139143 {
140- LogTraffic ( " Set Connected = " + m_bConnected + " -> " + value ) ;
144+ Logger . LogInformation ( "FilterWheel - Set Connected = " + m_bConnected + " -> " + value ) ;
141145
142146 // We are always connected to the hardware in the simulator
143147 // So just keep a record of the state change
144148 m_bConnected = value ;
145149
146- LogTraffic ( " (set connected, done)") ;
150+ Logger . LogVerbose ( "FilterWheel - (set connected, done)") ;
147151 }
148152 }
149153 }
@@ -163,7 +167,7 @@ public static short Position
163167 else
164168 ret = m_sPosition ; // Otherwise return position
165169
166- LogTraffic ( " Get Position = " + ret . ToString ( ) ) ;
170+ Logger . LogVerbose ( "FilterWheel - Get Position = " + ret . ToString ( ) ) ;
167171
168172 return ret ;
169173 }
@@ -174,12 +178,12 @@ public static short Position
174178 {
175179 int Jumps ; // number of slot positions we have to move
176180
177- LogTraffic ( " Set Position = " + value + " ..." ) ;
181+ Logger . LogInformation ( "FilterWheel - Set Position = " + value + " ..." ) ;
178182
179183 // position range check
180184 if ( value >= m_iSlots || value < 0 )
181185 {
182- LogTraffic ( " (set postion failed, out of range)") ;
186+ Logger . LogError ( "FilterWheel - (set position failed, out of range)") ;
183187
184188 throw new DriverException ( "Position: " + MSG_VAL_OUTOFRANGE , SCODE_VAL_OUTOFRANGE ) ;
185189 }
@@ -189,7 +193,7 @@ public static short Position
189193 // check if we are already there!
190194 if ( value == m_sPosition )
191195 {
192- LogTraffic ( " (set position, no move required)") ;
196+ Logger . LogInformation ( "FilterWheel - (set position, no move required)") ;
193197 return ;
194198 }
195199
@@ -200,7 +204,7 @@ public static short Position
200204 AbortMove ( ) ; // Stop the motor
201205 else
202206 {
203- LogTraffic ( " (set position failed, already moving)") ;
207+ Logger . LogInformation ( "FilterWheel - (set position failed, already moving)") ;
204208
205209 throw new DriverException ( "Position: " + MSG_MOVING , SCODE_MOVING ) ;
206210 }
@@ -214,7 +218,7 @@ public static short Position
214218 m_bMoving = true ;
215219
216220 // log action
217- LogTraffic ( " (set position in progress)...") ;
221+ Logger . LogVerbose ( "FilterWheel - (set position in progress)...") ;
218222 }
219223 }
220224 }
@@ -223,14 +227,12 @@ public static string[] FilterNames
223227 {
224228 get
225229 {
226- LogTraffic ( " Get FilterNames...") ;
230+ Logger . LogVerbose ( "FilterWheel - Get FilterNames...") ;
227231
228232 string [ ] temp = m_asFilterNames ;
229233 Array . Resize ( ref temp , m_iSlots ) ;
230- if ( m_bLogTraffic )
231234 for ( int i = 0 ; i < m_iSlots ; i ++ )
232- LogTraffic ( " Filter " + i . ToString ( ) + " = " + temp [ i ] . ToString ( ) ) ;
233- LogTraffic ( " (filternames done)" ) ;
235+ Logger . LogVerbose ( "FilterWheel - Filter " + i . ToString ( ) + " = " + temp [ i ] . ToString ( ) ) ;
234236 return temp ;
235237 }
236238 }
@@ -239,13 +241,11 @@ public static int[] FocusOffsets
239241 {
240242 get
241243 {
242- LogTraffic ( " Get FocusOffsets..." + Environment . NewLine ) ;
244+ Logger . LogVerbose ( "FilterWheel - Get FocusOffsets..." + Environment . NewLine ) ;
243245 int [ ] temp = m_aiFocusOffsets ;
244246 Array . Resize ( ref temp , m_iSlots ) ;
245- if ( m_bLogTraffic )
246247 for ( int i = 0 ; i < m_iSlots ; i ++ )
247- LogTraffic ( " Offset " + i . ToString ( ) + " = " + temp [ i ] . ToString ( ) + Environment . NewLine ) ;
248- LogTraffic ( " (focusoffsets done)" + Environment . NewLine ) ;
248+ Logger . LogVerbose ( "FilterWheel - Offset " + i . ToString ( ) + " = " + temp [ i ] . ToString ( ) + Environment . NewLine ) ;
249249 return temp ;
250250 }
251251 }
@@ -304,14 +304,14 @@ public static int TimerTickInverval
304304
305305 public static void AbortMove ( )
306306 {
307- LogTraffic ( " Abort move") ;
307+ Logger . LogInformation ( "FilterWheel - Abort move") ;
308308 // Clear the elapsed time
309309 m_iTimeElapsed = 0 ;
310310 // Stop moving
311311 m_bMoving = false ;
312312 // Set the postion intermediate between start and end
313313 m_sPosition = ( short ) Math . Floor ( Math . Abs ( m_sTargetPosition - m_sPosition ) / 2.0 ) ;
314- LogTraffic ( " (abort done) ") ;
314+ Logger . LogInformation ( "FilterWheel - Abort done") ;
315315 }
316316
317317 public static void UpdateState ( )
@@ -332,8 +332,6 @@ public static void UpdateState()
332332 m_bMoving = false ;
333333 // Set the new position
334334 m_sPosition = m_sTargetPosition ;
335- // log action
336- LogTraffic ( " (position done)" ) ;
337335 }
338336 }
339337 }
@@ -373,7 +371,7 @@ private static void LoadSettings()
373371 }
374372 catch ( Exception ex )
375373 {
376- LogTraffic ( ex . Message ) ;
374+ Logger . LogError ( $ "FilterWheel - { ex . Message } " ) ;
377375 SetDefaultSettings ( ) ;
378376 }
379377 }
@@ -438,12 +436,6 @@ private static void CheckConnected()
438436 if ( ! m_bConnected ) throw new ASCOM . DriverException ( MSG_NOT_CONNECTED , SCODE_NOT_CONNECTED ) ;
439437 }
440438
441- private static void LogTraffic ( string Text )
442- {
443- if ( m_bLogTraffic )
444- Trace . WriteLine ( Text ) ;
445- }
446-
447439 #endregion private utilities
448440 }
449441}
0 commit comments