PowerShell / PowerShell-IoT

Interact with I2C, SPI & GPIO devices using PowerShell Core!
https://www.powershellgallery.com/packages/Microsoft.PowerShell.IoT
MIT License
130 stars 28 forks source link

Added docs about WIRINGPI_CODES environment variable #37

Closed anmenaga closed 6 years ago

anmenaga commented 6 years ago

WiringPi library has a default behavior of terminating current process (e.g. PowerShell) even on non-critical errors in setup functions. For example:

pwsh will crash and throw the error Unable to select I2C device: Device or resource busy.

Get-I2CDevice -Id 911 #Or some other value that isn't valid
# pwsh will crash, throwing the error Unable to select I2C device: Invalid argument.

This PR adds doc instructions on how to avoid such crashes.

TylerLeonhardt commented 6 years ago

@anmenaga Did you try this:

[Environment]::SetEnvironmentVariable("WIRINGPI_CODES", "1", "Process")

Notice the Process scope.

https://msdn.microsoft.com/en-us/library/96xafkes(v=vs.110).aspx

tomlarse commented 6 years ago

This is probably related to #29 I guess?

TylerLeonhardt commented 6 years ago

@tomlarse indeed

TylerLeonhardt commented 6 years ago

Oops :)

anmenaga commented 6 years ago

@tylerl0706 Tried that, but it has no effect - wiringPi not picking it up. By the way, RaspberryIO library already has this line in its Initialize code, but no effect; I think I saw an issue on CoreCLR github about this.

TylerLeonhardt commented 6 years ago

So strange...

DanielSSilva commented 6 years ago

Even with this flag, this is still crashing with *** Error in `pwsh': free(): invalid pointer: 0x76c82694 ***

:( The worst part is that I can't understand when/why

TylerLeonhardt commented 6 years ago

@DanielSSilva can you add the code that's crashing here?

DanielSSilva commented 6 years ago

https://gist.github.com/DanielSSilva/ea2d5ddbaffa1ff5576622ea4543badd

It's easier to see here. Like I've said, it does not crash everytime...

anmenaga commented 6 years ago

@DanielSSilva This error is a signature of issue #29 . In short, there is a bug in error-handling routines of Unosquare.RaspberryIO library. WIRINGPI_CODES flag won't help with this; we actually need to fix RaspberryIO code.

@DanielSSilva please add your link to the issue #29 . It will help to keep everything related to this problem in one place. Thank you.