GPIO on Windows 10

WaterlooWaterloo Posts: 2New Member
Hello everybody,

I have a UpBoard and would like to use the GPIOs. How to configure and use the GPIOs on Windows 10?

Comments

  • Jacky KuoJacky Kuo Posts: 70New Member
    Hi,
    Please use this Windows SDK to config.
  • WaterlooWaterloo Posts: 2New Member
    Hi,

    thanks for the answer. It works well. Is it possible to change the start values?

    As an example, Pin 3. When running the program the following is set: Mode = Output and Value = Low.
    Can I rewrite the program so that these values are at the start of other? As an example, Mode = High and Value = High? If I can rewrite the program, where can I find the initial values? Are these included in GpioDefine.h or DioDlg.cpp?
  • Jacky KuoJacky Kuo Posts: 70New Member
    Hi,
    Please enter BIOS Setup, here should have GPIO configuration to set initial value. ;)
  • DenisDenis Posts: 4New Member
    Hi, can you tell me please how can i use GPIO on up board with C#? I'm programming a win form application.
    I saw that the SDK that you've linked is written in C

    Thanks in advance!
  • Chris BothaChris Botha Posts: 48New Member
    XineD wrote:
    Hi, can you tell me please how can i use GPIO on up board with C#? I'm programming a win form application.
    I saw that the SDK that you've linked is written in C

    Thanks in advance!

    Same request here please, the include results in "not a valid com object" and using dllimport is not delivering any result at all.
  • Jacky KuoJacky Kuo Posts: 70New Member
    Hi,
    Please use HiSafe2 and DIO SDK(For C#) to develop.

    Hi-Safe2&aaeonFramework
    https://www.dropbox.com/s/ha0nxu0kmdnfta9/Hi-Safe_v2_20161017.rar?dl=0

    DIO SDK(For C#)
    https://www.dropbox.com/s/uamv9p4tt5881jm/Dio.rar?dl=0
  • Jacky KuoJacky Kuo Posts: 70New Member
    Hi,
    Please use Hi-Safe2 and DIO SDK(For C#) to develop.

    Hi-Safe2&aaeonFramework
    www.dropbox.com/s/ha0nxu0kmdnfta9/Hi-Safe_v2_20161017.rar?dl=0

    DIO SDK(For C#)
    www.dropbox.com/s/uamv9p4tt5881jm/Dio.rar?dl=0
  • Chris BothaChris Botha Posts: 48New Member
    Thank you for that reply, will poke around at it tonight.
  • Jacky KuoJacky Kuo Posts: 70New Member
    Thanks~~Please try it. : )
  • Chris BothaChris Botha Posts: 48New Member
    Im having hardware issues as detailed here

    https://up-community.org/forum/public-upboardhw/943-bad-screen-and-bad-bios

    but I did manage to get an LED to blink on and off using the c# code, so confirm it does work for me.
  • Chris BothaChris Botha Posts: 48New Member
    edited October 2016
    CeeBee wrote:
    Thank you for that reply, will poke around at it tonight.

    Hi. So a minor issue.. using teh hi-safe app i can successfully turn an LED on and off, but using the sdk supplied at link you posted, when I tried to code using info i can launch library, but not set pin values.

    So i tried I compiled the DIO app to test. Same result, it runs, it says its changing values but at pin level there is nothing happening. the aaeon dll is in the folder so not a library issue.

    Can you please advise what is different between the code in the Hi-Safe app and the supplied dio example?

    EDIT: the older c++ compiled example runs and sets the pins fine, BUT it refuses to compile in VS15, quoting multiple .net references 2.0 and 3.5.
    However I need C#

    Please find my file attached, intact, it simply sets pin3 high and low over 300ms intervals. Code is based on the sample code you provided about, with aaeon 64bit framework installed, https://drive.google.com/open?id=0B5yCbfbC75zDaXlDZWZueHZjWDQ

    compiling in "any cpu", 32 or 64 bit makes no difference.
  • Chris BothaChris Botha Posts: 48New Member
    To try clarify what I am getting at.

    original c++ compiled sample from release folder
    cplussample.jpg

    Hi-Safe
    hisafe.jpg

    Compiled example from your posted link above of c# code does not work, it says its done it, but does nothing.
    my own code posted above has same issue...
    suppliedsamplecode.jpg
  • Jacky KuoJacky Kuo Posts: 70New Member
    Hi ,
    Please use below DIO revision(For C#), this has fixed the issue.
    https://www.dropbox.com/s/9r3j77zesppj828/Dio.rar?dl=0
  • Chris BothaChris Botha Posts: 48New Member
    Thank for the quick reply, will give it a spin now.
  • Chris BothaChris Botha Posts: 48New Member
    Ok the C# app working now. Ill get back to transferring my own app over.

    For anyone else following this thread, you cant compile in vs15, after it "upgrades" the package, and will get about 20 errors regarding clash between .net 2 and .net 3.5 with ms links to all kinds of obscure fixes.. don't do any of the fixes, do these four things, in this order. (if like me you need functionality over .net 2...)

    1. In your references, delete System.Core (vs15 no longer needs to be included, its called automatically)

    2. Set your project to use .Net 4.52 (or whatever version you need)

    3. Rightclick DIO in solution explorer, hit properties then tab to Build Events, delete the entry in Post-Build Events command line which specifically wants a .net 2 build ""$(DevEnvDir)../../SDK/v2.0/bin/mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" -outputresource:"$(TargetDir)$(TargetFileName)";#1"

    4. Close VS15, reopen app, run Clean build. Now it will compile properly and I can confirm it now runs properly.
  • Chris BothaChris Botha Posts: 48New Member
    edited October 2016
    @JKuo

    I am a bit stumped here, I'm trying to write a simple app to understand how the pins work, but while my code runs fine and does not crash, its not lighting the pins up. I thinks its related to the EApiGPIOGetCaps which is called before every "set" in the example, but the example is difficult to figure out.

    Could you please scan this and tell me what I'm doing wrong?

    LED is on pin3(gpio2) and 6(GND) and works fine when i use your example.

    Apologies to have to ask bu t documentation is scarce ion the downloaded PDF's with hisafe.
    using Dio;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace CB_UpBoard_Blinky
    {
        public partial class Form1 : Form
        {
            #region Variables
            public uint HIGH = 0x01;
            public uint LOW = 0x00;
            public uint INPUT = 0x01;
            public uint OUTPUT = 0x00;
            private uint nPinCount;
            private uint bDioDisable = 1;
            #endregion
            #region Import DLL Calls
            [DllImport("aaeonEAPI.dll", EntryPoint = "EApiGPIOGetDirectionCaps")]
            public static extern UInt32 EApiGPIOGetDirectionCaps(uint Id, ref UInt32 pInputs, ref UInt32 pOutputs);
            [DllImport("aaeonEAPI.dll", EntryPoint = "EApiGPIOGetDirection")]
            public static extern UInt32 EApiGPIOGetDirection(UInt32 Id, UInt32 Bitmask, ref UInt32 pDirection);
            [DllImport("aaeonEAPI.dll", EntryPoint = "EApiGPIOSetDirection")]
            public static extern UInt32 EApiGPIOSetDirection(UInt32 Id, UInt32 Bitmask, UInt32 Direction);
            [DllImport("aaeonEAPI.dll", EntryPoint = "EApiGPIOGetLevel")]
            public static extern UInt32 EApiGPIOGetLevel(UInt32 Id, UInt32 Bitmask, ref UInt32 pLevel);
            [DllImport("aaeonEAPI.dll", EntryPoint = "EApiGPIOSetLevel")]
            public static extern UInt32 EApiGPIOSetLevel(UInt32 Id, UInt32 Bitmask, UInt32 Level);
            [DllImport("aaeonEAPI.dll", EntryPoint = "EApiGPIOGetCaps")]
            public static extern UInt32 EApiGPIOGetCaps(UInt32 Id, ref UInt32 PinCount, ref UInt32 pDioDisable);
            [DllImport("aaeonEAPI.dll", EntryPoint = "EApiLibInitialize")]
            public static extern UInt32 EApiLibInitialize();
            [DllImport("aaeonEAPI.dll", EntryPoint = "EApiLibUnInitialize")]
            public static extern UInt32 EApiLibUnInitialize();
            #endregion
    
            public  Form1()
            {
                InitializeComponent();
                EnableSDIO();
                label1.Text = "SDIO Enabled";
                pause(2);
    
                //what is this?
                EApiGPIOGetCaps(EAPI.EAPI_GPIO_GPIO_ID((uint)0), ref nPinCount, ref bDioDisable);
    
                //set direction
                EApiGPIOSetDirection(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, OUTPUT);
    
                //off
                EApiGPIOSetLevel(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, LOW);
                label1.Text = "Set 3 LOW";
                pause(3);
    
                //on
                EApiGPIOSetLevel(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, HIGH);
                label1.Text = "Set 3 HIGH";
                pause(3);
    
                //off
                EApiGPIOSetLevel(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, LOW);
                label1.Text = "Set 3 LOW";
                pause(3); 
                
                //kill 
                EApiLibUnInitialize();
            }
    
            private async void pause(int seconds)
            {
                await Task.Delay(TimeSpan.FromSeconds(seconds));
            }
            private void EnableSDIO()
            {
                uint err = EApiLibInitialize();
                if (err != EAPI.EAPI_STATUS_INITIALIZED)
                {
                    MessageBox.Show(this, "Can't initialize the application: " + err.ToString("X"), "Hi-Safe", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }  
            }
        }
    
  • Jacky KuoJacky Kuo Posts: 70New Member
    Hi,
    Sorry I'm not the SDK developer.. he is out of office these days, I will try to consult him about EApiGPIOGetCaps function when he comes back.
    By the way, maybe you can try another GPIO pins?
  • Chris BothaChris Botha Posts: 48New Member
    edited October 2016
    Hi there,

    yes i tried on multiple pins, all with same result.

    I'm hoping a sane API comes out soon.. INCLUDE UP_GPIO with calls like SetPinDir(3, output) and SetPinValue(3, HIGH)

    EDIT: NM wrote my own.

    Thank you for your help until so far anyhow.
  • Chris BothaChris Botha Posts: 48New Member
    edited October 2016
    .
  • Chris BothaChris Botha Posts: 48New Member
    ok got it sorted, pin numbering glitch in the sdk...
  • Jacky KuoJacky Kuo Posts: 70New Member
    Hi CB,
    Thanks for your inspiring suggestion, let me feedback to developer.

    About "EApiGPIOGetCaps" API, currently I am not yet get confirmation of meaning from developer, but I further check the sample code, the "EApiGPIOGetCaps" API should only be a API to "See if a specific pin is capable to be set a value".

    In "buttonSet_Click" API, it uses judgment "if (bDioDisable != 0x01)" before actually set pin value . (For pin3, the "k" should be 2 and "nPinCount" should be 3 I think)


    If we want to light up LED, we have to set "direction" and "level".

    //on
    EApiGPIOSetDirection(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, OUTPUT);
    EApiGPIOSetLevel(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, HIGH);

    If the LED can be turned on, then we add delay and turn off LED.

    //delay
    pause(3);

    //off
    EApiGPIOSetDirection(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, OUTPUT);
    EApiGPIOSetLevel(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, LOW);

    Try if this works.:)
  • Jacky KuoJacky Kuo Posts: 70New Member
    Hi CB,
    Thanks for your inspiring suggestion, let me feedback to developer.

    About "EApiGPIOGetCaps" API, currently I am not yet get confirmation of meaning from developer, but I further check the sample code, the "EApiGPIOGetCaps" API should only be a API to "See if a specific pin is capable to be set a value".

    In "buttonSet_Click" API, it uses judgment "if (bDioDisable != 0x01)" before actually set pin value . (For pin3, the "k" should be 2 and "nPinCount" should be 3 I think)


    If we want to light up LED, we have to set "direction" and "level".

    //on
    EApiGPIOSetDirection(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, OUTPUT);
    EApiGPIOSetLevel(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, HIGH);

    If the LED can be turned on, then we add delay and turn off LED.

    //delay
    pause(3);

    //off
    EApiGPIOSetDirection(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, OUTPUT);
    EApiGPIOSetLevel(EAPI.EAPI_GPIO_GPIO_ID((uint)3), 0xFFFFFFFF, LOW);


    Note:
    If this doesn't work, maybe can try index 2.
  • Chris BothaChris Botha Posts: 48New Member
    Thanks, as per this thread earlier today I figured out the sdk has the pin numbering wrong.

    https://up-community.org/forum/general-discussion/956-got-gpio-working-in-c-finally#2738
  • Jacky KuoJacky Kuo Posts: 70New Member
    Cool....thanks for your sharing.
  • MarekLaniMarekLani Posts: 1New Member

    Please, can somebody share DIO SDK for C#?

  • mervinDevmervinDev Posts: 2New Member

    Hi, I know this is an old topic but is there any updates regarding using GPIO in windows 10? All the links included in this thread is currently unavailable. Thanks in advance in any help..

  • JuliaTruchsessJuliaTruchsess Posts: 4New Member

    @mervinDev said:
    Hi, I know this is an old topic but is there any updates regarding using GPIO in windows 10? All the links included in this thread is currently unavailable. Thanks in advance in any help..

    +1

Sign In or Register to comment.