locked
Multiple instances of Trevor Taylor's Serial Port code RRS feed

  • Question

  • Hey I want to get some tips on how I can tackle this problem.

    On the system I am working on (robot) I have a need to connect up to more than 4 usb ports via hub. Meaning each port will be controlled separately in MDRS. How can I possible introduce the serial port code as a service but at the same time have different configuration for each of these ports. Ultimately what I want to avoid is having to replicate the serial port code 4 times to represent the 4 comm ports. Any ideas would be appreciated ?


    Im new to the world of VPL. Hence why im here :)
    Wednesday, July 20, 2011 11:57 PM

Answers

  • Hmm. I just found that the Visual Studio Wizard does not properly handle multiple instances of a partner. Oh well, it's easy to fix.

    What I did was create a new service using Visual Studio and specify the Serial Port service as a partner 4 times. In the generated code I renamed each of the partners to have a different suffix, e.g. here are the first 2 partners:

        /// <summary>
        /// SerialPortService partner
        /// </summary>
        [Partner("SerialPortService1", Contract = comms.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate)]
        comms.SerialPortOperations _serialPortServicePort1 = new comms.SerialPortOperations();
        comms.SerialPortOperations _serialPortServiceNotify1 = new comms.SerialPortOperations();
    
        /// <summary>
        /// SerialPortService partner
        /// </summary>
        [Partner("SerialPortService2", Contract = comms.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate)]
        comms.SerialPortOperations _serialPortServicePort2 = new comms.SerialPortOperations();
        comms.SerialPortOperations _serialPortServiceNotify2 = new comms.SerialPortOperations();
    
    
    

     

    After compiling this new service, I used the DSS Manifest Editor to edit its manifest. It immediately showed me that this service needs 4 serial ports so I added a new instance of a Serial Port service 4 times, renaming them as I went so that they had the suffixes 1, 2, 3, 4.

    Then I set the Initial Configuration for each of the Serial Port services and specified a different COM port for each one.

    When I saved the manifest it wrote out 4 config files as well as the new manifest.

    I have not been able to test this because I don't have 4 serial ports on my PC, but I think you should get the idea.

    Trevor

     

     

     

     

     

    • Marked as answer by kasunt Tuesday, July 26, 2011 5:37 AM
    Thursday, July 21, 2011 4:51 AM

All replies

  • You can have multiple Serial Port services and create config files for each of them that specify a different COM port.

    Are you working in VPL or C#? If in VPL, then just drag a Serial Port service onto your diagram 4 times and set the initial configuration for each of them. If you are writing in C# you need to create 4 partnerships with different port names and then in the manifest you need to specify the names of the config files for each of the services.

    Trevor

     

    Thursday, July 21, 2011 3:51 AM
  • In C#.

    Have you got a tutorial or an example code somewhere ? I read PMRDS but couldnt see anywhere referring to this. There was a chapter about doing it in VPL.

     

    Thanks alot Trevor. As always very helpful ;)


    Im new to the world of VPL. Hence why im here :)
    Thursday, July 21, 2011 3:55 AM
  • Hmm. I just found that the Visual Studio Wizard does not properly handle multiple instances of a partner. Oh well, it's easy to fix.

    What I did was create a new service using Visual Studio and specify the Serial Port service as a partner 4 times. In the generated code I renamed each of the partners to have a different suffix, e.g. here are the first 2 partners:

        /// <summary>
        /// SerialPortService partner
        /// </summary>
        [Partner("SerialPortService1", Contract = comms.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate)]
        comms.SerialPortOperations _serialPortServicePort1 = new comms.SerialPortOperations();
        comms.SerialPortOperations _serialPortServiceNotify1 = new comms.SerialPortOperations();
    
        /// <summary>
        /// SerialPortService partner
        /// </summary>
        [Partner("SerialPortService2", Contract = comms.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate)]
        comms.SerialPortOperations _serialPortServicePort2 = new comms.SerialPortOperations();
        comms.SerialPortOperations _serialPortServiceNotify2 = new comms.SerialPortOperations();
    
    
    

     

    After compiling this new service, I used the DSS Manifest Editor to edit its manifest. It immediately showed me that this service needs 4 serial ports so I added a new instance of a Serial Port service 4 times, renaming them as I went so that they had the suffixes 1, 2, 3, 4.

    Then I set the Initial Configuration for each of the Serial Port services and specified a different COM port for each one.

    When I saved the manifest it wrote out 4 config files as well as the new manifest.

    I have not been able to test this because I don't have 4 serial ports on my PC, but I think you should get the idea.

    Trevor

     

     

     

     

     

    • Marked as answer by kasunt Tuesday, July 26, 2011 5:37 AM
    Thursday, July 21, 2011 4:51 AM
  • Definitely got the idea.

    Thanks a bunch Trevor. This will work :) ....


    Im new to the world of VPL. Hence why im here :)
    Thursday, July 21, 2011 4:54 AM