danriches / WiringPi.Net

A simple C# wrapper for Gordon's WiringPi library.
46 stars 32 forks source link

EntryPointNotFoundException #3

Closed varadig closed 9 years ago

varadig commented 10 years ago

Hi Dan,

I'm new in C# so if my question is trivial, sorry :)

I follow your instruction and compile shared libraries. But when I want to try the GPIO on this way:

using System;

namespace WiringPiTest { class MainClass { public static void Main (string[] args) { WiringPi.Init.WiringPiSetup (); WiringPi.Init.WiringPiSetupSys (); WiringPi.GPIO.digitalWrite (0, 1); } } }

I got the following error

Unhandled Exception: System.EntryPointNotFoundException: digitalWriteGpio at (wrapper managed-to-native) WiringPi.GPIO:digitalWrite (int,int) at WiringPiTest.MainClass.Main (System.String[] args) [0x00000] in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.EntryPointNotFoundException: digitalWriteGpio at (wrapper managed-to-native) WiringPi.GPIO:digitalWrite (int,int) at WiringPiTest.MainClass.Main (System.String[] args) [0x00000] in :0

what should I do?

danriches commented 10 years ago

Hi,

Could you tell me where you created the shared libraries on the raspberry pi? The type of error you've posted seems to be because the application cannot find the shared libraries, or it could be that the libraries weren't created as shared objects properly. The part of the error EntryPointNotFound means it cannot find the libraries initialization function. You should also check that the file name you specified had the exact same case, for example the WiringPi WrapperClass.cs has the libraries named as: "libwiringPi.so", you can change the WrapperClass to match if you want.

If you could check those and let me know how you get on, both good and bad comments are welcome as it helps to make the library more functional and helps the greater community.

Regards,

Dan Riches

varadig commented 10 years ago

Hi,

the steps:

cc -shared wiringPi.o -o libwiringPi.so
cc -shared wiringPiI2C.o -o libwiringPiI2C.so
cc -shared wiringPiSPI.o -o libwiringPiSPI.so
sudo mv libwiringPi.so /lib
sudo mv libwiringPiI2C.so /lib
sudo mv libwiringPiSPI.so /lib
sudo nano /etc/modprobe.d/raspi-blacklist.conf

blacklist spi-bcm2708

and compiled your ConsoleApplication1

SPI init completed, using channel 0 at 20MHz for OLED Display
SPI init completed, using channel 0 at 20MHz for OLED Display

Unhandled Exception:
System.EntryPointNotFoundException: pinModeGpio
  at (wrapper managed-to-native) WiringPi.GPIO:pinMode (int,int)
  at SPITest.OLEDDriver.RunTest () [0x00000] in <filename unknown>:0
  at SPITest.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.EntryPointNotFoundException: pinModeGpio
  at (wrapper managed-to-native) WiringPi.GPIO:pinMode (int,int)
  at SPITest.OLEDDriver.RunTest () [0x00000] in <filename unknown>:0
  at SPITest.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
SPI init completed, using channel 0 at 32MHz for loopback testing
All zeros read back
danriches commented 10 years ago

The OLEDDriver run test is specifically for my oled screen i'm using connected to the spi bus, same for the AD9834 which is a DDS module. I would be inclined to remove those test files from the project and just use the standard LoopTest.RunTest(); which shouldn't fail.

Also under the ConsoleApplication1 Solution file, edit program.cs so that the lines referring to the AD9834 and OLEDDriver are commented out and your class file is the only one uncommented. This is the first piece of code to run which you want to be your code.

Let me know if this helps or not. Sorry for the late reply I did my back in well and truly :(

t0mek321 commented 9 years ago

Hi Dan,

I would like use WiringPi.Net, but I have error. This is me cod: 1) File Program.cs namespace SPITest { class Program { static void Main(string[] args) { //AD9834DDS.RunTest(); //OLEDDriver.RunTest(); LoopTest.RunTest(); } } } 2) File LoopTest.cs namespace SPITest { class LoopTest { //Main entry point public static int RunTest() { //Init WiringPi library int result = Init.WiringPiSetup();

    if (result == -1)
    {
        Console.WriteLine("WiringPi init failed!");
        return result;
    }
    else
    {
        Console.WriteLine("Init GPIO OK");
    }
    result = Init.WiringPiSetupSys();
    Console.WriteLine("Result SetupSys = " + result);
    //GPIO.pinMode(4,GPIO.GPIOpinmode.Output);
    GPIO.digitalWrite(7, 1);
    GPIO.digitalWrite(4, 1);
    return 0;
}

} }

I use my Pi and in console I run my program like: sudo mono SPITest.exe

I have seen information "Init GPIO OK" and later this ERROR: Unhandled Exception: System.EntryPointNotFoundException: digitalWriteGpio at (wrapper managed-to-native) WiringPi.GPIO:digitalWrite (int,int) at SPITest.LoopTest.RunTest () [0x00000] in :0 at SPITest.Program.Main (System.String[] args) [0x00000] in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.EntryPointNotFoundException: digitalWriteGpio at (wrapper managed-to-native) WiringPi.GPIO:digitalWrite (int,int) at SPITest.LoopTest.RunTest () [0x00000] in :0 at SPITest.Program.Main (System.String[] args) [0x00000] in :0

Dan could you tell me solution for fix it?

danriches commented 9 years ago

Hi,

First off you need to set the GPIO pin to output mode and you've commented that line out ("//GPIO.pinmode....."). The missing entry point is possibly because the application cannot find the compiled shared library, please make sure you follow the compile instructions for Gordon's WiringPi C library on the front page of this repository to ensure you have compiled ALL the required shared libraries. If you still have issues then hopefully if I find time I'll look into it and update the compile instructions or reply to you with the changes you need to get this to work correctly.

Best Regards,

Dan

t0mek321 commented 9 years ago

Dan

I have added this line: GPIO.pinMode(4,GPIO.GPIOpinmode.Output);

I have the same error. I have tested in Raspberry Pi B+ and Raspberry Pi 2. I did everything with your description with this page: https://github.com/danriches/WiringPi.Net

Could send me some solution?

danriches commented 9 years ago

Hmm, you shouldn't really have this problem. Some questions for you: 1) Have you got the SPI bus enabled? Use "sudo raspi-config" to check and enable it. 2) Have you got the latest updated kernel and linux loaded? Use sudo update, sudo upgrade. 3) You've obviously got mono loaded otherwise yo wouldn't have that error, but what version of visual studio are you compiling under?

Regards,

Dan

t0mek321 commented 9 years ago

Hi Dan,

Ok, it work now. I have now small problem with use function wiringPiISR(). I have added post: http://direct.raspberrypi.org/forums/viewtopic.php?t=102269&p=708170

Dan could you tell me how use function wiringPiISR() in C# ?

danriches commented 9 years ago

The ISR functions were written by someone else and I pulled in their changes to this repository, please see the issue below and have a look at what Gherman added. I've not tested this myself but Gherman says it worked for him. I hope you get it all working.

https://github.com/danriches/WiringPi.Net/issues/1

Regards, Dan

MENUT commented 9 years ago

Hello, I think the problem come from WrapperClass GPIO class and DllImport EntryPoint are with Gpio name.

If you observe libwiringPi.so pinModeGpio does not exists and this is the same for source file wiringPi.h in section Core wiringPi functions extern void pinMode (int pin, int mode) ; extern void digitalWrite (int pin, int value) ;

Solution : Change all class GPIO EntryPoints without Gpio : Exemple: pinModeGpio by pinMode //[DllImport("libwiringPi.so", EntryPoint = "pinModeGpio")] //Uses Gpio pin numbers [DllImport("libwiringPi.so", EntryPoint = "pinMode")] //Uses Gpio pin numbers public static extern void pinMode(int pin, int mode);

/// <summary>
/// Used to configure a GPIO pin's direction and provide read & write functions to a GPIO pin
/// </summary>
public class GPIO
{
    [DllImport("libwiringPi.so", EntryPoint = "pinMode")]           //Uses Gpio pin numbers
    public static extern void pinMode(int pin, int mode);

    [DllImport("libwiringPi.so", EntryPoint = "digitalWrite")]      //Uses Gpio pin numbers
    public static extern void digitalWrite(int pin, int value);

    [DllImport("libwiringPi.so", EntryPoint = "digitalWriteByte")]      //Uses Gpio pin numbers
    public static extern void digitalWriteByte(int value);

    [DllImport("libwiringPi.so", EntryPoint = "digitalRead")]           //Uses Gpio pin numbers
    public static extern int digitalRead(int pin);

    [DllImport("libwiringPi.so", EntryPoint = "pullUpDnControl")]         //Uses Gpio pin numbers  
    public static extern void pullUpDnControl(int pin, int pud);

    //This pwm mode cannot be used when using GpioSys mode!!
    [DllImport("libwiringPi.so", EntryPoint = "pwmWrite")]              //Uses Gpio pin numbers
    public static extern void pwmWrite(int pin, int value);

    [DllImport("libwiringPi.so", EntryPoint = "pwmSetMode")]             //Uses Gpio pin numbers
    public static extern void pwmSetMode(int mode);

    [DllImport("libwiringPi.so", EntryPoint = "pwmSetRange")]             //Uses Gpio pin numbers
    public static extern void pwmSetRange(uint range);

    [DllImport("libwiringPi.so", EntryPoint = "pwmSetClock")]             //Uses Gpio pin numbers
    public static extern void pwmSetClock(int divisor);

    [DllImport("libwiringPi.so", EntryPoint = "gpioClockSet")]              //Uses Gpio pin numbers
    public static extern void ClockSetGpio(int pin, int freq);

    public enum GPIOpinmode
    {
        Input = 0,
        Output = 1,
        PWMOutput = 2,
        GPIOClock = 3
    }
}

It works for me but I think it is possible to correct it in repository. Regards, Fred