MSRS - Exchanging Data with External Applications RRS feed

  • Question

  • I thought it would be very convenient to integrate MSRS with external softwares. Matlab for example, is a great tool for fast development -  an image processing algorithm programmed using hundreds of lines of C# code can be developed in just a few lines in Matlab. Matlab code can also be compiled and converted to a standalone application.


    I thought that MSRS and Matlab can exchange data in such a way that a vector/matrix taken from the MSRS scene (for example, images taken from a robot camera) will constantly be sent to Matlab. Matlab will also constantly process the information and send a result back to the MSRS. This will save, on one hand, a lot of programming efforts. On the other hand it might slow down the performance of the MSRS application due to: (i) the "price" we have to pay for the exchange and (ii) Matlab processing is considered to be slow.


    I did something similar in the past when I wanted to exchange data between a VB .Net application controlling a Motoman 6 DOF fixed-arm robot and Matlab. The VB .Net application sent a signal (vector of numbers as string) to Matlab. Then Matlab processed the signal and returned the pick indexes and values back to the VB . Net application. Similarly it can be done for statistics purposes / using neural networks / fuzzy logic / etc.


    That's a pseudo code that demonstrates it: 

    Code Snippet

    Dim MatLab As Object

    Dim Result As String


    Code Snippet


    MatLab = CreateObject("Matlab.Application")


    Code Snippet

    Result = MatLab.Execute("cd " + A Directory where your ".m" file is placed)


    Result = MatLab.Execute("The name of the ".m" file ([" + String Vector + "])")


    Then you can manipulate the string result using the Mid command, for example, 

    Code Snippet

    Result = Result.Replace(" ", "      ")

    Events_Value_vector_String_Splitted = QuoteSplit(Result, " ")


    and inspect the result using phrases like these: 

    Code Snippet
    Mid(Result, 1, 6)


     QuoteSplit converts a string to an array of numbers that can be used at the VB. Net application:

    Code Snippet

    Public Function QuoteSplit(ByVal str As String, Optional ByVal splitChar As Char = ","c, Optional ByVal QuoteChar As Char = """"c) As String()
            'Use double-quotes to escape the quote character. Example: Hello ""John"" will produce Hello "John"
            Dim quoteOpened As Boolean = False
            Dim al As New ArrayList
            Dim curStr As New System.Text.StringBuilder
            For i As Integer = 0 To str.Length - 1
                Dim c As Char = CChar(str.Substring(i, 1))
                Dim nextChar As String = "" ' Cannot use Char because it is a value type and cannot contain Nothing or empty string
                If str.Length > (i + 1) Then nextChar = str.Substring(i + 1, 1)
                If quoteOpened Then
                    'Look for ending quote character
                    If (Not c = QuoteChar) Then
                    ElseIf c = QuoteChar AndAlso Not nextChar = "" AndAlso nextChar = QuoteChar Then
                        i += 1
                    ElseIf c = QuoteChar Then
                        quoteOpened = False 'Clear
                    End If
                Else 'If Not quoteOpened
                    If c = splitChar Then
                        al.Add(curStr.ToString) 'Add to arraylist
                        curStr.Length = 0 'Clear current string
                    ElseIf c = QuoteChar Then
                        quoteOpened = True
                        curStr.Length = 0 'Clear the current string, so if we have something like: , "Hello World" the result is "Hello World" instead of " Hello World"
                    End If
                End If
            al.Add(curStr.ToString) 'Add to arraylist
            curStr.Length = 0 'Clear current string

            Return CType(al.ToArray(GetType(String)), String())
        End Function


    All Matlab toolboxes are available here:


    Monday, July 16, 2007 3:57 PM