Read I/O Pin in C# fails

  • Hello,


    i have got a problem reading an I/O - Pin of my PicoMOD6 in a C# application under Win CE6.0.


    i use CreateFile() and ReadFile() which are used via DllImport, but when I do CreateFile i get a "-1" as result.
    Here is some code:



    According to a PM to fs-support_ZU here are some additional information:
    In the registry under HKLM\Drivers\Active\ there is one key with following entrys:

    • Hnd = 3499885408
    • Name = DIO1:
    • Key = Drivers\BuiltIn\DIGITALIO
    • BusParent = 3492486400
    • InterfaceType = 0
    • BusName = BuiltInPhase1_0_0_0


    When i try different DIOs then DIO1 i get an invalid handle.
    If I use DIO1 then i get a valid handle, but when reading the Pin there is always a "1" as result. Even when connecting pin over 10kOhm to GND.


    In the registry under HKLM\Drivers\\BuiltIn\DIGITALIO
    is the following:


    • DataInit = 16
    • DataDir = 16
    • Type = 0
    • UseAsKey = 0
    • IRQCfg0 = 0
    • IRQCfg1 = 0
    • IRQCfg2 = 0
    • UseAsIO = 16715775
    • Prefix = DIO
    • Dll = PM6_DIGIO.dll
    • Order = 151
    • Index = 1
    • Ioctl = 4
    • Port = 1
    • FriendyName = Digital I/O driver for PicoMOD6
  • Hello,
    please use following document http://www.fs-net.de/download/…D_DeviceDriver_WCE600.pdf for correct your "UseASIO" and "DataDir" registry names/values. For PicoMOD you these values are named "UseAsIOX" or "DataDirX" (X=A...D).


    Note also - if "your pin" is not on "•Port = 1" you need a "SetFilePointer" before "ReadFile"!


    Here you will find a C# DIO sample class http://www.fs-net.de/phpBB2/viewtopic.php?f=4&t=2377.

    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.

  • Thanks for the Documentation it helped to configure it correct but it doesn't work.


    I want to poll the Port every 500ms so i use a Timer and the time it elapsed i read the Pin.


    This is my complete code:



    I want to use GPIO5 on Pin29 on Port1 and at connector J5 at Pin9.
    I still get "1" when i use ReadFile() no matter if i connect GND, +3V3 or +5V of the J5 connector over 10kOhm to Pin 9.


    The registry is the following:



      UseAsIOA DWORD 0x00000200
      DataDirA DWORD 0x00000000
      DataInitA DWORD 0x00000000
      IRQCfg0A DWORD 0x00000000
      IRQCfg1A DWORD 0x00000000
      IRQCfg2A DWORD 0x00000000

  • Hello,
    everything seem to be right!


    Whats the return value of "ReadFile()"?
    Whats the value of "Data"?
    And is "Read"=1?


    Please check also value of "GetLastError()".

    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.

  • return from ReadFile() is 1
    Data[0] is 0
    Read[0] is 1


    i will check GetLastError() in a minute and edit post
    edit: value from GetLastError() is 87
    edit2:to be more precisely:
    Int32 error = Marshal.GetLastWin32Error(); --> error 87 sometimes 6
    with DllImport of coredll.dll and then GetLastError()
    Int32 error = GetLastError(); --> error 5

  • Hello,


    Quote

    still get "1" when i use ReadFile() no matter if i connect GND, +3V3 or +5V of the J5 connector over 10kOhm to Pin 9


    You said you still get "1". But above you said "Data"=0? "Data" contains the IO-value of Port1!
    Please refer http://msdn.microsoft.com/en-us/library/aa365467(VS.85).aspx.

    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.

  • yes at first i had a misunderstanding of ReadFile() und took the result of that as the value read from Port and that was always 1 which is not bad at all
    but Data was always 0
    sry for that mistake of me that was surely a little bit confusing

  • another, maybe important, information:
    we had to install a new ebootloader and kernel because we did the reset to factory settings.
    so we installed a new ebootloader, repartitioned the Flash and installed a new kernel.
    and we had to take a kernel from the BETA folder of the "kernel" folder on CD.


    "XIPNK6_CORE_091211.bin" didn't want to install properly


    so we took


    "NK6_MP_091201.bin" and everything worked. Could that be a problem?

  • any ideas?


    i tried to write on that port and pin and it worked without any problems using WriteFile() within a timer and toggled that pin... for that i changed the registry settings of course... then i change UseDataDirA back to 0x0 and tried to read and always "0" even with only 1kOhm from +3V3 to PIN9


    i measured the voltage at that Pin and there were 3,311V so it is a logical 1


    i have no idea were to look at or what to change to get it to work

  • Hello,


    we will check this behaviour and answer in this forum asp.

    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,
    you are right "ReadFlie" does not work correct. We will rework the driver. The corrected version will be available with kernel release V0.03.

    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.

  • We have fixed the problem in the new DIO driver (version: V2.0). This driver will be included in the next kernel release.

    Software developer, 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,


    i've got the same problem with PicoMOD6 but using C++.
    I use already the same settings as described above.
    But i get never data after ReadFile.


    I use Kernel V1.04 (6. Sept. 2010)


    Here the functions:


    Here are the Reg-Settings:

    Code
    1. "UsesAsIOA"=dword:0000ffff
    2. "DataDirA"=dword:00002000
    3. "Prefix"="DIO"
    4. "Dll"="PM6_DIGIO.dll"
    5. "Order"=dword:00000097
    6. "Index"=dword:00000001
    7. "Ioctl"=dword:00000004
    8. "Port"=dword:00000001
    9. "FriendlyName"="Digital I/O driver for PicoMOD6"


    Thanx !

  • We will check this again.
    Could you please enable some debug messages and check if there appears an error?

    Code
    1. reg open \drivers\builtin\digitalio
    2. reg set val debug dword 0xffff
    3. reg save


    Maybe you could also test this with a small sample application available in this forum:
    DIO Read/Write Port dialog based application

    Software developer, 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 have set the debug reg key, but i get no debug messages and no error message !


    Now i try the sample from you, but still there is a linker error:
    coredll.lib(COREDLL.dll) : fatal error LNK1112: Modul-Computertyp "THUMB" steht in Konflikt mit dem Zielcomputertyp "ARM


    Maybe a conversion problem, because of Visual Studio 2008.

  • Quote from "SML"

    I have set the debug reg key, but i get no debug messages and no error message !


    Could you post the complete debug trace? At least during DIO intialization there should be some messages that tells about pin configuration.


    Quote from "SML"

    Now i try the sample from you, but still there is a linker error:
    coredll.lib(COREDLL.dll) : fatal error LNK1112: Modul-Computertyp "THUMB" steht in Konflikt mit dem Zielcomputertyp "ARM


    This project was based on PicoCOM2 SDK. When switching to PicoMOD6 platform type it should compile correctly.
    If this does not work you could also use the available executable (Release directoy). This should also work on PicoMOD6.

    Software developer, 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.

  • The sample works not and there is no executable inside the zip file.


    But i created a new project and copied the relevant sources and now it works on picomod6
    but still no data is read from port.


    Look here:

  • Thanks for you efforts.
    We will check this issue in detail and post the results in this thread.

    Software developer, 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 can't reproduce your issue!


    For my tests I use the sample application and the same registry settings.



    The pins as standard high(0xFF) so I use an pull down to register any change. With an pull down the tool shows 0xBF.

    Files

    • DIO_RW-Port.zip

      (339.79 kB, downloaded 359 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.

  • Maybe you have another PicoMOD6 to verify if the IO-Pins of your current board are damaged?
    Did you run this test on your own base board?

    Software developer, 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.