Access DIO from Visual Studio 2005 (VB Project)

  • This sample shows how to access DIO from VS2005. A short description and required registry modifications are include.


    For IO configuration you can use the tool "WinNDCUCfg" in the "tools" section under http://www.fs-net.de/download/bin/.

    Files

    • DIO_VBTest.zip

      (34.5 kB, downloaded 492 times, last: )

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello,


    X is labeled as arbitrary in my description that means the user can set these bits to 0 or 1 without affect the basic functionallty of this program sample.


    But this sample is created for NetDCUX (your registry screen shot is from PicoMOD). Of course the funtions for access DIO works on PicoMOD as well as on NetDCUX but the HW is quite different. Please also note, that the pin assigment in the "PicoMOD1_DeviceDriver_eng.pdf" refers to the PicoMOD and not to the PicoMOD Startinterface! So for adjust your registry setting follow:


    Code
    1. J9/Pin3 = GPE0 = J1/Pin35 = Port1/Bit5 = UseAsIOA/Bit13
    2. J9/Pin4 = GPE1 = J1/Pin36 = Port1/Bit6 = UseAsIOA/Bit14
    3. J9/Pin5 = GPE2 = J1/Pin37 = Port1/Bit7 = UseAsIOA/Bit15
    4. J9/Pin6 = GPE3 = J1/Pin38 = Port2/Bit0 = UseAsIOA/Bit16
    5. J9/Pin7 = GPE4 = J1/Pin39 = Port2/Bit1 = UseAsIOA/Bit17
    6. J9/Pin8 = EINT3 = J1/Pin24 = Port1/Bit5 = UseAsIOA/Bit9


    On PicoMOD you can also use I2C IO-chips (e.g. PCA9555) for increase number (and speed) of IOs.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello,
    thereby a sample (includes registry settings) which use the IOs on PicoMOD Starterkit J9.

    Files

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello


    Is it correct, that first, I need the DIGITIO.DLL on my picMod in \FFDISK or \Windows? Because I don't have anything there.


    ' P/Invoke calls to DIGITIO.DLL (digital IO driver) via win32 API (coredll.dll)
    ' CreateFileW()


    Timo

  • Hello,


    by default the dio driver shoud be loaded. You will find the driver in \windows, e.g. using telnet "attrib \windows\*.dll.


    You can also check if the driver is active by:
    - boot out on serial line
    - under registry key: [HKLM]\drivers\active\XX


    Check if the "hPort" value is a valid handel, only then you can access to the driver.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello


    Thank you for your example. With your example, we can OPEN the following Ports as OUTPUT:
    IO_A: 1, 2, 3, 4
    IO_B: 1


    But what we need is
    IO_B: 2 (A=0, B=4)



    What does that mean:
    ' PORT 33221100


    Why, we can not change the "0" Binary to a "1" to make it as OUTPUT:
    ' reg set value UseAsIOA DWORD 0x0003E000
    ' reg set value DataDirA DWORD 0x0003E000 '1111110000000000000 --> 7E000 --> 253952



    ############################################3


    For what is the value bValue:
    Public Class Form1
    Dim DIO As New DIOport
    Dim ValuePort1 As Byte = 0 'tree msb bits from porta1
    Dim ValuePort2 As Byte = 1 'two lsb bits from porta2


    Sub Write(ByVal bValue As Byte)


    DIO.SetPort(1)
    DIO.WriteByte(ValuePort1)
    Label1.Text = ValuePort1.ToString()


    DIO.SetPort(2)
    DIO.WriteByte(ValuePort2)
    Label3.Text = ValuePort2.ToString()


    'ValuePort1 <<= 1
    If ValuePort1 = 0 Then
    ValuePort1 = 64
    End If


    If ValuePort2 = 1 Then
    ValuePort2 = 2
    Else
    ValuePort2 = 1
    End If
    End Sub

  • Quote from "Nase"

    Why, we can not change the "0" Binary to a "1" to make it as OUTPUT:


    It has no effect when you change the registry at runtime. The driver is loaded when the system starts and then reads the registry settings. They can not be changed later anymore. Therefore you have to set the registry to reflect your needs, and then reboot your board. Now the new settings should take effect.


    Regards,


    H. Keller

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Quote from "Nase"

    I know this. But the problem is, that we DONT KNOW, what value is to set in the registry. Because we did't found any document hwo let's us understand, how it works.


    Is it really this difficult? Regarding to the document "NetDCU_DeviceDriver_eng.pdf" available on the CD or here:
    For each pin there is a bit in the UseAsIOBit entry. If you want to use this pin for I/O, set the bit to 1, otherwise leave it as 0. Then, for any of these pins with the 1-bit, set 0 or 1 in DataDirBit, depending on your need for input (0) or output (1). And finally, for all pins with 1-bit for the direction, you have to specify if the port starts with low (0) or high (1) when being initialized. This is set in the entry DataInitBit.


    So where is the problem?


    Regards,


    H. Keller

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • I received a CD from F&S and a PicoMod1. The correct file name on the CD is: "NetDCU_DeviceDriver.pdf". But it is under the folder "NetDCU". and under the folder "German", there is no german description. I program in VB.NET and all examples are in C++. There are more than 15 documents with about 50 pages and every time I have to think, if it is the right document for my PicoMod. Last time we discuss about this and we did't know some settings eighter with Mr. Zutter.


    I'm not a machine.

  • Hello,


    there is only one document for PicoMOD device driver!


    With the PicoMOD sample in this thread you can write to 5 IO pins, j1 is on PicoMOD, j9 is on StartIntf:


    J9/Pin3 = GPE0 = J1/Pin35 = Port1/Bit5 = UseAsIOA/Bit13
    J9/Pin4 = GPE1 = J1/Pin36 = Port1/Bit6 = UseAsIOA/Bit14
    J9/Pin5 = GPE2 = J1/Pin37 = Port1/Bit7 = UseAsIOA/Bit15
    J9/Pin6 = GPE3 = J1/Pin38 = Port2/Bit0 = UseAsIOA/Bit16
    J9/Pin7 = GPE4 = J1/Pin39 = Port2/Bit1 = UseAsIOA/Bit17
    J9/Pin8 = EINT3 = J1/Pin24 = Port1/Bit5 = UseAsIOA/Bit9


    These 5 pins located on different ports, a1 and a2. A0 and a3 are not used also any pin from port b is in use. After CreateFile() you can "jump" from porta1 to porta0 use SetPort().
    The code documentation says:

    Code
    1. ' reg set value Port DWORD 1
    2. ' reg set value Index DWORD 1
    3. ' PORT 33221100
    4. ' reg set value UseAsIOA DWORD 0x0003E000
    5. ' reg set value DataDirA DWORD 0x0003E000


    The port number above the UseAsIOA assigns to which porta this pins belong. If you like to use UseDirA/Bit15 for read you have to set this bit to zero:

    Code
    1. ' reg set value Port DWORD 1
    2. ' reg set value Index DWORD 1
    3. ' PORT 33221100
    4. ' reg set value UseAsIOA DWORD 0x0003E000
    5. ' reg set value DataDirA DWORD 0x00036000


    If you like to use other IOPins as in this sample you have to check if they are available (see VIO Interface HW docu.)!

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Quote from "Nase"

    I received a CD from F&S and a PicoMod1. The correct file name on the CD is: "NetDCU_DeviceDriver.pdf". But it is under the folder "NetDCU". and under the folder "German", there is no german description.


    Sorry, my mistake. I hadn't realized that it was for the PicoMOD1. Then the correct file is PicoMOD1_DeviceDriver_eng.pdf
    As the PicoMOD1 has more I/O pins than the standard NetDCUs, there is in fact a difference when using them. Mr. Zutter already explained that.


    Quote

    I program in VB.NET and all examples are in C++.


    Yes, this is a big problem. The .NET languages are getting more and more popular, but the drivers provide their interface in C only. However as all drivers use the file interface (CreateFile(), ReadFile(), WriteFile(), SetFilePointer(), DeviceIoControl(), CloseHandle()), using a .NET language you have two ways of accessing them:


    • Use the .NET file functions. They'll go down to the basic C interface in the end anyway.
    • Write your own wrapper functions to call the C file functions from coredll directly.


    It is very difficult to provide all documents in all languages and for all programming environments. For example if we have one document for C/C++, one for C#, one for VB, and then each of them at least in German and English, this is quite a lot to do.


    Therefore our main goal is to provide the English documentation and the C interface as a minimum. English is understood by most software people and this is also the reason why we prefer English here in the forum. And when the C interface is known, you can usually transfer the call to .NET somehow rather easily.


    Best regards,


    H. Keller

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello


    Thank you both for your response. I'll try it next week.


    Of course you can not write all codes in any language. For that, it's just fine to have access to this forum
    :)


    Timo

  • Hallo!
    Was ist zur Benutzung dieses Beispiels per WinNDCUCfg einzustellen?


    2-9(OUT) und 17-24(IN)? (& Haken in Generate...)


    Bei der Ausführung bekomme ich nur einen WinMain Fehler.




    In meiner Anwendung in C# bleibe ich bei dem ReadFile hängen, mit dem LastError 6. Woran kann dies liegen?


    Welches der Beispiele(auch AnalogIO) ist in C#? Habe leider keines gefunden.


    MfG

  • Hallo,


    der Fehler "WinMain(), CreateFile Failed" kommt schon wenn Sie die Schnittstelle öffnen möchten! Es hat also nichts mit den Einstellungen die Sie über WinNDCUCfg erzeugen zu tun. In WinNDCUCfg können Sie z.Z. für den DIO nur festlegen welche Funktion ein einzelner DIO Pin haben kann (IN oder OUT).
    Im vorliegenden Beispiel (für die NetDCU8) wird die DIO Schnittstelle mit dem Namen "DIO0:" geöffnet, d.h. Sie müssen den Wert "Index" unter "HKLM\Drivers\BuiltIn\DIO" auf "0" setzen (übrigens müssen Sie auch den Wert für den "Port" anpassen - oder SetFilePointer() verwenden).
    Im Quellkode ist das im Kopf genau beschrieben:


    d.h. für "WinNDCUCfg": die Pins von Port 0 sind Ausgänge und die Pins von Port 2 Eingänge. Die Werte "Index" und "Port" sind manuell auf "0" einzustellen - oder das Programm muss entsprechend angepasst werden.


    In C# und VB sind die Funktionsnamen identisch Sie müssen nur die Schreibweise anpassen!

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Danke soweit, jedoch hab ich noch folgendes:


    Read lt. DIO_VBTest:

    Code
    1. //Read File()
    2. [DllImport("coredll.dll", EntryPoint = "ReadFile", SetLastError = true)]
    3. private static extern int ReadFile(IntPtr hObject, Byte[] lpBuffer, uint NumberOfBytesToRead,
    4. uint lpNumberOfBytesRead, IntPtr lpOverLapped);


    mit der Funktion:



    Leider erhalte ich jedoch einen LastError 87, sprich falsche Parameter. und als Wert von data[0] = 255. Sehen Sie den Fehler?

  • sorry, falsche Funktion, das oben war nur ein Versuch: