locked
usb sensor RRS feed

  • Question

  • hi,
    i'm a student and i'm newbie of robotic studio. I have to connect few usb sensors to my pc and i want using it with microsoft robotic studio.the sensors ready work with an other application in windows xp with another software. For example humidity, temperature sensor.i would like to know how realize a vlp block of my sensor.
    My problem is that i dont know how to set the sensor block in order to make it read the data from usb port of my computer.
    I see some sensors in wich the port used was the bluetooth, but what i need is to read the data from the usb, because my sensor have an usb interface.
    Thanks a lot for your help!
    Saturday, May 31, 2008 11:23 AM

Answers

  • I'm not sure that this is a project for a beginner, but here are some steps that might help you.

     

    You should also look at the Service Tutorials. In particular, Service Tutorial 9 is about implementing generic contracts.

     

    Make yourself a folder under your MRDS installation to put your services into. For example, you could call it Projects.

     

    Start a DSS Command Prompt and change directories to your new Projects folder. Then create a new service as follows:

     

    Code Snippet

    dssnewservice /service:usbsensor /i:..\bin\roboticscommon.proxy.dll /alt:"http://schemas.microsoft.com/robotics/2006/06/analogsensor.html"

     

     

    The /service gives your new service a name. A new folder will be created to hold the source files using this name.

    The /i specifies the DLL to look in, which is Robotics Common.

    The /alt says that you want to implement the generic Analog Sensor contract.

     

    Now open your new project. I am going to refer to it as usbsensor, but you might want to give it a different name, especially if you have several different sensors.

     

    You will have to add a Reference to your USB programming library. I am assuming that you can call it from C#. It should be a DLL of some sort.

     

    In Visual Studio, look at usbsensor.cs. This will contain a Start method, which is where you have to open the connection to the USB device. There will also be a handler for the Get operation:

     

    Code Snippet

    /// <summary>

    /// Get Handler

    /// </summary>

    /// <param name="get"></param>

    /// <returns></returns>

    [ServiceHandler(ServiceHandlerBehavior.Concurrent)]

    public virtual IEnumerator<ITask> GetHandler(pxanalogsensor.Get get)

    {

        get.ResponsePort.Post(_state);

        yield break;

    }

     

     

    This returns the current state of the sensor, which must be stored into _state before your post back the response. You can use IntelliSense in Visual Studio to see what the properties are in _state. For the purposes of testing, you can use RawMeasurement which is a double. Call your USB library to get the current value from the device, and then place it into the RawMeasurement.

     

    Now build your service and run it.

     

    Once it is running (and you have your USB device plugged in) you can open a web browser and browse to http://localhost:50000. Then select the Service Directory.

     

    There will be a service called /usbsensor. If you click on this you will see the service state as XML. The Raw Measurement should show the current value. You will have to refresh the page to see it change.

     

    Once you have this working, you might want to set up a timer to regularly poll the sensor and maybe implement subscriptions. However, just work on the Get operation first.

     

    I hope this helps.

     

    Trevor

     

     

     

     

    Tuesday, June 3, 2008 12:04 PM

All replies

  • To make this work you will need to write some services for the USB devices. Does the software that you have for the sensors include a programming library of functions to read from the sensors?

     

    In this case you should implement the Analog Sensor generic contract. However, as you are new to MRDS you might find this a little difficult.

     

    Once you have written services, they will appear automatically in the VPL Services panel and you can use them in your diagrams.

     

    Trevor

     

    Sunday, June 1, 2008 1:26 AM
  • We have the programming library of functions to read from the sensors usb.
    do you can suggest me the work flow for
    implement the Analog Sensor generic contract, pls?
    there is some guide about it that you may send me?
    Thx vey much for you help!

    Monday, June 2, 2008 3:06 PM
  • I'm not sure that this is a project for a beginner, but here are some steps that might help you.

     

    You should also look at the Service Tutorials. In particular, Service Tutorial 9 is about implementing generic contracts.

     

    Make yourself a folder under your MRDS installation to put your services into. For example, you could call it Projects.

     

    Start a DSS Command Prompt and change directories to your new Projects folder. Then create a new service as follows:

     

    Code Snippet

    dssnewservice /service:usbsensor /i:..\bin\roboticscommon.proxy.dll /alt:"http://schemas.microsoft.com/robotics/2006/06/analogsensor.html"

     

     

    The /service gives your new service a name. A new folder will be created to hold the source files using this name.

    The /i specifies the DLL to look in, which is Robotics Common.

    The /alt says that you want to implement the generic Analog Sensor contract.

     

    Now open your new project. I am going to refer to it as usbsensor, but you might want to give it a different name, especially if you have several different sensors.

     

    You will have to add a Reference to your USB programming library. I am assuming that you can call it from C#. It should be a DLL of some sort.

     

    In Visual Studio, look at usbsensor.cs. This will contain a Start method, which is where you have to open the connection to the USB device. There will also be a handler for the Get operation:

     

    Code Snippet

    /// <summary>

    /// Get Handler

    /// </summary>

    /// <param name="get"></param>

    /// <returns></returns>

    [ServiceHandler(ServiceHandlerBehavior.Concurrent)]

    public virtual IEnumerator<ITask> GetHandler(pxanalogsensor.Get get)

    {

        get.ResponsePort.Post(_state);

        yield break;

    }

     

     

    This returns the current state of the sensor, which must be stored into _state before your post back the response. You can use IntelliSense in Visual Studio to see what the properties are in _state. For the purposes of testing, you can use RawMeasurement which is a double. Call your USB library to get the current value from the device, and then place it into the RawMeasurement.

     

    Now build your service and run it.

     

    Once it is running (and you have your USB device plugged in) you can open a web browser and browse to http://localhost:50000. Then select the Service Directory.

     

    There will be a service called /usbsensor. If you click on this you will see the service state as XML. The Raw Measurement should show the current value. You will have to refresh the page to see it change.

     

    Once you have this working, you might want to set up a timer to regularly poll the sensor and maybe implement subscriptions. However, just work on the Get operation first.

     

    I hope this helps.

     

    Trevor

     

     

     

     

    Tuesday, June 3, 2008 12:04 PM
  • Hi,

    I have created a c++ file (the program and the libreries that read from usb sensor are writted in c++ so I prefer to implement my service in this language) whit the dssprompt and the string "dssnewservice" and the "/language" option to specify the c++ language.
    I open the .sln file whit visual studio, i have compile and run it in order to try to open it whit vpl.
    I found my new service and I connect it a dialog window.
    The only avable variable that i can use is Member, the variable in which there is stored the string "This is my state!".
    What i need to know is:
     
    1)how the service share the variables with vpl?
    2)How can I put other variables from service to vpl in order to store in those variables the data from usb sensors?
    3)Where have I put the function code that reads from usb? (in which part of the .cpp file)
    4)Do I have to include in my c++ project something like the RawMeasurement variable that you suggest me in the last answer u sent me?

    5)Why when i create a new service using c# like you told me, i can see a lot of variables and when i try this:


    dssnewservice /service:usbsensor /i:..\bin\roboticscommon.proxy.dll /alt:"http://schemas.microsoft.com/robotics/2006/06/analogsensor.html" /L:cpp


    i see only Member variable in VPL and i don't see all the variables that i need when i read from an usb sensor like RawMeasurement?


    This is my code generated whit dssnewservice: 

    Code Snippet

    #include "Lux_cpp.h"


    namespace Robotics {

     Lux_cpp::Lux_cpp(DsspServiceCreationPort^ creationPort)
      : DsspServiceBase(creationPort),
      _state(gcnew Lux_cppState()),
      _mainPort(gcnew Lux_cppOperations())
     {
      Activate(
       Arbiter::Interleave(
        gcnew TeardownReceiverGroup(
         Arbiter::Receive<DsspDefaultDrop^>(false, _mainPort, gcnew Handler<DsspDefaultDrop^>(this, &Lux_cpp::DefaultDropHandler))
        ),
        gcnew ExclusiveReceiverGroup(
         Arbiter::Receive<Replace^>(true, _mainPort, gcnew Handler<Replace^>(this, &Lux_cpp::ReplaceHandler))
        ),
        gcnew ConcurrentReceiverGroup(
         Arbiter::Receive<DsspDefaultLookup^>(true, _mainPort, gcnew Handler<DsspDefaultLookup^>(this, &Lux_cpp::DefaultLookupHandler)),
         Arbiter::Receive<Get^>(true, _mainPort, gcnew Handler<Get^>(this, &Lux_cpp::GetHandler)),
         Arbiter::Receive<HttpGet^>(true, _mainPort, gcnew Handler<HttpGet^>(this, &Lux_cpp::HttpGetHandler))
        )
       )
      );
     }

     void Lux_cpp::Start()
     {
      DsspServiceBase::Start();
     }

     void Lux_cpp::GetHandler(Get^ get)
     {
      get->ResponsePort->Post(_state);
     }

     void Lux_cpp::HttpGetHandler(HttpGet^ httpGet)
     {
      httpGet->ResponsePort->Post(gcnew HttpResponseType(_state));

     }

     void Lux_cpp::ReplaceHandler(Replace^ replace)
     {
      _state = replace->Body;
      replace->ResponsePort->Post(DefaultReplaceResponseType::Instance);
     }

     }

     

     

     


    Thanks a lot for your great help!

     

    Tuesday, June 10, 2008 10:58 AM
  • OK, I did not expect you to create a service in C++. When you do this with dssnewservice it does not create an implementation of a generic contract. So let's forget about the generic contract for now.

     

    Have a look at samples\Technologies\Interop\UsbView. This sample might help you, not because it reads from a USB device but because it shows how to add more info to the service state and also how to display the state in a web browser using an XSLT file (although this is not essential).

     

    In the following explanation xxx is the name of your service.

     

    In the xxxTypes.h file there should be a definition for the xxx_State class. It only has one member at the moment. You can add more members as ints, doubles, etc. Note that you must use the [DataContract] attribute on any members that you want to be visible in VPL and they have to be public.

     

    Next, you need to edit the xxx.cpp file. This will have a method called GetHandler that probably has just one line that posts back the _state variable. Assuming you have expanded the State class with appropriate properties, then you need to call the USB library here and put the values into _state before you post it back.

     

    Make the same changes to populate _state in the HttpGetHandler method as well. This will allow you to view the current value of the sensor using a web browser. You need an XSLT file if you want to format the web page so it looks pretty.

     

    That's all you need to do if you just want access to the current sensor reading. Then in VPL you can issue a Get and the result will contain the sensor value.

     

    Trevor

     

     

    Wednesday, June 11, 2008 11:16 AM
  • Hi Trevor,
    I have to tell u a big thanks for the help u are giving me!
    I finally have my service, it reads from usb and send to the http page the values of my variables.
    The last step i need to make is to run my service on a device in wich it is installed windows CE5.
    It means that i have to convert my c++ service in a compact framework service and, using utility dssdeploy.exe, make an exe file which extract the needed folder on the device.
    I already try to make it, the cf.dsshost.exe works on the device, but i have some errors. This is what i read on the device monitor:


    Rebuilding contract directory cache. This will take a few moments ...
    Contract directory cache refresh complete
    *   Service uri:  [06/16/2008 07:38:05][http://colibri:50000/directory]
    *   Service uri:  [06/16/2008 07:38:10][http://colibri:50000/constructor/78ef4c9
    d-d284-4397-b0e9-965bdd2f19ae]
    *   Starting manifest load: file:///flashdisk/services/lux/lux.manifest.xml [06/
    16/2008 07:38:16][http://colibri:50000/manifestloaderclient]
    Rebuilding contract directory cache. This will take a few moments ...
    Contract directory cache refresh complete
    **  Error creating service. Fault Subcode:UnknownEntry. Service type:http://sche
    mas.tempuri.org/2008/06/lux/diagram.html [06/16/2008 07:38:22][http://colibri:50
    000/constructor/78ef4c9d-d284-4397-b0e9-965bdd2f19ae]
    *** Manifest Loader: Creating service failed: http://schemas.tempuri.org/2008/06
    /lux/diagram.html.
    Reason: unspecified [06/16/2008 07:38:22][http://colibri:50000/manifestloader/2f
    303d37-c4cb-41a5-be93-05acb1fc9a01]
    **  Error creating service. Fault Subcode:UnknownEntry. Service type:http://sche
    mas.tempuri.org/2008/06/toralux_cpp.html [06/16/2008 07:38:24][http://colibri:50
    000/constructor/78ef4c9d-d284-4397-b0e9-965bdd2f19ae]
    *** Manifest Loader: Creating service failed: http://schemas.tempuri.org/2008/06
    /toralux_cpp.html.
    Reason: unspecified [06/16/2008 07:38:24][http://colibri:50000/manifestloader/2f
    303d37-c4cb-41a5-be93-05acb1fc9a01]
    *   Manifest load complete [06/16/2008 07:38:25][http://colibri:50000/manifestlotor


    If i try to see the control panel of this service it works, but i cant see the service which read from usb running.
    May u tell me the workflow to have a winCE5 application wich use the compact framework, starting from my c++ file?
    As i alrady told u i have a c++ file and i wish to have a file in winCE with reads the values from the usb of the device, like did with the usb of my laptop.

    Monday, June 16, 2008 3:59 PM
  • Glad you got it partially working.

     

    Before going any further, do you have device drivers and the programming library for Windows CE 5.0? If not, then you cannot proceed from here.

     

    Can you tell me who the supplier of the USB device is? It might help me to look at their web site.

     

    Presumably they have the necessary software and some way to test that the device is working on WinCE. I suggest you verify this first.

     

    You realise that you need to create a Compact Framework (CF) project from your existing MRDS project. I assume that this was successful and you can build the CF project on your laptop.

     

    Then you create a DssDeploy package to copy the CF code over to your embedded device. I am a little concerned to see diagram.html mentioned in the Manifest Loader output. This suggests to me that you have used VPL. In that case you will need to convert the VPL code to C# (use the compile as a service option) and then convert the C# service to the Compact Framework.

     

    The error messages in your posting indicate that cf.dsshost could not find the services. Please check after you have run DssDeploy on the embedded device to make sure that all of the DLLs for your compact services are there.

     

    Trevor

     

     

     

    Tuesday, June 17, 2008 6:28 AM
  • Hi trevor,
    I have the dll library and the driver for the mobile device.
    My problem is how to convert my c++ project to a cf one, because i think that the way i used for now isnt correct.
    May u tell me the easiest way to make this conversion?
    I try a lot of ways:

    1) I try to cnvert the c++ file in a cf file by typing this in cmd:

    dssnewservice.exe /generatecfproject:Toralux_cpp.vcproj

    As the result i have the file "cf.Toralux_cpp.vcproj".
    I try to build this file to have the cf.toralux_cpp.dll but in the cf folder of msrs i dont see this file.
    It means that, when i try to make dssdeploy.exe /p /cf /m, i have this error:

    *** Exception Finding Service: Could not find the needed CF file: c:\microsoft
        robotics studio (1.5)\bin\cf\cf.toralux_cpp.dll
    and in the package there arent all the needed files.

    2) I try to open a new vpl project, i put the bloc Toradex_cpp in this project and then i compiled it like a service;
    I have a cs project like result. I build it, and with dssnewservice /genera...., i convert it in a cf file.If i try to open this cf file, I see in  the references that i have a problem (there is a ! simbol) with the cf.Toralux_cpp.Proxy. (Toralux_cpp is the service that i put in vpl to make the cs file).
    If i try to build this cf project i obtain the cf files in the cd directori of msrs, but, when i try to deploy, i have again the problem with the
    cf.toralux_cpp.dll.

    *** Exception Finding Service: Could not find the needed CF file: c:\microsoft
        robotics studio (1.5)\bin\cf\cf.toralux_cpp.dll
    and in the package there arent all the needed files.


    Then I have some problems to convert my c++ file in a cf file.


    Thanks again for your help!
    U have an holiday payed in italy! :-D


    Tuesday, June 17, 2008 7:14 AM
  • Hi all,

     

    This is an old post.

     

    However very interesting.

     

    I am interested in how a webpage (mass market) could read sensor data (run time) off a USB device.

     

    We would create the USB device to our own specification.

     

    The question is what are the most user friendly ways in which a customer could surf to a website - plugin the USB device - the webpage - server etc... reads the USB device sensor data and sends it to a remote hosted server.

     

    I am guessing that we would have to create a bespoke driver for the device - or an activex plugin - and that the website would access the driver - through javascript calls.

     

    The other thing I was wondering is whether it would be possible to piggy back off exsiting generic USB drivers?

     

    Sorry guys I am not a programmer - so I might be off track.

     

    Any input to point me in the right direction appreciated.

     

     

    Kind Regards

    David Wright

    Wednesday, December 10, 2008 2:46 AM
  • Hi David,

    This question is actually off-topic because this is a Robotics forum.

    Reading from a USB device would be a security violation for a web browser, unless you use an ActiveX control. Normal JavaScript is "sandboxed" and would not be able to do it -- as you have guessed.

    I don't see why it could not be done, but personally I would never install such an ActiveX control because I would be really concerned about what it might be doing on my machine that I did not know about :-)

    Trevor

     

    Friday, December 12, 2008 7:38 AM
  • Hi,

    I'm probably much too late. But I just found this very low cost sensors with an interface for the Microsoft Robotics Studio. I think this a very nice way if you want save some time.
    http://www.toradex.com/En/Products/Oak_USB_Sensors

    Gnal 
    Wednesday, July 15, 2009 6:13 AM