/// <summary> /// Overrides RobotBrain Bind function to implement addition LEDAdapter functions. /// </summary> protected override void Bind() { base.Bind(); //Bind to scribbler specific sensors //Specialized LED array directory.Query dquery = new directory.Query(new directory.QueryRequestType( new Microsoft.Dss.ServiceModel.Dssp.ServiceInfoType("http://www.roboteducation.org/scribblerledarray.html"))); //Uri direcURI = DssEnvironment.FindService(directory.Contract.Identifier); //TODO: remove the line below once the above line works Uri direcURI = new Uri("http://localhost:" + httpPort + "/directory"); directory.DirectoryPort dport = DssEnvironment.ServiceForwarder <directory.DirectoryPort>(direcURI); dport.Post(dquery); Arbiter.Activate(DssEnvironment.TaskQueue, Arbiter.Choice(dquery.ResponsePort, delegate(directory.QueryResponseType success) { sledadapter = new ScribblerLEDArrayAdapter(success.RecordList[0].Service); }, delegate(Fault fault) { } ) ); }
public VectorAdapter(ServiceInfoType serviceRecord) { ServiceInfo = serviceRecord; opPort = DssEnvironment.ServiceForwarder <vector.VectorOperations>(new Uri(serviceRecord.Service)); //if (opPort == null) // throw new AdapterCreationException("Service forwarder port was null"); }
protected virtual void Initialize() { // Initialize the port and subscribe to the service motorsOn = false; drivePort = DssEnvironment.ServiceForwarder <drive.DriveOperations>(new Uri(ServiceInfo.Service)); drive.DriveOperations driveNotificationPort = new drive.DriveOperations(); drivePort.Subscribe(driveNotificationPort); // Set up notifications Arbiter.Activate(DssEnvironment.TaskQueue, Arbiter.Receive <drive.Update>(true, driveNotificationPort, NotifyDriveUpdate)); }
protected virtual void Initialize() { // Initialize the port and subscribe to the service to know when the motors are enabled motorsOn = false; drivePort = DssEnvironment.ServiceForwarder <drive.DriveOperations>(new Uri(ServiceInfo.Service)); drive.DriveOperations driveNotificationPort = new drive.DriveOperations(); RSUtils.ReceiveSync(taskQueue, drivePort.Subscribe(driveNotificationPort), Params.DefaultRecieveTimeout); // Set up notifications Arbiter.Activate(DssEnvironment.TaskQueue, Arbiter.Receive <drive.Update>(true, driveNotificationPort, NotifyDriveUpdate)); }
protected void updateAdapters() { var dirPort = DssEnvironment.ServiceForwarder <dirProxy.DirectoryPort>(new Uri("http://localhost:50000/directory")); //Console.WriteLine("Querying directory"); //dirProxy.QueryRequest request = new dirProxy.QueryRequest(); //request.QueryRecord = new ServiceInfoType(); Arbiter.ExecuteToCompletion(DssEnvironment.TaskQueue, Arbiter.Choice <dirProxy.GetResponse, Fault>( dirPort.Get(), delegate(dirProxy.GetResponse success) { // See if each service matches a known one from the config file, if so, make an adapter //Console.WriteLine("Checking " + success.RecordList.Length + " services"); foreach (var rec in success.RecordList) { //Uri foundUri = new Uri(rec.Service); AdapterSpec adapterSpec = null; //Console.WriteLine("Checking " + rec.Service); foreach (var adapter in adapterNames.Values) { //Console.WriteLine("Comparing " + rec.Service + " to " + adapter.ServiceInfo.Service); //Uri testUri = new Uri(adapter.ServiceInfo.Service); //if (Uri.Compare(foundUri, testUri, UriComponents.Path, UriFormat.UriEscaped, StringComparison.InvariantCultureIgnoreCase) == 0) if (rec.Service.EndsWith(adapter.ServiceConfig.Service)) { //Console.WriteLine("* Assigned * " + rec.Service + " to " + adapter.ServiceInfo.Service); if (adapterSpec == null) { adapterSpec = adapter; } else { Console.WriteLine("WARNING: duplicate service: " + rec.Service + " (already had one for " + adapter.ServiceConfig.Service + ")"); } } } if (adapterSpec != null) { AdapterFactory.CreateAdapterIfNeeded(adapterSpec, rec); } } }, delegate(Fault fault) { Console.WriteLine("AdapterBank: Fault querying directory: " + fault.Reason); })); }
/// <summary> /// This is a helper mehtod that connects the Scribbler on the specified /// COM port. It waits for the connection to complete, and re-throws any /// exceptions generated by the Scribbler service. /// </summary> /// <param name="comPort"></param> private static void connectWaitForScribbler(string comPort) { ManualResetEvent evt = new ManualResetEvent(false); waitForService(new ServiceInfoType(scribbler.Contract.Identifier), delegate(ServiceInfoType info) { brickService = info; evt.Set(); }); evt.WaitOne(Params.DefaultRecieveTimeout, false); if (brickService == null) { throw new MyroInitException("Could not find Scribbler service"); } var scribPort = DssEnvironment.ServiceForwarder <scribbler.ScribblerOperations>(new Uri(brickService.Service)); DispatcherQueue queue = new DispatcherQueue("init", new Dispatcher()); try { if (comPort != null) { int comNumber; if (comPort.ToLower().StartsWith("com")) { comNumber = Int32.Parse(comPort.Substring(3)); } else { throw new MyroInitException("COM port string must be of the format com2, com5, etc."); } RSUtils.ReceiveSync(queue, scribPort.Replace(new scribbler.ScribblerState() { ComPort = comNumber }), Params.DefaultRecieveTimeout); } DssEnvironment.LogInfo("calling reconnect..."); RSUtils.ReceiveSync(queue, scribPort.Reconnect(), Params.DefaultRecieveTimeout); DssEnvironment.LogInfo("reconnect returned"); } catch (Exception) { throw; } finally { queue.Dispose(); } }
void ConnectToScribbler(DateTime dt) { Uri driveUri = null; // Look for any active generic drive contract service running Arbiter.Activate(DssEnvironment.TaskQueue, Arbiter.Choice(DssEnvironment.DirectoryQuery(drive.Contract.Identifier), delegate(ServiceInfoType success) { driveUri = new Uri(success.Service); Console.WriteLine("================\n" + driveUri); // Initialize the port and subscribe to the service motorsOn = false; drivePort = DssEnvironment.ServiceForwarder <drive.DriveOperations>(driveUri); drive.DriveOperations driveNotificationPort = new drive.DriveOperations(); drivePort.Subscribe(driveNotificationPort); // Set up notifications Arbiter.Activate(DssEnvironment.TaskQueue, Arbiter.Receive <drive.Update>(true, driveNotificationPort, NotifyDriveUpdate) ); autolock.Set(); }, delegate(W3C.Soap.Fault failure) { // Request failed. Sleep for 1 sec and look for 30 times. if (++attemptCount >= 30) { DssEnvironment.LogError("Unable to find Drive Service, aborting - Press <Enter>"); Console.ReadLine(); DssEnvironment.Shutdown(); } else { // Post a timer message that expires in 30 seconds TimeSpan timeout = new TimeSpan(0, 0, 30); DssEnvironment.TaskQueue.EnqueueTimer(timeout, _timerPort); } } )); }
protected void subscribeDirectory() { var dirPort = DssEnvironment.ServiceForwarder <dirProxy.DirectoryPort>(new Uri("http://localhost:50000/directory")); var resPort = new dirProxy.DirectoryPort(); Arbiter.ExecuteToCompletion(DssEnvironment.TaskQueue, Arbiter.Choice <SubscribeResponseType, Fault>( dirPort.Subscribe(resPort, null), delegate(SubscribeResponseType success) { Console.WriteLine("AdapterBank subscribed to directory service"); }, delegate(Fault failure) { throw new Exception("Could not subscribe to directory service: " + failure.Reason); })); Arbiter.Activate(DssEnvironment.TaskQueue, Arbiter.Receive <dirProxy.Insert>(true, resPort, directoryInsertHandler)); }
public WebcamAdapter(ServiceInfoType serviceInfo) { ServiceInfo = serviceInfo; opPort = DssEnvironment.ServiceForwarder <webcam.WebCamOperations>(new Uri(serviceInfo.Service)); }
protected virtual void Initialize() { // Initialize the port and subscribe to the service ttsPort = DssEnvironment.ServiceForwarder <tts.SpeechTextOperations>(new Uri(serviceUri)); }
protected virtual void Initialize() { // Initialize the port sensorPort = DssEnvironment.ServiceForwarder <contact.ContactSensorArrayOperations>(new Uri(serviceUri)); }
protected virtual void Initialize() { // Initialize the port sensorPort = DssEnvironment.ServiceForwarder <analogArray.AnalogSensorOperations>(new Uri(serviceUri)); Console.WriteLine("Analog sensor array adapter: " + serviceUri); }
/// <summary> /// Helper method that waits for a service to start and runs a handler when it does. /// This subscribes to and queries the DSS directory. /// </summary> /// <param name="serviceInfo"></param> /// <param name="handler"></param> private static void waitForService(ServiceInfoType serviceInfo, Handler <ServiceInfoType> handler) { var dirPort = DssEnvironment.ServiceForwarder <directory.DirectoryPort>(new Uri("dssp.tcp://localhost/directory")); var notPort = new directory.DirectoryPort(); // Keep this flag to only run the handler once bool ranHandler = false; Object lockObj = new Object(); // Subscribe first, then query, to make sure we don't miss the service registering itself DssEnvironment.LogInfo("Subscribing to directory"); Arbiter.Activate(DssEnvironment.TaskQueue, Arbiter.Choice( dirPort.Subscribe( new directory.SubscribeRequest() { QueryRecordList = new List <ServiceInfoType>() { serviceInfo }, NotificationCount = 1 }, notPort, typeof(directory.Insert)), delegate(SubscribeResponseType r) { DssEnvironment.LogInfo("Subscribed to directory!"); // Run handler if the service starts and we get the subscription notification DssEnvironment.LogInfo("Activating subscription receive"); Arbiter.Activate(DssEnvironment.TaskQueue, Arbiter.Receive <directory.Insert>(false, notPort, delegate(directory.Insert ins) { DssEnvironment.LogInfo("Got subscription notification!"); lock (lockObj) { if (ranHandler == false) { new Thread(new ThreadStart(delegate() { handler.Invoke(ins.Body.Record); })).Start(); ranHandler = true; } } })); }, delegate(Fault f) { lock (lockObj) { if (ranHandler == false) { new Thread(new ThreadStart(delegate() { handler.Invoke(null); })).Start(); ranHandler = true; } } DssEnvironment.LogError("Fault received while subscribing to directory: " + Strings.FromFault(f)); })); // Query directory, run handler if the service is already started DssEnvironment.LogInfo("Querying directory"); Arbiter.Activate(DssEnvironment.TaskQueue, Arbiter.Choice( dirPort.Query(new directory.QueryRequest() { QueryRecord = serviceInfo }), delegate(directory.QueryResponse r) { DssEnvironment.LogInfo("Queried directory!"); lock (lockObj) { if (ranHandler == false && r.RecordList.Length > 0) { new Thread(new ThreadStart(delegate() { handler.Invoke(r.RecordList[0]); })).Start(); ranHandler = true; } } }, delegate(Fault f) { //lock (lockObj) //{ // if (ranHandler == false) // { // new Thread(new ThreadStart(delegate() { handler.Invoke(null); })).Start(); // ranHandler = true; // } //} DssEnvironment.LogError("Fault received while querying directory: " + Strings.FromFault(f)); })); }
protected virtual void Initialize() { // Initialize the port sensorPort = DssEnvironment.ServiceForwarder <analogArray.AnalogSensorOperations>(new Uri(serviceUri)); }
protected virtual void Initialize() { // Initialize the port and subscribe to the service tonePort = DssEnvironment.ServiceForwarder <tonegen.ToneGeneratorOperations>(new Uri(serviceUri)); }
protected virtual void Initialize() { // Initialize the port and subscribe to the service ledPort = DssEnvironment.ServiceForwarder <ledarray.LedarrayOperations>(new Uri(serviceUri)); }
/// <summary> /// Searches service directory for a service with the specified contract. On success binds it to an Adapter object and inserts it in the /// adapters lookup dictionary. /// </summary> /// <param name="contract">The contract of the service</param> /// <returns>Nothing</returns> protected virtual IEnumerator <ITask> DirectorySearch(string contract) { directory.Query dquery = new directory.Query(new directory.QueryRequestType( new Microsoft.Dss.ServiceModel.Dssp.ServiceInfoType(contract))); //Uri direcURI = DssEnvironment.FindService(directory.Contract.Identifier); //TODO: remove the line below once the above line works Uri direcURI = new Uri("http://localhost:" + httpPort + "/directory"); directory.DirectoryPort dport = DssEnvironment.ServiceForwarder <directory.DirectoryPort>(direcURI); dport.Post(dquery); yield return(Arbiter.Choice( dquery.ResponsePort, delegate(directory.QueryResponseType success) { switch (contract) { case drive.Contract.Identifier: { ArrayList list = new ArrayList(); for (int i = 0; i < success.RecordList.Length; i++) { if (verbosity >= 2) { Console.WriteLine(contract + ":" + success.RecordList[i].Service); } list.Add(new DriveAdapter(success.RecordList[i].Service)); } AdaptersDictionary.Add(AdapterTypes.DriveAdapter, list); break; } case analog.Contract.Identifier: { ArrayList list = new ArrayList(); for (int i = 0; i < success.RecordList.Length; i++) { if (verbosity >= 2) { Console.WriteLine(contract + ":" + success.RecordList[i].Service); } list.Add(new AnalogSensorAdapter(success.RecordList[i].Service)); } AdaptersDictionary.Add(AdapterTypes.AnalogSensorAdapter, list); break; } case contact.Contract.Identifier: { ArrayList list = new ArrayList(); for (int i = 0; i < success.RecordList.Length; i++) { if (verbosity >= 2) { Console.WriteLine(contract + ":" + success.RecordList[i].Service); } list.Add(new ContactSensorArrayAdapter(success.RecordList[i].Service)); } AdaptersDictionary.Add(AdapterTypes.ContactSensorArrayAdapter, list); break; } case analogArray.Contract.Identifier: { ArrayList list = new ArrayList(); for (int i = 0; i < success.RecordList.Length; i++) { if (verbosity >= 2) { Console.WriteLine(contract + ":" + success.RecordList[i].Service); } list.Add(new AnalogSensorArrayAdapter(success.RecordList[i].Service)); } AdaptersDictionary.Add(AdapterTypes.AnalogSensorArrayAdapter, list); break; } case tonegen.Contract.Identifier: { ArrayList list = new ArrayList(); for (int i = 0; i < success.RecordList.Length; i++) { if (verbosity >= 2) { Console.WriteLine(contract + ":" + success.RecordList[i].Service); } list.Add(new ToneGeneratorAdapter(success.RecordList[i].Service)); } AdaptersDictionary.Add(AdapterTypes.ToneGeneratorAdapter, list); break; } case ledarray.Contract.Identifier: { ArrayList list = new ArrayList(); for (int i = 0; i < success.RecordList.Length; i++) { if (verbosity >= 2) { Console.WriteLine(contract + ":" + success.RecordList[i].Service); } list.Add(new LEDArrayAdapter(success.RecordList[i].Service)); } AdaptersDictionary.Add(AdapterTypes.LEDArrayAdapter, list); break; } case sonar.Contract.Identifier: { ArrayList list = new ArrayList(); for (int i = 0; i < success.RecordList.Length; i++) { if (verbosity >= 2) { Console.WriteLine(contract + ":" + success.RecordList[i].Service); } list.Add(new SonarAdapter(success.RecordList[i].Service)); } AdaptersDictionary.Add(AdapterTypes.SonarAdapter, list); break; } } }, delegate(Fault fault) { } )); yield break; }
protected virtual void Initialize() { // Initialize the port sensorPort = DssEnvironment.ServiceForwarder <sonar.SonarOperations>(new Uri(serviceUri)); }
/// <summary> /// See adapter documentation in the Myro 3 developer manual. /// http://wiki.roboteducation.org/Myro_3.0_Developer_Manual /// </summary> /// <param name="serviceRecord"></param> public FlukeControlAdapter(ServiceInfoType service) { this.ServiceInfo = service; opPort = DssEnvironment.ServiceForwarder <fluke.CamControlOperations>(new Uri(service.Service)); }