RoboTXController und VisualBasicExpress2010

Alles rund um TX(T) und RoboPro, mit ft-Hard- und Software
Computing using original ft hard- and software
Forumsregeln
Bitte beachte die Forumsregeln!
Antworten
Andy42
Beiträge: 20
Registriert: 05 Apr 2014, 18:42

RoboTXController und VisualBasicExpress2010

Beitrag von Andy42 » 07 Apr 2014, 19:39

Liebe Fischertechnik-RoboTX-Freunde,

seit einiger Zeit versuche ich bislang völlig ergebnislos den Robo TX Controller (v1.30) mithilfe von VisualBasic 2010 Express (WinXP) zu programmieren. Es wäre dabei sehr praktisch DLLs ftMscLib.dll, umFish50.dll, ftMscLib.dll usw. über [Verweise ...] einbilden zu können. Leider geht das nur mit FishFaceTX.dll, die zu der .net Programmierung kompatibel ist, aber offenbar ist diese eine Bibliothek alleine unzureichend. Somit ist die Anwendung von Declare unumgänglich. Im Internet habe ich folgendes gefunden:


Dear Fischertechnik-RoboTX friends,

for a lot of hours I have tried to program the Robo TX Controller (v1.30) with VisualBasic 2010 Express (WinXP), up to now without any progress. It would be very helpful to refer to DLLs like ftMscLib.dll, umFish50.dll, ftMscLib.dll. Unfortunately this only works with FishFaceTX.dll, which is compatible with .net programming. The use of FishFaceTX.dll seems to be not enough. So the use of DECLARE Function seems to be necessary. In the Internet I found the following code:

***

Imports System
Imports System.Text
Imports System.Runtime.InteropServices

Public Class FTXLib

Declare Function IniLib Lib "ftMscLib.dll" Alias "ftxInitLib" () As UInteger
Declare Sub CloseLib Lib "ftMscLib.dll" Alias "ftxCloseLib" ()
Declare Function ftxOpenComDevice Lib "ftMscLib.dll" Alias "ftxOpenComDevice" (<MarshalAs(UnmanagedType.LPStr)> ByVal comStr As String, ByVal baudr As UInteger, <Out()> ByRef errcode As UInteger) As UInteger

<DllImport(".//ftMscLib.dll", EntryPoint:="ftxCloseDevice")> _
Public Shared Sub CloseInterface(ByVal fthdl As UInteger)
End Sub

***

Sub Main()
Dim errCode2 As UInteger
FTXLib.IniLib()
fthdl = FTXLib.ftxOpenComDevice("COM7", 38400, errCode2) '<- hier gibt es immer irgendwelche Fehler, always problem here
FTXLib.CloseInterface(fthdl)
FTXLib.CloseLib()
End Sub

***

Wenn man das so laufen läßt im debuger, meldet der Robo TX Controller einen Verbindungsaufbau. Ganz falsch kann das also nicht sein. Allerdings bleibt dann der Debuger stehen. Das Hauptproblem scheint eine irgendwie unpassende Variablendefinition zu sein. Bei Variation der Parametrierung und Variablenfestlegung gibt es dann noch die Meldung von unpassenden Speicherzugriffen, oder sonstigem.

Hat vielleicht jemand das Problem schonmal gelöst? Eine Veröffentlichung wäre nett. So wäre z.B. eine Sammlung der wichtigsten Dektarationen sehr schön zu haben ... :)



when I start running this code in debug mode, the Robo TX Controller indicates a connection. So the code can not be completely wrong. But then the debuger stops working thru the code. The main problem seems to be an uncorrect variable declaration. With different parameters ther are error messages bacase of wrong memory access or different other things.

May be there is some one who alredy solved this problem. A publication would be very nice. So a summary of important declaration (e.g. DECLARE ode DLLIMPORT) would be very nice to have ... :)



Andy42

a c

vleeuwen
Beiträge: 1585
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von vleeuwen » 07 Apr 2014, 20:25

Hi Andy,
See my earlier publication about this subject too.

Only the C-API functions without a callback are easy to use at .NET 3.5 and 4.0 level.
In case you like to use the C-API functions which are using a callback, you need to develop a wrapper from unmanaged code to managed code (events and delegates).
For this you will need C++ friendly callback backs (with a context parameter) which are available in the extended FTMscLib (tested with MS-Visual Studio 2010/2012).

The Umfish dll's are probably not ported to firmaware 1.30.

As example some C# code.(You will need to transform these into VB.NET)

Code: Alles auswählen

public class DLL {
        const string dllpath = ".\\ftMscLib.dll";
        const int VERSTRLEN = 25;

        [DllImport(dllpath, EntryPoint = "ftxGetLibVersionStr")]
        static extern uint GetLibVersionStr(StringBuilder sb, uint len);

        [DllImport(dllpath, EntryPoint = "ftxInitLib")]
        public static extern uint InitLib();

        [DllImport(dllpath, EntryPoint = "ftxCloseLib")]
        public static extern uint CloseLib();

        [DllImport(dllpath, EntryPoint = "ftxOpenComDevice")]
        public static extern uint OpenComDevice(string comStr, uint bdr, ref uint err);

        [DllImport(dllpath, EntryPoint = "ftxCloseDevice")]
        public static extern uint CloseDevice(uint fthdl);

        [DllImport(dllpath, EntryPoint = "ftxStartTransferArea")]
        public static extern uint StartTransferArea(uint fthdl); 

        [DllImport(dllpath, EntryPoint = "ftxStopTransferArea")]
        public static extern uint StopTransferArea(uint fthdl);

        [DllImport(dllpath, EntryPoint = "SetOutMotorValues")]
        public static extern uint SetMotorValues(uint fthdl, int shmId, int id, int duty_p, int duty_m, bool brake);

        [DllImport(dllpath, EntryPoint = "SetFtMotorConfig")]
        public static extern uint SetMotorConfig(uint fthdl, int shmId, int id, bool status);

        [DllImport(dllpath, EntryPoint = "SetFtUniConfig")]
        public static extern uint SetUniConfig(uint fthdl, int shmId, int id, int mode, bool status);

        [DllImport(dllpath, EntryPoint = "SetOutCounterReset")]
        public static extern uint SetCntReset(uint fthdl, int shmId, int id);

        [DllImport(dllpath, EntryPoint = "GetInCounterValue")]
        public static extern unsafe uint GetInCntValue(uint fthdl, int shmId, int idx, ref ushort count, ref ushort val);

        [DllImport(dllpath, EntryPoint = "GetInIOValue")]
        public static extern unsafe uint GetUniInValue(uint fthdl, int shmId, int idx, ref short val, ref bool overrun);

        [DllImport(dllpath, EntryPoint = "GetInDisplayButtonValue")]
        public static extern unsafe uint GetDisplayButton(uint fthdl, int shmId, ref ushort left, ref ushort right);

        [DllImport(dllpath, EntryPoint = "SetRoboTxMessage")]
        public static extern uint SetRoboTxMessage(uint fthdl, int shmId, string msg);

       [DllImport(dllpath, EntryPoint = "GetRoboTxSlaveAlive")]
        public static extern unsafe uint IsIFSlaveAlive(uint fthdl, int id, ref bool alive);

        [DllImport(dllpath, EntryPoint = "GetRoboTxSlaveState")]
        public static extern unsafe uint IFSlaveState(uint fthdl, byte[] alive);

       }

Andy42
Beiträge: 20
Registriert: 05 Apr 2014, 18:42

Re: RoboTXController und VisualBasicExpress2010

Beitrag von Andy42 » 13 Apr 2014, 11:51

Thank you vleeuwen for your rapid support.
After several hours of Internet activity and in this Forum I did not get it running under VisualBasic. Using ftxOpenComDevice the parameter errCode2 is one, which contains an answer after running the funcion. I am sure you are right that there is a callback problem. Unfortunately I have no Idea unsing a wrapper or program callbacks.

Anyhow, maybe there is a fischertechnik VB programmer out there who solved this Problem. It would be very nice to share the code for using callbacks under VB2012Express.

have a nice day
Andy42

vleeuwen
Beiträge: 1585
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von vleeuwen » 13 Apr 2014, 21:30

The problem is that native .NET support is missing for the TX-C.

I have the basic stuff for the TX-C at .NET level running.
However I am using C#. This less important because C# and VB.NET are using the same assemblies.
Are you able to work with C# examples and transform these into VB.NET?

For the moment I am rather busy, maybe later this week I have some time free to do something with VB.NET.

vleeuwen
Beiträge: 1585
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von vleeuwen » 13 Apr 2014, 23:02

Hi Andy42
Some suggestions, I did not yet tested myself!!
Maybe you have time to test is?
I tried to translate my C# code into VB.NET

A) You need to import all the functions that you are using
B) You need to check if the lib is init [ftxIsLibInit()]
C) You need to check if the com port is available (the right name) with

Code: Alles auswählen

Imports System
Imports System.Text
Imports System.Runtime.InteropServices

Sub Main()
 Dim errCode2 As UInteger
Dim errCode As UInteger

  errCode=FtMscLibEx.IniLib()
'===================
'check error code
' user code    errCode=ftxIsLibInit()]
'===================
'===================
'get list of available com TX-C devices
' user code containing:
'ftxGetAvailableComPorts and ftxEnumComPorts
'===================

'===================
'Open an existing device
'===================

 fthdl = FtMscLibEx.ftxOpenComDevice("COM7", 38400, errCode2) '<- hier gibt es immer irgendwelche Fehler, always problem here
'===================
'check error code
' user code
'===================

 errCode=FtMscLibEx.CloseInterface(fthdl)
'===================
'check error code
' user code
'===================

 errCode=FtMscLibEx.CloseLib()
 End Sub



FtMscLibEx class.vb

Code: Alles auswählen

 Public Class FtMscLibEx
'Todo: test if the String(Buider) parames are used properly

 Public Class FtMscLibEx
    Const dllpath As String = ".\\FtMscLib\\ftMscLib.dll"
    Const VERSTRLEN As Integer = 25

    <DllImport(dllpath, EntryPoint:="ftxGetLibVersionStr")> _
    Public Shared Function GetLibVersionStr(ByRef sb As StringBuilder, ByVal len As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxGetAvailableComPorts")> _
    Public Shared Function ftxGetAvailableComPorts(ByVal selectMode As Integer) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxEnumComPorts")> _
    Public Shared Function ftxEnumComPorts(ByVal idx As UInteger, ByRef comStr As StringBuilder, ByVal len As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxOpenComDevice")> _
    Public Shared Function OpenComDevice(<MarshalAs(UnmanagedType.LPStr)> ByVal comStr As String, ByVal bdr As UInteger, ByRef uint As UInteger) As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="ftxOpenComDeviceNr")> _
    Public Shared Function OpenComDeviceNr(ByVal comStr As UInteger, ByVal bdr As UInteger, ByRef uint As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxInitLib")> _
    Public Shared Function ftxInitLib() As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="ftxIsLibInit")> _
    Public Shared Function ftxIsLibInit() As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="ftxCloseLib")> _
    Public Shared Function ftxCloseLib() As UInteger
    End Function
' More functions
End Class


Ad2
Beiträge: 306
Registriert: 31 Okt 2010, 22:20

Re: RoboTXController und VisualBasicExpress2010

Beitrag von Ad2 » 14 Apr 2014, 08:27

Shouln't COM devices be opened as "\\.\COM7" for instance? Since the \ is an escape char, at least in C. You may need to write it as "\\\\.\\COM7"

vleeuwen
Beiträge: 1585
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von vleeuwen » 14 Apr 2014, 17:51

Hi Ad
I don't expect this because it is using the same assemblies as in C#.
And in C# I am using for example "COM6".

Andy42
Beiträge: 20
Registriert: 05 Apr 2014, 18:42

Re: RoboTXController und VisualBasicExpress2010

Beitrag von Andy42 » 14 Apr 2014, 20:41

Dear ftFriends,

thank you for your support. I took your code and modified it like this, to get rid of error indications and I have changed the dllpath to define a explicit file of ftMscLib.dll (file date: 13.11.2012, dll-internal modification date Tuesday 13 November 2012, 15.24.44):

Code: Alles auswählen


Imports System
Imports System.Text
Imports System.Runtime.InteropServices

Public Class FtMscLibEx

    'Todo: test if the String(Buider) parames are used properly

    'Const dllpath As String = ".\\FtMscLib\\ftMscLib.dll"  'ALT
    Const dllpath As String = "c:\WINDOWS\system32\ftMscLib.dll"  
    Const VERSTRLEN As Integer = 25

    <DllImport(dllpath, EntryPoint:="ftxGetLibVersionStr")> _
    Public Shared Function GetLibVersionStr(ByRef sb As StringBuilder, ByVal len As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxGetAvailableComPorts")> _
    Public Shared Function ftxGetAvailableComPorts(ByVal selectMode As Integer) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxEnumComPorts")> _
    Public Shared Function ftxEnumComPorts(ByVal idx As UInteger, ByRef comStr As StringBuilder, ByVal len As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxOpenComDevice")> _
    Public Shared Function OpenComDevice(<MarshalAs(UnmanagedType.LPStr)> ByVal comStr As String, ByVal bdr As UInteger, ByRef uint As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxOpenComDeviceNr")> _
    Public Shared Function OpenComDeviceNr(ByVal comStr As UInteger, ByVal bdr As UInteger, ByRef uint As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxInitLib")> _
    Public Shared Function ftxInitLib() As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxIsLibInit")> _
    Public Shared Function ftxIsLibInit() As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxCloseLib")> _
    Public Shared Function ftxCloseLib() As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxCloseDevice")> _
    Public Shared Sub CloseInterface(ByVal fthdl As UInteger)
    End Sub



    ' More functions


End Class

Code: Alles auswählen


Module Module1

    Sub Main()

        Dim errCode2 As UInteger
        Dim errCode As UInteger

        errCode = FtMscLibEx.ftxInitLib()
        '===================
        'check error code
        ' user code    errCode=ftxIsLibInit()]
        '===================
        '===================
        'get list of available com TX-C devices
        ' user code containing:
        'ftxGetAvailableComPorts and ftxEnumComPorts
        '===================

        '===================
        'Open an existing device
        '===================

        fthdl = FtMscLibEx.OpenComDevice("COM11", 38400, errCode2) '<-ERROR MESSAGE
        '===================
        'check error code
        ' user code
        '===================

        FtMscLibEx.CloseInterface(fthdl)
        '===================
        'check error code
        ' user code
        '===================

        errCode = FtMscLibEx.ftxCloseLib()

    End Sub

End Module

After running main() the controller itself indicated on its display, so I think that there is no general trouble with com definition:

-local, BT connected (BT=BlueTooth)
-no program file loaded
-master

The VisualBasic code stoped running at command "FtMscLibEx.OpenComDevice" als always, with an unclear error message:

PInvokeStackImbalance wurde erkannt.
Message: Ein Aufruf an die PInvoke-Funktion "RoboTX_Ctrl!WindowsApplication1.FtMscLibEx::OpenComDevice" hat das Gleichgewicht des Stapels gestört. Wahrscheinlich stimmt die verwaltete PInvoke-Signatur nicht mit der nicht verwalteten Zielsignatur überein. Überprüfen Sie, ob die Aufrufkonvention und die Parameter der PInvoke-Signatur mit der nicht verwalteten Zielsignatur übereinstimmen.

@ vleeuwen:
Up to now I have no experience with c# or c++ programming, I just started to make first steps with it, but I think I am not too bad in VB code-ing under Version 6.0 (from 1998) and making VB programs under MS Office (Excel, Access).

so thats it for now, thank you
cu Andy42

vleeuwen
Beiträge: 1585
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von vleeuwen » 14 Apr 2014, 22:16

@Andy42
VB 6 code difference a lot from VB.NET, be aware of this.
I saw your last e-mail after I close this contribution. The results are the same I think.

Program tested with MS-Visual Studio 2013 prof.
Connection with the TX-C is working.

In this case my TX-C is connected by USB and is using "COM11"
In the console output of the example program, you will see this in the enumeration as:

"found COM11 (fischertechnik USB ROBO TX Controller)"

The program is written in a great hurry, the quality is not so well.
I hope this will help you!!

The console test program

Code: Alles auswählen

Imports System
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.IO

Module Module1

    Sub Main()
        Console.WriteLine("hoi")
        Debug.WriteLine("hoi", "fischertechnik")
        Dim errCode2 As UInteger
        Dim errCode As UInteger
        Dim fthdl As UInteger
        Dim Len As UInteger
        Dim r As UInteger
        Dim buff As StringBuilder = New StringBuilder(45)
        Dim buff2 As StringBuilder = New StringBuilder(45)
        Console.WriteLine(If(File.Exists(FtMscLibEx.dllpath), "File exists.", "File does not exist."))

        errCode = FtMscLibEx.ftxInitLib()
        Len = FtMscLibEx.ftxGetLibErrorString(errCode, 1, buff, 40)
        Console.WriteLine(buff)


        '===================
        'check error code
        ' user code    errCode=ftxIsLibInit()]
        '===================
        '===================
        'get list of available com TX-C devices
        ' user code containing:
        'ftxGetAvailableComPorts and ftxEnumComPorts
     
        Len = FtMscLibEx.ftxGetAvailableComPorts(0)
        For tel As UInteger = 0 To Len - 1
            r = FtMscLibEx.ftxIsLibInit()
            buff2 = New StringBuilder(100)
            buff = New StringBuilder(100)
            r = FtMscLibEx.ftxEnumComPorts(tel, buff2, 100)
            If (r < 100) Then
                Console.WriteLine(" found " + buff2.ToString())
            Else
                FtMscLibEx.ftxGetLibErrorString(r, 1, buff, 40)
                Console.WriteLine(buff)
            End If

        Next
        Len = FtMscLibEx.ftxGetAvailableComPorts(2)
        For tel As UInteger = 0 To Len - 1
            r = FtMscLibEx.ftxIsLibInit()
            FtMscLibEx.ftxGetLibErrorString(r, 1, buff, 40)
            Console.WriteLine(" LibInit " + buff.ToString())
            buff2 = New StringBuilder(100)
            buff = New StringBuilder(100)
            r = FtMscLibEx.ftxEnumComPorts(tel, buff2, 100)
            If (r < 100) Then
                Console.WriteLine(" found " + buff2.ToString())
            Else
                FtMscLibEx.ftxGetLibErrorString(r, 1, buff, 40)
                Console.WriteLine(buff)
            End If

        Next
        fthdl = FtMscLibEx.ftxOpenComDevice("COM11", 38400, errCode2) '<- hier gibt es immer irgendwelche Fehler, always problem here
        Len = FtMscLibEx.ftxGetLibErrorString(errCode2, 1, buff, 40)
        Console.WriteLine(" OpenComDevice " + buff.ToString())
        errCode = FtMscLibEx.ftxCloseDevice(fthdl)
        FtMscLibEx.ftxGetLibErrorString(errCode, 1, buff, 40)
        Console.WriteLine(" CloseDevice " + buff.ToString())

        errCode = FtMscLibEx.ftxCloseLib()
        FtMscLibEx.ftxGetLibErrorString(errCode, 1, buff, 40)
        Console.WriteLine(" CloseLib" + buff.ToString())

    End Sub

End Module

The connection with the FtMscLibEx.dll

Code: Alles auswählen

'ftMscLibEx.vb
'

Imports System
Imports System.Text
Imports System.Runtime.InteropServices

Public Class FtMscLibEx
    Public Const dllpath As String = "C:\Users\_admin\Documents\Visual Studio 2012\Projects\fischertechnik\VBexample\FtMscLibEx\ftMscLibEx.dll"
    ' Public Const dllpath As String = "C:\Users\_admin\Documents\Visual Studio 2012\Projects\fischertechnik\VBexample\FtMscLibEx\ftMscLib.dll"

    Const VERSTRLEN As Integer = 25


    <DllImport(dllpath, EntryPoint:="ftxGetLibVersionStr")> _
    Public Shared Function GetLibVersionStr(<MarshalAs(UnmanagedType.LPStr)> ByVal Foo2 As StringBuilder, ByVal len As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="GetAvailableComPorts")> _
    Public Shared Function ftxGetAvailableComPorts(ByVal selectMode As Integer) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="EnumComPorts")> _
    Public Shared Function ftxEnumComPorts(ByVal idx As UInteger, <MarshalAs(UnmanagedType.LPStr)> ByVal comstr As StringBuilder, ByVal len As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxOpenComDevice")> _
    Public Shared Function ftxOpenComDevice(ByVal comStr As String, ByVal bdr As UInteger, ByRef uint As UInteger) As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="ftxOpenComDeviceNr")> _
    Public Shared Function ftxOpenComDeviceNr(ByVal comStr As UInteger, ByVal bdr As UInteger, ByRef uint As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxInitLib")> _
    Public Shared Function ftxInitLib() As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="ftxIsLibInit")> _
    Public Shared Function ftxIsLibInit() As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="ftxCloseLib")> _
    Public Shared Function ftxCloseLib() As UInteger
    End Function
     <DllImport(dllpath, EntryPoint:="ftxGetLibErrorString")> _
    Public Shared Function ftxGetLibErrorString(ByVal errCode As UInteger, ByVal typ As UInteger, <MarshalAs(UnmanagedType.LPStr)> ByVal Foo2 As StringBuilder, ByVal maxLen As UInteger) As UInteger
     End Function
    <DllImport(dllpath, EntryPoint:="ftxCloseDevice")>
    Public Shared Function ftxCloseDevice(ByVal fthdl As UInteger) As UInteger
    End Function
    ' [DllImport(dllpath, EntryPoint = "ftxStartTransferArea")]
    ' public static extern uint StartTransferArea(uint fthdl); 

    ' [DllImport(dllpath, EntryPoint = "ftxStopTransferArea")]
    ' public static extern uint StopTransferArea(uint fthdl);

    ' [DllImport(dllpath, EntryPoint = "SetOutMotorValues")]
    ' public static extern uint SetMotorValues(uint fthdl, int shmId, int id, int duty_p, int duty_m, bool brake);

    ' [DllImport(dllpath, EntryPoint = "SetFtMotorConfig")]
    ' public static extern uint SetMotorConfig(uint fthdl, int shmId, int id, bool status);

    ' [DllImport(dllpath, EntryPoint = "SetFtUniConfig")]
    ' public static extern uint SetUniConfig(uint fthdl, int shmId, int id, int mode, bool status);

    ' [DllImport(dllpath, EntryPoint = "SetOutCounterReset")]
    ' public static extern uint SetCntReset(uint fthdl, int shmId, int id);

    ' [DllImport(dllpath, EntryPoint = "GetInCounterValue")]
    ' public static extern unsafe uint GetInCntValue(uint fthdl, int shmId, int idx, ref ushort count, ref ushort val);

    ' [DllImport(dllpath, EntryPoint = "GetInIOValue")]
    ' public static extern unsafe uint GetUniInValue(uint fthdl, int shmId, int idx, ref short val, ref bool overrun);

    ' [DllImport(dllpath, EntryPoint = "GetInDisplayButtonValue")]
    ' public static extern unsafe uint GetDisplayButton(uint fthdl, int shmId, ref ushort left, ref ushort right);

    ' [DllImport(dllpath, EntryPoint = "SetRoboTxMessage")]
    ' public static extern uint SetRoboTxMessage(uint fthdl, int shmId, string msg);

    '[DllImport(dllpath, EntryPoint = "GetRoboTxSlaveAlive")]
    ' public static extern unsafe uint IsIFSlaveAlive(uint fthdl, int id, ref bool alive);

    ' [DllImport(dllpath, EntryPoint = "GetRoboTxSlaveState")]
    ' public static extern unsafe uint IFSlaveState(uint fthdl, byte[] alive);

End Class


Andy42
Beiträge: 20
Registriert: 05 Apr 2014, 18:42

Re: RoboTXController und VisualBasicExpress2010

Beitrag von Andy42 » 15 Apr 2014, 21:41

Hi Carel,

thank you so far, with your code and ideas I have done some tests. So I can report the following:

1) I checked the situation with the code (version 14.04.2014, in forum) with cabel usb connection, in the past I always tried with BlueTooth (BT). But the error message is still the same, a connection indication on the Robos hardware display did not appeared like it did in nearly all cases with BT.

2) Before checking a new version of code I tested the connection with RoboPro Software or RoboTXTest to be sure to use a working com-connection. So I do not believe that I use a wrong com-Channel.

3) I think, the library "ftMscLibEx.dll" uses itself "ftMscLib.dll", I think it was written somewhere. But using the program "cff explorer 2012" to have a look into the dll, "ftMscLib.dll" is not in the import list. That is strange.

4) My "ftMscLibEx.dll" is version 25.08.2013, 00.49.18

5) the error message is like this, it appers by calling the function ftxInitLib(), which never was a problem before:
System.DllNotFoundException wurde nicht behandelt.
Message=Die DLL "C:\windows\system32\ftMscLibEx.dll": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.

The thing is, that the library "ftMscLibEx.dll" is defenitely in the folder "C:\windows\system32". I had the same effect by calling umfish50.dll, which clearly uses "ftMscLib.dll" as internal reference.

6) My VB 2010 Express uses .net framework 4. RoboTXController runs under v 1.30. Computer System is WinXP home SP3.

7) So in total we have got a better results with classical "ftMscLib.dll" than "ftMscLibEx.dll". So I would prefer "ftMscLib.dll". By calling the function

fthdl = FtMscLibEx.OpenComDevice("COM5", 38400, errCode2)

the problem seems to be the reference variable errCode2. The function tries to sent the result after running from unmanaged code to managed code.

always nice to hear from u
Andy

vleeuwen
Beiträge: 1585
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von vleeuwen » 15 Apr 2014, 23:20

Hi Andy
Strange that you have a different result than I have.
I sent you an e-mail for some details.

The FtMscLibEx is a with MS-Visual Studio 2012 recompiled version of the FtMscLib.

Did you try MS-VS2012 Express edition?

vleeuwen
Beiträge: 1585
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von vleeuwen » 17 Apr 2014, 09:35

I tested my example with VB.NET in VS2010.
It is working.

I only switch off the DEBUG exception: pInvokeStackImbalance MDA.
This exception was raised unprodictable.
The calling convention is fine and I could not discover a problem with the parameters.

vleeuwen
Beiträge: 1585
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von vleeuwen » 17 Apr 2014, 17:27

My apologies for the weak start of this VB.NET thread.
Even for a Software Engineer C# is VB in the beginning not evident.

Improved version of the connection class with the FtMscLib.
This resolves the pInvokeStackImbalance MDA event.

Code: Alles auswählen


Imports System
Imports System.Text
Imports System.Runtime.InteropServices


Public Class FtMscLibEx
     ' Fill in yourself
    Public Const dllpath As String = "C:\Users\_admin\Documents\Visual Studio 2010\Projects\fischertechnik\VBexample\FtMscLibEx\ftMscLibEx.dll"
    ' Fill in yourself

    Const VERSTRLEN As Integer = 25


    <DllImport(dllpath, EntryPoint:="ftxGetLibVersionStr", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function GetLibVersionStr(<MarshalAs(UnmanagedType.LPStr)> ByVal Foo2 As StringBuilder, ByVal len As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="GetAvailableComPorts", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxGetAvailableComPorts(ByVal selectMode As Integer) As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="EnumComPorts", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxEnumComPorts(ByVal idx As UInteger,
                                           <MarshalAs(UnmanagedType.LPStr)> ByVal comstr As StringBuilder,
                                           ByVal len As UInteger) As UInteger
    End Function


    <DllImport(dllpath, EntryPoint:="ftxOpenComDevice", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxOpenComDevice(ByVal comStr As String, ByVal bdr As UInteger, ByRef uint As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxOpenComDeviceNr", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxOpenComDeviceNr(ByVal comStr As UInteger, ByVal bdr As UInteger, ByRef uint As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxInitLib", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxInitLib() As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxIsLibInit", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxIsLibInit() As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="ftxIsHandleValid", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxIsHandleValid(ByVal fthdl As UInteger) As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="GetComStatus", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function GetComStatus(ByVal fthdl As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxCloseLib", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxCloseLib() As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxGetLibErrorString", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxGetLibErrorString(ByVal errCode As UInteger,
                                                 ByVal typ As UInteger,
                                                <MarshalAs(UnmanagedType.LPStr)> ByVal buff As StringBuilder,
                                                ByVal maxLen As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxCloseDevice", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxCloseDevice(ByVal fthdl As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxStartTransferArea", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function StartTransferArea(ByVal fthdl As UInteger) As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="ftxStopTransferArea", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function StopTransferArea(ByVal fthdl As UInteger) As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="SetOutMotorValues", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function SetMotorValues(ByVal fthdl As UInteger, ByVal shmId As Integer, ByVal id As Integer,
                                           ByVal duty_p As Integer, ByVal duty_m As Integer,
                                              ByVal brake As Boolean) As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="SetFtMotorConfig", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function SetMotorConfig(ByVal fthdl As UInteger, ByVal shmId As Integer, ByVal id As Integer,
                                          ByVal status As Boolean) As UInteger
    End Function
    <DllImport(dllpath, EntryPoint:="SetFtUniConfig", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function SetUniConfig(ByVal fthdl As UInteger, ByVal shmId As Integer, ByVal id As Integer,
                                        ByVal mode As Integer, ByVal status As Boolean) As UInteger
    End Function
    ' [DllImport(dllpath, EntryPoint = "SetOutCounterReset")]
    ' public static extern uint SetCntReset(uint fthdl, int shmId, int id);

    ' [DllImport(dllpath, EntryPoint = "GetInCounterValue")]
    ' public static extern unsafe uint GetInCntValue(uint fthdl, int shmId, int idx, ref ushort count, ref ushort val);

    ' [DllImport(dllpath, EntryPoint = "GetInIOValue")]
    ' public static extern unsafe uint GetUniInValue(uint fthdl, int shmId, int idx, ref short val, ref bool overrun);

    ' [DllImport(dllpath, EntryPoint = "GetInDisplayButtonValue")]
    ' public static extern unsafe uint GetDisplayButton(uint fthdl, int shmId, ref ushort left, ref ushort right);

    ' [DllImport(dllpath, EntryPoint = "SetRoboTxMessage")]
    ' public static extern uint SetRoboTxMessage(uint fthdl, int shmId, string msg);

    '[DllImport(dllpath, EntryPoint = "GetRoboTxSlaveAlive")]
    ' public static extern unsafe uint IsIFSlaveAlive(uint fthdl, int id, ref bool alive);

    ' [DllImport(dllpath, EntryPoint = "GetRoboTxSlaveState")]
    ' public static extern unsafe uint IFSlaveState(uint fthdl, byte[] alive);
    Public Const FTLIB_ERR_SUCCESS As UInteger = &H0UI
    Public Const FTLIB_ERR_NO_MEMORY As UInteger = &HE0000100UI

    Public Const FTLIB_ERR_FAILED As UInteger = &HE0001000UI 'errorL
    Public Const FTLIB_ERR_TIMEOUT As UInteger = &HE000100CUI 'errorL
    Public Const FTLIB_ERR_INVALID_PARAM As UInteger = &HE0001018UI 'errorL

    Public Const FTLIB_ERR_SOME_DEVICES_ARE_OPEN As UInteger = &HE0001101UI 'errorL
    Public Const FTLIB_ERR_DEVICE_IS_OPEN As UInteger = &HE0001102UI 'errorL
    Public Const FTLIB_ERR_DEVICE_NOT_OPEN As UInteger = &HE0001103UI 'errorL
    Public Const FTLIB_ERR_NO_SUCH_DEVICE_INSTANCE As UInteger = &HE0001104UI 'errorL

    Public Const FTLIB_ERR_UNKNOWN_DEVICE_HANDLE As UInteger = &HE0001283UI 'errorL
    Public Const FTLIB_ERR_LIB_IS_INITIALIZED As UInteger = &HE0001286UI 'errorL
    Public Const FTLIB_ERR_LIB_IS_NOT_INITIALIZED As UInteger = &HE0001287UI 'error
    Public Const FTLIB_ERR_THREAD_NOT_STARTABLE As UInteger = &HE00012A0UI 'errorL
    Public Const FTLIB_ERR_THREAD_IS_RUNNING As UInteger = &HE00012A5UI 'error
    Public Const FTLIB_ERR_THREAD_NOT_RUNNING As UInteger = &HE00012A6UI 'errorL
    Public Const FTLIB_ERR_THREAD_SYNCHRONIZED As UInteger = &HE00012AFUI 'errorL

    Const FTLIB_ERR_TIMEOUT_TA As UInteger = &HE00012B0UI 'errorL
    Const FTLIB_ERR_CREATE_EVENT As UInteger = &HE00012B1UI 'errorL
    Const FTLIB_ERR_CREATE_MM_TIMER As UInteger = &HE00012B2UI 'errorL

    Const FTLIB_ERR_UPLOAD_FILE_NOT_OPEN As UInteger = &HE0001400UI 'errorL
    Const FTLIB_ERR_UPLOAD_FILE_READ_ERR As UInteger = &HE0001401UI 'errorL
    Const FTLIB_ERR_UPLOAD_INVALID_FSIZE As UInteger = &HE0001402UI 'errorL
    Const FTLIB_ERR_UPLOAD_START As UInteger = &HE0001403UI 'errorL
    Const FTLIB_ERR_UPLOAD_CANCELED As UInteger = &HE0001404UI 'errorL
    Const FTLIB_ERR_UPLOAD_FAILED As UInteger = &HE0001405UI 'errorL
    Const FTLIB_ERR_UPLOAD_TIMEOUT As UInteger = &HE0001406UI 'error
    Const FTLIB_ERR_UPLOAD_ACK As UInteger = &HE0001407UI 'errorL
    Const FTLIB_ERR_UPLOAD_NAK As UInteger = &HE0001408UI 'errorL
    Const FTLIB_ERR_UPLOAD_DONE As UInteger = &HE0001409UI 'errorL
    Const FTLIB_ERR_UPLOAD_FLASHWRITE As UInteger = &HE000140AUI 'errorL
    Const FTLIB_ERR_REM_CMD_FAILED As UInteger = &HE000140BUI 'errorL
    Const FTLIB_ERR_REM_CMD_NOT_SUPPORTED As UInteger = &HE000140CUI 'errorL
    Const FTLIB_ERR_FWUPD_GET_FILES As UInteger = &HE000140DUI 'errorL
    Const FTLIB_ERR_FWUPD_NO_FILES As UInteger = &HE000140EUI 'errorL

    Const FTLIB_ERR_ACCESS_DENIED As UInteger = &HE0001905UI 'errorL
    Const FTLIB_ERR_OPEN_COM As UInteger = &HE0001906UI 'errorL
    Const FTLIB_ERR_INIT_COM As UInteger = &HE0001908UI 'errorL
    Const FTLIB_ERR_INIT_COM_TIMEOUT As UInteger = &HE0001909UI 'errorL

    Const FTLIB_ERR_WRONG_HOSTNAME_LEN As UInteger = &HE0002000UI 'errorL

    Const FTLIB_FWUPD_UPLOAD_START As UInteger = &HE0003000UI 'errorL
    Const FTLIB_FWUPD_UPLOAD_DONE As UInteger = &HE0003001UI 'errorL
    Const FTLIB_FWUPD_TIMEOUT As UInteger = &HE0003002UI 'errorL
    Const FTLIB_FWUPD_FLUSH_DISK As UInteger = &HE0003003UI 'errorL
    Const FTLIB_FWUPD_CLEAN_DISK As UInteger = &HE0003004UI 'errorL
    Const FTLIB_FWUPD_ERR_FILE_READ As UInteger = &HE0003005UI 'error
    Const FTLIB_FWUPD_UPLOAD_FAILED As UInteger = &HE0003006UI 'errorL
    Const FTLIB_FWUPD_STARTING As UInteger = &HE0003007UI 'errorL
    Const FTLIB_FWUPD_FINISHED As UInteger = &HE0003008UI 'errorL
    Const FTLIB_FWUPD_REM_COMMAND As UInteger = &HE0003009UI 'errorL
    Const FTLIB_FWUPD_REM_TIMEOUT As UInteger = &HE000300AUI 'errorL
    Const FTLIB_FWUPD_REM_FAILED As UInteger = &HE000300BUI 'errorL
    Const FTLIB_FWUPD_IZ_STEPS As UInteger = &HE000300CUI 'errorL
    Const FTLIB_FWUPD_STEP As UInteger = &HE000300DUI 'errorL

    Const FTLIB_BT_INVALID_CONIDX As UInteger = &HE0004000UI 'errorL
    Const FTLIB_BT_CON_NOT_EXISTS As UInteger = &HE0004001UI 'errorL
    Const FTLIB_BT_CON_ACTIVE As UInteger = &HE0004002UI 'errorL
    Const FTLIB_BT_CON_INACTIVE As UInteger = &HE0004003UI 'errorL
    Const FTLIB_BT_CON_WRONG_ADDR As UInteger = &HE0004004UI 'error
    Const FTLIB_BT_CON_WAIT_BUSY As UInteger = &HE0004005UI 'error

    Const FTLIB_I2C_INVALID_DEV_ADDR As UInteger = &HE0005000UI 'error
    Const FTLIB_I2C_INVALID_FLAGS_ADDRMODE As UInteger = &HE0005001UI 'error
    Const FTLIB_I2C_INVALID_FLAGS_DATAMODE As UInteger = &HE0005002UI 'error
    Const FTLIB_I2C_INVALID_FLAGS_ERRMODE As UInteger = &HE0005003UI 'error

    Const FTLIB_ERR_UNKNOWN As UInteger = &HEFFFFFFFUI 'error
End Class


Andy42
Beiträge: 20
Registriert: 05 Apr 2014, 18:42

Re: RoboTXController und VisualBasicExpress2010

Beitrag von Andy42 » 21 Apr 2014, 09:28

Many thanks to vleeuwen for the code from 17.04.2014, this was an extremly good job! I did some tests with it.



1) There is only one observation left:

Connection only works with "ftMscLib.dll", with "ftMscLibEx.dll" there is an error message:

System.DllNotFoundException wurde nicht behandelt.
Message=Die DLL "C:\windows\system32\ftMscLibEx.dll": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.

This behavior is still very strange, because the file "ftMscLibEx.dll" is stored under the given path. Even the line

Debug.Print(If(System.IO.File.Exists(FtMscLibEx.dllpath), "File exists.", "File does not exist."))

has the result: "File exists."



2) The rest works very well with the following extendet code on the basis of vleeuwens work (Microsoft Visual Basic 2010 Express)

a) class classFtMscLib

Code: Alles auswählen


Imports System
Imports System.Text
Imports System.Runtime.InteropServices

Public Class classFtMscLib

    '*** List of var

    Public Const dllpath As String = "C:\windows\system32\ftMscLib.dll"


    '*** List of declarations

    <DllImport(dllpath, EntryPoint:="ftxGetLibVersionStr", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxGetLibVersionStr(<MarshalAs(UnmanagedType.LPStr)> ByVal Foo2 As StringBuilder, ByVal len As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxGetLibVersion", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxGetLibVersion() As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxIsTransferActiv", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxIsTransferActiv(ByVal fthdl As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="GetAvailableComPorts", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxGetAvailableComPorts(ByVal selectMode As Integer) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="EnumComPorts", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxEnumComPorts(ByVal idx As UInteger, <MarshalAs(UnmanagedType.LPStr)> ByVal comstr As StringBuilder, ByVal len As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxOpenComDevice", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxOpenComDevice(ByVal comStr As String, ByVal bdr As UInteger, ByRef uint As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxOpenComDeviceNr", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxOpenComDeviceNr(ByVal comStr As UInteger, ByVal bdr As UInteger, ByRef uint As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxInitLib", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxInitLib() As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxIsLibInit", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxIsLibInit() As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxIsHandleValid", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxIsHandleValid(ByVal fthdl As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="GetComStatus", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxGetComStatus(ByVal fthdl As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxCloseLib", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxCloseLib() As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxGetLibErrorString", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxGetLibErrorString(ByVal errCode As UInteger, ByVal typ As UInteger, <MarshalAs(UnmanagedType.LPStr)> ByVal buff As StringBuilder, ByVal maxLen As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxCloseDevice", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxCloseDevice(ByVal fthdl As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxStartTransferArea", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxStartTransferArea(ByVal fthdl As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="ftxStopTransferArea", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxStopTransferArea(ByVal fthdl As UInteger) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="SetOutMotorValues", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxSetOutMotorValues(ByVal fthdl As UInteger, ByVal shmId As Integer, ByVal id As Integer, ByVal duty_p As Integer, ByVal duty_m As Integer, ByVal brake As Boolean) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="SetFtMotorConfig", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function ftxSetOutMotorConfig(ByVal fthdl As UInteger, ByVal shmId As Integer, ByVal id As Integer, ByVal status As Boolean) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="SetFtUniConfig", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function ftxSetUniConfig(ByVal fthdl As UInteger, ByVal shmId As Integer, ByVal id As Integer, ByVal mode As Integer, ByVal status As Boolean) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="GetInIOValue", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function ftxGetInIOValue(ByVal fthdl As UInteger, ByVal shmId As Integer, ByVal idx As Integer, ByRef valRef As Short, ByRef overrunRef As Boolean) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="StartCounterReset", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function ftxStartCounterReset(ByVal fthdl As UInteger, ByVal shmId As Integer, ByVal idx As Integer) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="GetInCounterValue", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function ftxGetInCounterValue(ByVal fthdl As UInteger, ByVal shmId As Integer, ByVal idx As Integer, ByRef contRef As UShort, ByRef valRef As UShort) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="GetInDisplayButtonValue", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function ftxGetInDisplayButtonValue(ByVal fthdl As UInteger, ByVal shmId As Integer, ByRef leftRef As UShort, ByRef rightRef As UShort) As UInteger
    End Function

    <DllImport(dllpath, EntryPoint:="SetRoboTxMessage", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function ftxSetRoboTxMessage(ByVal fthdl As UInteger, ByVal shmId As Integer, ByVal msg As String) As UInteger
    End Function


    '*** List of error codes

    Public Const FTLIB_ERR_SUCCESS As UInteger = &H0UI                                  'decErr 0
    Public Const FTLIB_ERR_NO_MEMORY As UInteger = &HE0000100UI                         '              

    Public Const FTLIB_ERR_FAILED As UInteger = &HE0001000UI                            '
    Public Const FTLIB_ERR_TIMEOUT As UInteger = &HE000100CUI                           '
    Public Const FTLIB_ERR_INVALID_PARAM As UInteger = &HE0001018UI                     '

    Public Const FTLIB_ERR_SOME_DEVICES_ARE_OPEN As UInteger = &HE0001101UI             '
    Public Const FTLIB_ERR_DEVICE_IS_OPEN As UInteger = &HE0001102UI                    '
    Public Const FTLIB_ERR_DEVICE_NOT_OPEN As UInteger = &HE0001103UI                   '
    Public Const FTLIB_ERR_NO_SUCH_DEVICE_INSTANCE As UInteger = &HE0001104UI           '

    Public Const FTLIB_ERR_UNKNOWN_DEVICE_HANDLE As UInteger = &HE0001283UI             '
    Public Const FTLIB_ERR_LIB_IS_INITIALIZED As UInteger = &HE0001286UI                '
    Public Const FTLIB_ERR_LIB_IS_NOT_INITIALIZED As UInteger = &HE0001287UI            '
    Public Const FTLIB_ERR_THREAD_NOT_STARTABLE As UInteger = &HE00012A0UI              '
    Public Const FTLIB_ERR_THREAD_IS_RUNNING As UInteger = &HE00012A5UI                 '
    Public Const FTLIB_ERR_THREAD_NOT_RUNNING As UInteger = &HE00012A6UI                '
    Public Const FTLIB_ERR_THREAD_SYNCHRONIZED As UInteger = &HE00012AFUI               '

    Public Const FTLIB_ERR_TIMEOUT_TA As UInteger = &HE00012B0UI                        '
    Public Const FTLIB_ERR_CREATE_EVENT As UInteger = &HE00012B1UI                      '
    Public Const FTLIB_ERR_CREATE_MM_TIMER As UInteger = &HE00012B2UI                   '

    Public Const FTLIB_ERR_UPLOAD_FILE_NOT_OPEN As UInteger = &HE0001400UI              '
    Public Const FTLIB_ERR_UPLOAD_FILE_READ_ERR As UInteger = &HE0001401UI              '
    Public Const FTLIB_ERR_UPLOAD_INVALID_FSIZE As UInteger = &HE0001402UI              '
    Public Const FTLIB_ERR_UPLOAD_START As UInteger = &HE0001403UI                      '
    Public Const FTLIB_ERR_UPLOAD_CANCELED As UInteger = &HE0001404UI                   '
    Public Const FTLIB_ERR_UPLOAD_FAILED As UInteger = &HE0001405UI                     '
    Public Const FTLIB_ERR_UPLOAD_TIMEOUT As UInteger = &HE0001406UI                    '
    Public Const FTLIB_ERR_UPLOAD_ACK As UInteger = &HE0001407UI                        '
    Public Const FTLIB_ERR_UPLOAD_NAK As UInteger = &HE0001408UI                        '
    Public Const FTLIB_ERR_UPLOAD_DONE As UInteger = &HE0001409UI                       '
    Public Const FTLIB_ERR_UPLOAD_FLASHWRITE As UInteger = &HE000140AUI                 '
    Public Const FTLIB_ERR_REM_CMD_FAILED As UInteger = &HE000140BUI                    '
    Public Const FTLIB_ERR_REM_CMD_NOT_SUPPORTED As UInteger = &HE000140CUI             '
    Public Const FTLIB_ERR_FWUPD_GET_FILES As UInteger = &HE000140DUI                   '
    Public Const FTLIB_ERR_FWUPD_NO_FILES As UInteger = &HE000140EUI                    '

    Public Const FTLIB_ERR_ACCESS_DENIED As UInteger = &HE0001905UI                     '
    Public Const FTLIB_ERR_OPEN_COM As UInteger = &HE0001906UI                          '
    Public Const FTLIB_ERR_INIT_COM As UInteger = &HE0001908UI                          '
    Public Const FTLIB_ERR_INIT_COM_TIMEOUT As UInteger = &HE0001909UI                  '

    Public Const FTLIB_ERR_WRONG_HOSTNAME_LEN As UInteger = &HE0002000UI                '

    Public Const FTLIB_FWUPD_UPLOAD_START As UInteger = &HE0003000UI                    '
    Public Const FTLIB_FWUPD_UPLOAD_DONE As UInteger = &HE0003001UI                     '
    Public Const FTLIB_FWUPD_TIMEOUT As UInteger = &HE0003002UI                         '
    Public Const FTLIB_FWUPD_FLUSH_DISK As UInteger = &HE0003003UI                      '
    Public Const FTLIB_FWUPD_CLEAN_DISK As UInteger = &HE0003004UI                      '
    Public Const FTLIB_FWUPD_ERR_FILE_READ As UInteger = &HE0003005UI                   '
    Public Const FTLIB_FWUPD_UPLOAD_FAILED As UInteger = &HE0003006UI                   '
    Public Const FTLIB_FWUPD_STARTING As UInteger = &HE0003007UI                        '
    Public Const FTLIB_FWUPD_FINISHED As UInteger = &HE0003008UI                        '
    Public Const FTLIB_FWUPD_REM_COMMAND As UInteger = &HE0003009UI                     '
    Public Const FTLIB_FWUPD_REM_TIMEOUT As UInteger = &HE000300AUI                     '
    Public Const FTLIB_FWUPD_REM_FAILED As UInteger = &HE000300BUI                      '
    Public Const FTLIB_FWUPD_IZ_STEPS As UInteger = &HE000300CUI                        '
    Public Const FTLIB_FWUPD_STEP As UInteger = &HE000300DUI                            '

    Public Const FTLIB_BT_INVALID_CONIDX As UInteger = &HE0004000UI                     '
    Public Const FTLIB_BT_CON_NOT_EXISTS As UInteger = &HE0004001UI                     '
    Public Const FTLIB_BT_CON_ACTIVE As UInteger = &HE0004002UI                         '
    Public Const FTLIB_BT_CON_INACTIVE As UInteger = &HE0004003UI                       '
    Public Const FTLIB_BT_CON_WRONG_ADDR As UInteger = &HE0004004UI                     '
    Public Const FTLIB_BT_CON_WAIT_BUSY As UInteger = &HE0004005UI                      '

    Public Const FTLIB_I2C_INVALID_DEV_ADDR As UInteger = &HE0005000UI                  '
    Public Const FTLIB_I2C_INVALID_FLAGS_ADDRMODE As UInteger = &HE0005001UI            '
    Public Const FTLIB_I2C_INVALID_FLAGS_DATAMODE As UInteger = &HE0005002UI            '
    Public Const FTLIB_I2C_INVALID_FLAGS_ERRMODE As UInteger = &HE0005003UI             '

    Public Const FTLIB_ERR_UNKNOWN As UInteger = &HEFFFFFFFUI                           '

End Class

b) additional function

Code: Alles auswählen


Module modVersionCalc

    Public Function VersionEncode(ByVal VersionCode As Long) As String

        On Error Resume Next

        Dim VersionString As String
        Dim VersionStringLen As Integer
        Dim VersionStringMain As String
        Dim VersionStringRel As String
        Dim VersionStringSub As String

        'converts integer format to binary
        VersionString = System.Convert.ToString(VersionCode, 2)

        VersionStringLen = Len(VersionString)

        'encoding sub version
        If VersionStringLen >= 8 Then
            VersionStringSub = Right(VersionString, 8)
        Else
            VersionStringSub = "x"
        End If
        'Debug.Print(VersionStringSub)
        VersionString = Left(VersionString, VersionStringLen - 8)
        VersionStringLen = Len(VersionString)

        'encoding release version
        If VersionStringLen >= 8 Then
            VersionStringRel = Right(VersionString, 8)
        Else
            VersionStringRel = "x"
        End If
        'Debug.Print(VersionStringRel)
        VersionString = Left(VersionString, VersionStringLen - 8)

        'encoding main version
        VersionStringMain = Right(VersionString, 8)
        'Debug.Print(VersionStringMain)

        VersionEncode = System.Convert.ToUInt32(VersionStringMain, 2) & "." & System.Convert.ToUInt32(VersionStringRel, 2) & "." & System.Convert.ToUInt32(VersionStringSub, 2)

    End Function

End Module

c) main programm
In the main programm some functions of the library "ftMscLib.dll" are explained with a code examples. The most of it happens in the direct diolog box in the development invirenment of visual basic, with message boxes are for user dialogs.

Code: Alles auswählen


Module modMain

    Sub Main()

        Dim errCode As UInteger
        Dim errCode2 As UInteger

        Dim allPorts As UInteger
        Dim r As UInteger
        Dim buff As System.Text.StringBuilder = New System.Text.StringBuilder(45)
        Dim buff2 As System.Text.StringBuilder = New System.Text.StringBuilder(45)

        Dim valRef As Short
        Dim overrunRef As Boolean

        Dim rightRef As Short
        Dim leftRef As Short

        Dim countRef As UShort
        Dim valRef2 As UShort

        'Check if dll of the class is really available under the given path
        Debug.Print(If(System.IO.File.Exists(classFtMscLib.dllpath), "File exists.", "File does not exist."))

        'step 1: initialisation of library
        Debug.Print("")
        Debug.Print("step 1")
        errCode = classFtMscLib.ftxInitLib()
        Debug.Print("ftxInitLib(), errCode=" & errCode)

        'step 2: check initialisation of library
        Debug.Print("")
        Debug.Print("step 2")
        errCode = classFtMscLib.ftxIsLibInit()
        Debug.Print("ftxIsLibInit(), errCode=" & errCode)
        If errCode = classFtMscLib.FTLIB_ERR_LIB_IS_INITIALIZED Then
            Debug.Print("   FTLIB_ERR_LIB_IS_INITIALIZED")
        End If

        'step 3: look up existing com ports
        Debug.Print("")
        Debug.Print("step 3")
        Debug.Print("number of all ports=" & classFtMscLib.ftxGetAvailableComPorts(0))
        Debug.Print("number of usb ports=" & classFtMscLib.ftxGetAvailableComPorts(1))
        Debug.Print("number ob bt ports=" & classFtMscLib.ftxGetAvailableComPorts(2))

        'step 4: list all existing ports
        Debug.Print("")
        Debug.Print("step 4")
        allPorts = classFtMscLib.ftxGetAvailableComPorts(0)
        For tel As UInteger = 0 To allPorts - 1
            r = classFtMscLib.ftxIsLibInit()
            buff2 = New System.Text.StringBuilder(100)
            buff = New System.Text.StringBuilder(100)
            r = classFtMscLib.ftxEnumComPorts(tel, buff2, 100)
            If (r < 100) Then
                Debug.Print(" found " + buff2.ToString())
            Else
                classFtMscLib.ftxGetLibErrorString(r, 1, buff, 40)
                Debug.Print(buff.ToString())
            End If

        Next

        'step 5: direct command window
        Debug.Print("")
        Debug.Print("step 5")
        MsgBox("wait & check: look at direct command window")

        'step 6: activate connection to RoboTX controller
        Debug.Print("")
        Debug.Print("step 6")
        fthdl = classFtMscLib.ftxOpenComDevice("COM7", 38400, errCode2)     'way of working 1
        'fthdl = classFtMscLib.ftxOpenComDeviceNr(7, 38400, errCode2)       'way of working 2 (alternatively)
        Debug.Print("ftxOpenComDevice('COM7', 38400, errCode2), errCode2=" & errCode2)

        'step 7: connection OK?
        Debug.Print("")
        Debug.Print("step 7")
        MsgBox("wait & check: connection OK?")

        'step 8: activate transfer area for command and data exchenge between RoboRX controller and PC
        Debug.Print("")
        Debug.Print("step 8")
        errCode = classFtMscLib.ftxStartTransferArea(fthdl)
        Debug.Print("ftxStartTransferArea(fthdl), errCode=" & errCode)

        'step 9: test of transfer area
        Debug.Print("")
        Debug.Print("step 9")
        errCode = classFtMscLib.ftxIsTransferActiv(fthdl)
        Debug.Print("ftxIsTransferActiv(fthdl), errCode=" & errCode)
        If errCode = classFtMscLib.FTLIB_ERR_THREAD_IS_RUNNING Then
            Debug.Print("   FTLIB_ERR_THREAD_IS_RUNNING")
        End If

        'step 10: from step before, show acitive error code as human interface reply
        Debug.Print("")
        Debug.Print("step 10")
        buff = New System.Text.StringBuilder(100)
        Debug.Print(classFtMscLib.ftxGetLibErrorString(errCode, 1, buff, 40))
        Debug.Print(errCode & " = " & buff.ToString())

        'step 11: read master RoboTXController (0), inpitID (1)
        Debug.Print("")
        Debug.Print("step 11")
        Debug.Print(classFtMscLib.ftxGetInIOValue(fthdl, 0, 1, valRef, overrunRef))
        Debug.Print("  valRef=" & valRef)
        Debug.Print("  overrunRef=" & overrunRef)

        'step 12: connection still active?
        Debug.Print("")
        Debug.Print("step 12")
        MsgBox("wait & check: connection still active?")

        'step 13: read library version as integer output
        Debug.Print("")
        Debug.Print("step 13")
        Debug.Print("ftxGetLibVersion()=" & classFtMscLib.ftxGetLibVersion() & " = " & VersionEncode(classFtMscLib.ftxGetLibVersion()))

        'step 14: read library version as string output
        Debug.Print("")
        Debug.Print("step 14")
        buff2 = New System.Text.StringBuilder(100)
        Debug.Print("ftxGetLibVersionStr(), string length=" & classFtMscLib.ftxGetLibVersionStr(buff2, 100))
        Debug.Print("ftxGetLibVersionStr(), string content=" & buff2.ToString)

        'step 15: check if RoboTxController handle ist still active
        Debug.Print("")
        Debug.Print("step 15")
        errCode = classFtMscLib.ftxIsHandleValid(fthdl)
        buff = New System.Text.StringBuilder(100)
        Debug.Print(classFtMscLib.ftxGetLibErrorString(errCode, 1, buff, 40))
        Debug.Print("handle still active = " & buff.ToString())

        'step 16: check communication status to RoboTxController
        Debug.Print("")
        Debug.Print("step 16")
        errCode = classFtMscLib.ftxGetComStatus(fthdl)
        buff = New System.Text.StringBuilder(100)
        Debug.Print(classFtMscLib.ftxGetLibErrorString(errCode, 1, buff, 40))
        Debug.Print("communication status = " & buff.ToString())

        'step 17: wait & check: press red RoboTXController button
        Debug.Print("")
        Debug.Print("step 17")
        MsgBox("wait & check: press and hold one button on the RoboTXController and quit this diolog box")

        'step 18: from step before, check which button was pressed from RoboTXController (0)
        Debug.Print("")
        Debug.Print("step 18")
        errCode = classFtMscLib.ftxGetInDisplayButtonValue(fthdl, 0, leftRef, rightRef)
        Debug.Print("leftRef button press time=" & leftRef)
        Debug.Print("rightRef button press time=" & rightRef)

        'step 19: reset from RoboTXController (0) counter c1 (0)
        Debug.Print("")
        Debug.Print("step 19")
        errCode = classFtMscLib.ftxStartCounterReset(fthdl, 0, 0)
        buff = New System.Text.StringBuilder(100)
        Debug.Print(classFtMscLib.ftxGetLibErrorString(errCode, 1, buff, 40))
        Debug.Print("reset of counter c1 = " & buff.ToString())

        'step 20: wait & check: set some signal pulses on counter c1 of RoboTXController
        Debug.Print("")
        Debug.Print("step 20")
        MsgBox("wait & check: set some signal pulses on counter c1 of RoboTXController and quit this diolog box")

        'step 21: from step before, check how many event there were on counter c1 (0) of RoboTXController (0)
        Debug.Print("")
        Debug.Print("step 21")
        Debug.Print(classFtMscLib.ftxGetInCounterValue(fthdl, 0, 0, countRef, valRef2))
        Debug.Print("contRef=" & countRef)
        Debug.Print("valRef2=" & valRef2)

        'step 22: wait & check: connect a motor to M2 (1) of RoboTXController (0)
        Debug.Print("")
        Debug.Print("step 22")
        MsgBox("wait & check: connect a motor to M2 (1) of RoboTXController (0)")

        'step 23: run motor on M2 turning right
        Debug.Print("")
        Debug.Print("step 23")
        Debug.Print("M2 error=" & classFtMscLib.ftxSetOutMotorConfig(fthdl, 0, 1, True)) 'def out O3 and O4 as motor
        Debug.Print("M2 error=" & classFtMscLib.ftxSetOutMotorValues(fthdl, 0, 1, 512, 0, False)) '512 is full speed

        'step 24: wait & check: is motor on M2 running, turning right?
        Debug.Print("")
        Debug.Print("step 24")
        MsgBox("wait & check: is motor on M2 running, turning right?")

        'step 25: run motor in other direction
        Debug.Print("")
        Debug.Print("step 25")
        Debug.Print("M2 error=" & classFtMscLib.ftxSetOutMotorValues(fthdl, 0, 1, 0, 512, False)) '512 is full speed

        'step 26: wait & check: is motor on M2 running, turning left?
        Debug.Print("")
        Debug.Print("step 26")
        MsgBox("wait & check: is motor on M2 running, turning left?")

        'step 27: stop running motor
        Debug.Print("")
        Debug.Print("step 27")
        Debug.Print("M2 error=" & classFtMscLib.ftxSetOutMotorValues(fthdl, 0, 1, 0, 0, True))

        'step 28: wait & check: disconnect motor an connect 2 lamps to O3 and O4
        Debug.Print("")
        Debug.Print("step 28")
        MsgBox("wait & check: disconnect motor an connect 2 lamps to O3 and O4")

        'step 29: run 2 separate lamps on O3 and O4
        Debug.Print("")
        Debug.Print("step 29")
        Debug.Print("M2 error=" & classFtMscLib.ftxSetOutMotorConfig(fthdl, 0, 1, False)) 'def out O3 and O4 as 2 single outputs
        Debug.Print("M2 error=" & classFtMscLib.ftxSetOutMotorValues(fthdl, 0, 1, 512, 512, False))

        'step 30: wait & check: are both lamps on
        Debug.Print("")
        Debug.Print("step 30")
        MsgBox("wait & check: are both lamps on?")

        'step 31: only O4 lamp is on, and only on 50% brightness (256=50%)
        Debug.Print("")
        Debug.Print("step 31")
        Debug.Print("M2 error=" & classFtMscLib.ftxSetOutMotorValues(fthdl, 0, 1, 0, 256, False))

        'step 32: wait & check: only O4 lamp is on, and only on 50% brightness
        Debug.Print("")
        Debug.Print("step 32")
        MsgBox("wait & check: only O4 lamp is on, and only on 50% brightness?")

        'step 33: set both lamps off
        Debug.Print("")
        Debug.Print("step 33")
        Debug.Print("M2 error=" & classFtMscLib.ftxSetOutMotorValues(fthdl, 0, 1, 0, 0, False))

        'step 34: wait & check: connect a photo resistance to I8
        Debug.Print("")
        Debug.Print("step 34")
        MsgBox("wait & check: connect a photo resistance to I8")

        'step 35: set I8 to analog 5k resistance measurement
        Debug.Print("")
        Debug.Print("step 35")
        Debug.Print("set I8 error = " & classFtMscLib.ftxSetUniConfig(fthdl, 0, 7, 1, False))
        MsgBox("pause")
        Debug.Print("read analog I8 error = " & classFtMscLib.ftxGetInIOValue(fthdl, 0, 7, valRef, overrunRef))
        Debug.Print("valRef=" & valRef)
        Debug.Print("overrunRef=" & overrunRef)

        'step 36: send a message to RoboTXController display
        Debug.Print("")
        Debug.Print("step 36")
        errCode = classFtMscLib.ftxSetRoboTxMessage(fthdl, 0, "Hello World")

        'step 37: wait & check: message on RoboTXController lcd display
        Debug.Print("")
        Debug.Print("step 37")
        MsgBox("wait & check: what is written on the RoboTXController display")

        'step 38: clear RoboTXController display
        Debug.Print("")
        Debug.Print("step 38")
        Debug.Print("clear display error = " & classFtMscLib.ftxSetRoboTxMessage(fthdl, 0, ""))

        'step 39: wait & check: RoboTXController lcd display clear
        Debug.Print("")
        Debug.Print("step 39")
        MsgBox("wait & check: RoboTXController display normal again?")

        'step 40: close transfer area
        Debug.Print("")
        Debug.Print("step 40")
        errCode = classFtMscLib.ftxStopTransferArea(fthdl)
        Debug.Print("ftxStopTransferArea(fthdl), errCode=" & errCode)

        'step 41: cut connection to RoboTX controller
        Debug.Print("")
        Debug.Print("step 41")
        errCode = classFtMscLib.ftxCloseDevice(fthdl)
        Debug.Print("ftxCloseDevice(fthdl), errCode=" & errCode)

        'step 42: close library
        Debug.Print("")
        Debug.Print("step 42")
        errCode = classFtMscLib.ftxCloseLib()
        Debug.Print("ftxCloseLib(), errCode=" & errCode)

        'step 43: program end
        Debug.Print("")
        Debug.Print("step 43")
        Debug.Print("program end")

        'end program
        End

    End Sub

End Module



3) It follows the list of functions of "ftMscLib.dll"

a) Functions explained above

EnumComPorts
GetAvailableComPorts
GetComStatus
GetInCounterValue
GetInDisplayButtonValue
GetInIOValue
SetFtMotorConfig
SetFtUniConfig
SetOutMotorValues
StartCounterReset
ftxCloseDevice
ftxCloseLib
ftxGetLibErrorString
ftxGetLibVersion
ftxGetLibVersionStr
ftxInitLib
ftxIsHandleValid
ftxIsLibInit
ftxIsTransferActiv
ftxOpenComDevice
ftxOpenComDeviceNr
ftxStartTransferArea
ftxStopTransferArea

b) Functions not explained above (so there is some work left :) ... )

SetFtCntConfig
SetOutPwmValues
FtRamFileUpload
FtRemoteCmd
GetRoboTxBtAddr
GetRoboTxBtStatus
GetRoboTxDevName
GetRoboTxDllStr
GetRoboTxFwStr
GetRoboTxFwVal
GetRoboTxHwStr
GetRoboTxInfo
GetRoboTxMasterState
GetRoboTxMemLayout
GetRoboTxSerialStr
GetRoboTxSlaveAlive
GetRoboTxSlaveState
GetSessionId
GetTransferAreaStatusAddr
GetTransferAreasArrayAddr
GetTrapStatistic
RTxCleanDisk
ResetTrapStatistic
RoboTxFwUpdate
SendBtMessage
SetCBCounterResetted
SetCBMotorExReached
SetCBRoboExtState
SetRoboTxDevName
SetRoboTxMessage
StartMotorExCmd
StartScanBtDevice
StatusBtConnection
StopAllMotorExCmd
StopMotorExCmd
ftxCloseAllDevices
ftxI2cRead
ftxI2cWrite
ftxGetLongNameStrg
ftxGetManufacturerStrg
ftxGetSerialNrStrg
ftxGetShortNameStrg



so now the community can start havin' fun with VB and the RoboTXController

Andy42

vleeuwen
Beiträge: 1585
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von vleeuwen » 21 Apr 2014, 15:28

xxxxxxxxxx
Zuletzt geändert von vleeuwen am 23 Mär 2019, 22:19, insgesamt 1-mal geändert.

Andy42
Beiträge: 20
Registriert: 05 Apr 2014, 18:42

Re: RoboTXController und VisualBasicExpress2010

Beitrag von Andy42 » 22 Apr 2014, 20:11

to vleeuwen: under WinXP I have checked the properties of the file "ftMscLibEx.dll". There are only two of them, [write protection] and [hide]. Both items had been not activated.
cu Andy42

Benutzeravatar
steffalk
ft:pedia-Herausgeber
Beiträge: 1809
Registriert: 01 Nov 2010, 16:41
Wohnort: Karlsruhe
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von steffalk » 14 Dez 2014, 17:08

Hello everybody,

is this really a StringBuilder object? Not a String?

Code: Alles auswählen

ftxGetLibVersionStr(<MarshalAs(UnmanagedType.LPStr)> ByVal Foo2 As StringBuilder...
Cannot believe that we have to pass a .net StringBuilder to a native code DLL - or do I miss something here?

Best Regards,
Stefan

Benutzeravatar
steffalk
ft:pedia-Herausgeber
Beiträge: 1809
Registriert: 01 Nov 2010, 16:41
Wohnort: Karlsruhe
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von steffalk » 14 Dez 2014, 21:35

Hello Carel,

Thank you for your prompt response. So do you pre-size the StringBuilder before you call ftxGetLibVersionStr(), and afterwards use StringBuilder.ToString()? And the StringBuilder implementation can be marshalled as LPStr, so that the pointer passed to/from native code actually points to the StringBuilder's buffer? Do you have a link to msdn for this behavior?

Best Regards again,
Stefan

Benutzeravatar
steffalk
ft:pedia-Herausgeber
Beiträge: 1809
Registriert: 01 Nov 2010, 16:41
Wohnort: Karlsruhe
Kontaktdaten:

Re: RoboTXController und VisualBasicExpress2010

Beitrag von steffalk » 14 Dez 2014, 21:44

Hello again,

found it: http://msdn.microsoft.com/de-de/library ... .110).aspx

Interesting. Didn't know (I need p/invoke nearly never ;-) )

Regards!
Stefan

Antworten