locked
What works in VB doesnt in C# RRS feed

  • Question

  • I'm writing a MSRS program to communicate with the Boe Bot via bluetooth (easy bluetooth module. Now I know your going to say MSRS doesnt support Boe Bot anymore, but thats okay I wrote a driver program on the boe bot to talk with my msrs program. I have two versions of the same program, one written in VB (which was after a c# program, during troubleshooting) and one in C#. The program sends the letter b (in bytes) out a serial port com3 which is my blue tooth. However the letter that is being recieved by the bluetooth on the robot is coming in as F. Now heres the catch: the same program written in VB sends the letters to the robot just fine, robot backs up when it gets the letter b and forward when it gets f. Upon debugging the program the letters show up in the debug console just as I asked it to do, but no luck in C#. I installed sp1 (which comes with .net 4 update) and still no luck. Any ideas? See my code for both VB and C# below. Thanks to anyone who can point me in the right direction!

    Also its worth noteing that the first letter sent to the boe bot is the letter in question, also the boe bot needs to recieve a second serial command before it executes the action specified.

    -=VB=-

    Imports System.IO.Ports.SerialPort
    
    
    Public Class Form1
        Public serialport As New System.IO.Ports.SerialPort("com3", 9600)
        Public ascii As New System.Text.ASCIIEncoding()
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            serialport.Parity = IO.Ports.Parity.None
            serialport.DataBits = 8
            serialport.StopBits = 1
            serialport.WriteTimeout = 1000
            serialport.Open()
    
    
        End Sub
    
        Private Sub sendData(ByRef buffer As Byte())
            serialport.Write(buffer, 0, buffer.Length)
    
        End Sub
    
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            sendData(ascii.GetBytes("b"))
    
        End Sub
    End Class
    

    -=C#=-

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using Microsoft.Ccr.Core;
    using Microsoft.Dss.Core.Attributes;
    using Microsoft.Dss.ServiceModel.Dssp;
    using Microsoft.Dss.ServiceModel.DsspServiceBase;
    using W3C.Soap;
    using System.IO.Ports;
    using System.Text;
    using System.Windows.Forms;
    using submgr = Microsoft.Dss.Services.SubscriptionManager;
    
    namespace BluetoothBoeBot
    {
        [Contract(Contract.Identifier)]
        [DisplayName("Bluetooth")]
        [Description("Bluetooth service (no description provided)")]
        class BluetoothService : DsspServiceBase
        {
            SerialPort serialport = new System.IO.Ports.SerialPort();
            System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
            /// <summary>
            /// Service state
            /// </summary>
            [ServiceState]
            BluetoothBoeBotState _state = new BluetoothBoeBotState();
    
            /// <summary>
            /// Main service port
            /// </summary>
            [ServicePort("/Bluetooth", AllowMultipleInstances = true)]
            BluetoothBoeBotOperations _mainPort = new BluetoothBoeBotOperations();
    
            [SubscriptionManagerPartner]
            submgr.SubscriptionManagerPort _submgrPort = new submgr.SubscriptionManagerPort();
    
            /// <summary>
            /// Service constructor
            /// </summary>
            public BluetoothService(DsspServiceCreationPort creationPort)
                : base(creationPort)
            {
            }
    
            /// <summary>
            /// Service start
            /// </summary>
    
            void Open(int comPort, int baudRate)
            {
                serialport = new SerialPort("COM" + comPort.ToString(), baudRate);
                serialport.Parity = Parity.None;
                serialport.DataBits = 8;
                serialport.StopBits = StopBits.One;
                serialport.WriteTimeout = 1000;
                serialport.Open();
            }
    
            void sendData(byte[] buffer)
            {
                serialport.Write(buffer, 0, buffer.Length);
    
            }
    
            void serialport_DataRecieved(object sender, SerialDataReceivedEventArgs e)
            {
                
                //_mainPort.Post(sensorMsg); //post sensor message to bluetooth main port
            }
    
            protected override void Start()
            {
    
                // 
                // Add service specific initialization here
                // 
    
                base.Start();
                //serialport.Write("b");
                //serialport.Write("b");
                sendData(ascii.GetBytes("b"));
                sendData(ascii.GetBytes("f"));
    
            }
    
            /// <summary>
            /// Handles Subscribe messages
            /// </summary>
            /// <param name="subscribe">the subscribe request</param>
            [ServiceHandler]
            public void SubscribeHandler(Subscribe subscribe)
            {
                SubscribeHelper(_submgrPort, subscribe.Body, subscribe.ResponsePort);
            }
        }
    }
    

    Saturday, December 31, 2011 5:44 AM

Answers

  • Did you create the project somewhere under the RDS installation folder? DSS services need to run from under there.

    Have a look in the project properties under the Debug tab and make sure that you have specified the correct manifest in the command line, that the manifest actually exists, and that you can open it with DssME and there are no errors.

    Trevor

     

    • Marked as answer by T3rr0rByte13 Monday, January 2, 2012 4:58 AM
    Monday, January 2, 2012 1:10 AM

All replies

  • Okay, just a little update. Created a windows form project in c#... and well it performs as it should. The boe bot recieves the correct b when it should. This leads me to suspect that it's the project file that is creating the grief.

    I'm going to try recreating the project from scratch and see if that helps.

    So see my Robotics blog on the MSRS forums for my progress in solving this issue! :P

    Saturday, December 31, 2011 9:08 AM
  • Okay... the blog continues:

    First of all issue solved, created the new project... with one minor change: added the Open(3,9600); code bit before the sendData(ascii.GetBytes("b")); bit. (my Bad!)

    HOWEVER!: This does not explain why the boe bot continued to recieve the "F" and move forward each time i ran the program. Further more, adding the same line of code to the old project did not achieve the results of the newly made project.

    Anybody with experience know? Chances are this is one of those things that will never really get solved.

    • Marked as answer by T3rr0rByte13 Saturday, December 31, 2011 9:31 AM
    • Unmarked as answer by T3rr0rByte13 Monday, January 2, 2012 12:23 AM
    Saturday, December 31, 2011 9:31 AM
  • Okay so it continues. It seems to stop working after I save the project and then re-open it. Also after closing the project an re-opening it I get an error when trying to run the project, it says "Invalid Manifest Identifier".

    Anybody have any insight? 

    Monday, January 2, 2012 12:26 AM
  • Did you create the project somewhere under the RDS installation folder? DSS services need to run from under there.

    Have a look in the project properties under the Debug tab and make sure that you have specified the correct manifest in the command line, that the manifest actually exists, and that you can open it with DssME and there are no errors.

    Trevor

     

    • Marked as answer by T3rr0rByte13 Monday, January 2, 2012 4:58 AM
    Monday, January 2, 2012 1:10 AM