unosquare / pigpio-dotnet Goto Github PK
View Code? Open in Web Editor NEWProvides complete managed access to the popular pigpio C library
Home Page: https://unosquare.github.io/pigpio-dotnet
License: MIT License
Provides complete managed access to the popular pigpio C library
Home Page: https://unosquare.github.io/pigpio-dotnet
License: MIT License
Could you please implement Unosquare.PiGpio.NativeMethods.Waves.GpioWaveChain in the managed model? It would make code much less clunky.
Should add a quick project background. This program is a GUI for some machines, its written in VB.Net and includes MySQL functions. It uses Mono running on Raspbian 10 (Pi 4B). The app runs great, now I need to implement the I/O portion which requires 1 Interrupt and 1 Output. I can get output to work but need to figure out the Interrupt.
Using Visual Studio 2019.
Not sure if an issue or I'm just clearly missing something... I cant figure out how to setup the interrupts...
I have :
Imports Unosquare.PiGpio
Imports Unosquare.PiGpio.NativeEnums
Imports Unosquare.PiGpio.NativeMethods
Imports Unosquare.PiGpio.NativeTypes
Public Sub InitializeController()
Setup.GpioInitialise()
Dim pin = SystemGpio.Bcm17
IO.GpioSetMode(pin, PinMode.Input)
IO.GpioSetIsrFunc(pin, EdgeDetection.RisingEdge, 0, DisplayMessage)
End Sub
Public Sub DisplayMessage()
MsgBox("Interrupt Received on Pin 17")
End Sub
The callback (DisplayMessage) has an error as Expression does not produce a value...
I tried a function instead of a Sub, but same issue. Not sure how to use the PiGpioIsrDelegate which the documentation mentions...
Using Visual Studio 2019, VB.Net.
Sorry this seems like a really stupid question/issue lol...
I just need a nudge in the right direction in regards to settings up the Interrupt to call a specific Sub/Function.
Thanks in advance.
Hi! Great work with this project! Is it possible to publish the latest version on Nuget? I am not able to use the abstraction project with the pigpio-dotnet version available on Nuget now.
Hi,
I always get InitFailed when calling Setup.GpioInitialise. Board.LibraryVersion returns 68. The pigpio daemon is running and I can use the command pigs so I am sure pigpio is working correctly.
But the Unosquare library can't initialize the library. What can I check to find the problem?
I am running Raspbian Buster.
Thanks,
Christian
Implement Unosquare.RaspberryIO.Abstractions
There are no Interfaces used in PiGpio(IGpioController/IGpioPin/ISpiChannel/etc...)
public sealed class GpioPin
{
...
}
should be
public sealed class GpioPin : IGpioPin
{
...
}
Maybe this is a feature request?
I want to use the Unosquare.PiGpio.NativeMethods.Waves.GpioWaveChain
method. This requires to prepare multiple waves and pass their wave id.
The issue is, that Unosquare.PiGpio.ManagedModel.WaveBuilder.Prepare
is calling Unosquare.PiGpio.NativeMethods.Waves.GpioWaveClear
which results in clearing the already prepared waves.
I would propose to remove the call Unosquare.PiGpio.NativeMethods.Waves.GpioWaveClear
I wrote an application on WinForm. What the program does. When pressing the touch button that is connected to BCM23, the LED lights on and off (BCM18).
I run this application with the command: sudo mono WindowsFormsApp6.exe
The program works for some time (about 3-5 minutes) and then freezes and writes an error:
How can this problem be solved?
Help me please.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Unosquare.PiGpio.NativeMethods;
using Unosquare.PiGpio.NativeEnums;
using System.Threading;
namespace WindowsFormsApp6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Setup.GpioInitialise();
var pin23 = SystemGpio.Bcm23;
IO.GpioSetPullUpDown(pin23, GpioPullMode.Up);
IO.GpioSetAlertFunc(UserGpio.Bcm23, triggerLED);
}
private void triggerLED(UserGpio userGpio, LevelChange levelChange, uint timeMicrosecs)
{
var LED_gpio = SystemGpio.Bcm18;
if (levelChange == 0)
{
IO.GpioWrite(LED_gpio, true);
}
else
{
IO.GpioWrite(LED_gpio, false);
}
}
}
}
Previously, I deduced in the textBox1:
private void triggerLED(UserGpio userGpio, LevelChange levelChange, uint timeMicrosecs)
{
var LED_gpio = SystemGpio.Bcm18;
if (levelChange == 0)
{
IO.GpioWrite(LED_gpio, true);
textBox1.Text += " gpio=" + userGpio + " level = " + levelChange + " tick =" + timeMicrosecs + '\r' + '\n';
}
else
{
IO.GpioWrite(LED_gpio, false);
textBox1.Text += " gpio=" + userGpio + " level = " + levelChange + " tick =" + timeMicrosecs + '\r' + '\n';
}
}
but after a couple of button presses, the application hangs with an error:
sigHandler: Unhandled signal 30, terminating
The PiGpio is working very nice and fast, but I can't start NetCore code as normal user ("pi"), it needs "sudo" to work. Is there a solution to this issue? I've searched around, but I coudn't solve. Is there anyone can help?
For some reasons, my monodevelop/VS Code doesn't work.
Could someone tell me, if there is still a chance to use this library and how?
Thx in advance :)
I tried to compile the pigpio-dotnet/Unosquare.PiGpio/Unosquare.PiGpio.csproj with:
msbuild Unosquare.PiGpio.csproj
And then use the dll for my cs program:
mcs motor.cs -r:Unosquare.PiGpio.dll
However I got error with I target netcoreapp3.0:
error CS0012: The type `System.Enum' is defined in an assembly that is not referenced. Consider adding a reference to assembly `System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
error CS0012: The type `System.Object' is defined in an assembly that is not referenced. Consider adding a reference to assembly `System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
I tried to target netstandard2.0, the similar error:
error CS0012: The type `System.Enum' is defined in an assembly that is not referenced. Consider adding a reference to assembly `netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
error CS0012: The type `System.Object' is defined in an assembly that is not referenced. Consider adding a reference to assembly `netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
Any ideas will be appreciated :)
Description
Hi When I use any gpio and then I want to get the output of a process like "cat /proc/cpuinfo | grep Serial | awk ' {print $3}'" the application hangs in WaitForExit of Process method, I've shared a project in a repo -> https://bitbucket.org/juandrn/waitforexithangsafterusegpio/src
To Reproduce
dotnet publish -r linux-arm -c debug
(In visual studio 2017)dotnet WaitForExitAfterSocketTimeout.dll
Expected behavior
The application should return the serial number, the first time always is empty, but It is not the problem, the problem Is the "System.TimeoutException"
Error
https://i.imgur.com/jOtJ55L.png
Develop Dotnet
https://i.imgur.com/TapdHSh.png
Raspberry Runtime Dotnet
https://i.imgur.com/RKGn6WL.png
Best regards
If you need another information please tell me
Thanks! and great project
Could you please implement a way of using pigpiod daemon instead of using the pipe interface?
When using the managed way you offer in your library, I did not found a way to chose between the two possibilities that PiGpio is offering.
When I compile with my app with dotnet publish -r linux-arm -o dist -c Release
the app is very unstable. I get a lot of messages like this: 2019-10-30 14:11:31 sigHandler: Unhandled signal 34, terminating
If I compile using dotnet publish -r linux-arm -o dist -c Debug
the app is much more stable.
Is this something you are familiar with?
I cannot start a wave using managed code:
Board.Waves.CreateWave.ClearPulses()
For i = 0 To 2000
Board.Waves.CreateWave.AddPulse(False, 100, NativeEnums.UserGpio.Bcm19)
Board.Waves.CreateWave.AddPulse(True, 100, NativeEnums.UserGpio.Bcm19)
Next
Board.Waves.CreateWave.Send(NativeEnums.WaveMode.OneShot)
Using native calls it works:
Dim pulseOn = New NativeTypes.GpioPulse With {
.DurationMicroSecs = 100,
.GpioOff = 0,
.GpioOn = NativeEnums.BitMask.Bit19}
Dim pulseOff = New NativeTypes.GpioPulse With {
.DurationMicroSecs = 100,
.GpioOff = NativeEnums.BitMask.Bit19,
.GpioOn = 0}
NativeMethods.Waves.GpioWaveClear()
Dim pulses(1999) As NativeTypes.GpioPulse
For i = 0 To 1999
pulses(i) = pulseOff
i += 1
pulses(i) = pulseOn
Next
NativeMethods.Waves.GpioWaveAddGeneric(2000, pulses)
Dim wid As Integer = NativeMethods.Waves.GpioWaveCreate()
NativeMethods.Waves.GpioWaveTxSend(CUInt(wid), NativeEnums.WaveMode.OneShot)
Stopping alerts makes the program crash (pigpio v67)
mcs test.cs
test.cs
namespace Unosquare.PiGpio.HangExample
{
using System;
using System.Runtime.InteropServices;
class PiGpioTest
{
public delegate void PiGpioAlertDelegate(uint userGpio, uint levelChange, uint ticks);
public static void Main(string[] args)
{
// Init the library
GpioInitialise();
// Register an alert function
GpioSetAlertFunc(4, (userGpio, levelChange, ticks) =>
{
Console.WriteLine($"GPIO: {userGpio} Level: {levelChange} Ticks: {ticks}");
});
// Set an alert watchdog of 1 second
GpioSetWatchdog(4, 1000);
// Wait for user input to stop alerts
Console.ReadKey(intercept: true);
GpioSetAlertFunc(4, null);
Console.WriteLine("Correctly stopped alerts.");
// Wait for the user to end the program gracefully
Console.ReadKey(intercept: true);
Console.WriteLine("Program stopped gracefully.");
}
[DllImport("libpigpio.so", EntryPoint = "gpioInitialise")]
public static extern int GpioInitialise();
[DllImport("libpigpio.so", EntryPoint = "gpioSetAlertFunc")]
public static extern int GpioSetAlertFunc(uint userGpio, [In, MarshalAs(UnmanagedType.FunctionPtr)] PiGpioAlertDelegate callback);
[DllImport("libpigpio.so", EntryPoint = "gpioSetWatchdog")]
public static extern int GpioSetWatchdog(uint userGpio, uint timeoutMilliseconds);
}
}
output:
pi@raspberrypi:~/pigpio-dotnet $ sudo mono test.exe
GPIO: 4 Level: 2 Ticks: 2063112400
GPIO: 4 Level: 2 Ticks: 2064112652
GPIO: 4 Level: 2 Ticks: 2065112905
GPIO: 4 Level: 2 Ticks: 2066113282
GPIO: 4 Level: 2 Ticks: 2067113535
GPIO: 4 Level: 1 Ticks: 2067530671
GPIO: 4 Level: 2 Ticks: 2068531289
GPIO: 4 Level: 2 Ticks: 2069531916
GPIO: 4 Level: 0 Ticks: 2069980377
GPIO: 4 Level: 1 Ticks: 2070152627
GPIO: 4 Level: 0 Ticks: 2070295198
GPIO: 4 Level: 1 Ticks: 2070470928
GPIO: 4 Level: 0 Ticks: 2070596259
GPIO: 4 Level: 1 Ticks: 2071118840
GPIO: 4 Level: 0 Ticks: 2071373096
GPIO: 4 Level: 1 Ticks: 2071373101
GPIO: 4 Level: 0 Ticks: 2071373131
GPIO: 4 Level: 1 Ticks: 2071811452
GPIO: 4 Level: 0 Ticks: 2072063727
GPIO: 4 Level: 2 Ticks: 2073064425
GPIO: 4 Level: 2 Ticks: 2074064677
GPIO: 4 Level: 2 Ticks: 2075065680
GPIO: 4 Level: 2 Ticks: 2076065682
GPIO: 4 Level: 2 Ticks: 2077066310
Correctly stopped alerts.
Program stopped gracefully.
2018-04-05 08:42:05 sigHandler: Unhandled signal 39, terminating
STATE CUE CARD: (? means a positive number, usually 1 or 2, * means any number)
0x0 - starting (GOOD, unless the thread is running managed code)
0x1 - running (BAD, unless it's the gc thread)
0x2 - detached (GOOD, unless the thread is running managed code)
0x?03 - async suspended (GOOD)
0x?04 - self suspended (GOOD)
0x?05 - async suspend requested (BAD)
0x?06 - self suspend requested (BAD)
0x*07 - blocking (GOOD)
0x?08 - blocking with pending suspend (GOOD)
--thread 0x19eeec0 id 0xb43db470 [(nil)] state 105
--thread 0xb4800480 id 0xb6a57470 [(nil)] state 1
--thread 0x190edd8 id 0xb6f10000 [(nil)] state 1 GC INITIATOR
WAITING for 1 threads, got 0 suspended
suspend_thread suspend took 200 ms, which is more than the allowed 200 ms
2018-04-05 08:42:05 sigHandler: Unhandled signal 6, terminating
Would you mind publishing the package to nuget? Otherwise projects which will make use of pigpio-dotnet will always contain hard copies of the whole project which in future will make it hard to keep them up to date
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Setup.GpioInitialise();
IO.GpioSetMode(SystemGpio.Bcm04, PinMode.Output);
var wf = new List<GpioPulse>();
wf.Add(new GpioPulse() { GpioOn = BitMask.Bit04, DurationMicroSecs = 9415 });
wf.Add(new GpioPulse() { GpioOff = BitMask.Bit04, DurationMicroSecs = 89565 });
var wid = (uint)Waves.GpioWaveAddGeneric((uint)wf.Count, wf.ToArray()); // crash here
Additional context
The error message:
Cannot marshal 'parameter #2': Unknown error."
What could be the cause? Am I doing something wrong?
When I try to use this library in windows, I get this error:
Unable to load DLL 'libpigpio.so' or one of its dependencies.
I can install Unosquare.PiGpio 0.0.1. But I can not install "Unosquare.PiGpio 0.0.2".
Error: Unable to install the “Unosquare.PiGpio 0.0.2” package. You are trying to install this package into a project, the required platform version of which is “.NETFramework, Version = v4.6.1”, but the package does not contain references to assemblies or content files compatible with this platform. Additional information can be obtained from the author of the package.
I've written a simple programm where IO.GpioSetAlertFunc is used. It works for a few seconds but then the error "Unhandled signal 11, terminating" happens.
I've noticed that the error doesn't happen if a pin whose value doesn't change is selected.
My code:
static void Main(string[] args)
{
ILogger log = LogManager.GetLogger(typeof(Program));
log.LogInformation("Start");
Setup.GpioInitialise();
IO.GpioSetAlertFunc(UserGpio.Bcm23, MyPiGpioAlertDelegate);
System.Console.ReadKey();
}
public static void MyPiGpioAlertDelegate(UserGpio userGpio, LevelChange levelChange, uint timeMicrosecs)
{
}
Add support for accessing pigpio via its daemon - no need for superuser rights and multiple applications can connect.
PR in progress.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.