Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pigpio.initialize() doenst do its job after pigpio.terminate() #34

Closed
joshi11 opened this issue Sep 18, 2017 · 4 comments
Closed

pigpio.initialize() doenst do its job after pigpio.terminate() #34

joshi11 opened this issue Sep 18, 2017 · 4 comments

Comments

@joshi11
Copy link

joshi11 commented Sep 18, 2017

I have a situation in which I use pigpio in Node and in native C
Thus I need to call pigpio.terminate() in Node before I can call pigpio in C otherwise C complains about not getting the lock on the pid.
When I then try to call pigpio.initialize in Node again it doesnt seem to work since I get the message:

calling initialize
Hardware Revision: 9000c1
initialized= 1
2017-09-17 18:45:59 gpioSetMode: pigpio uninitialised, call gpioInitialise()


var initialized;
var pigpio = require('pigpio')
var Gpio=pigpio.Gpio

 exports.test = function(led_nr, dutyCycle) {	
	if (!initialized)	{
		console.log("calling initialize");
		pigpio.initialize(); // pigpio C library initialized here
		initialized=1;
		console.log('Hardware Revision: ' + pigpio.hardwareRevision().toString(16));
		test_led(led_nr, dutyCycle);   
	}
	else 
		test_led(led_nr, dutyCycle);    //called function to make sure I dont get race conditions
	
	
};	

exports.terminate = function() {
	console.log("initialized= " + initialized);
	if (initialized)	{
		pigpio.terminate(); // pigpio C library terminated here
		initialized=0;
		console.log("initialized= " + initialized);
		console.log('Terminated');
	}	//end if
};//end terminate

    function test_led(led_nr, dutyCycle)	{
	console.log("initialized= " + initialized);
	led = Gpio(led_nr, {mode: Gpio.OUTPUT}); 
	
	led.pwmRange(100)
	led.pwmWrite(dutyCycle);
}

Versions:

pigpio: "_id": "pigpio@0.6.1",
node v6.11.3

I expirience no problems with the C version of the pigpio library - hence I would assume its an issue with the wrapper.

@fivdi
Copy link
Owner

fivdi commented Sep 18, 2017

Does it work if the following code in pigpio.js is modified from:

module.exports.terminate = function () {
  pigpio.gpioTerminate();
};

to:

module.exports.terminate = function () {
  pigpio.gpioTerminate();
  initialized = false;
};

@joshi11
Copy link
Author

joshi11 commented Sep 18, 2017

Yes!!!
Thank you!

@joshi11 joshi11 closed this as completed Sep 18, 2017
@fivdi
Copy link
Owner

fivdi commented Sep 18, 2017

Ok, thanks for the feedback.
I'll release a new version on npm with a fix as soon as possible.

@fivdi fivdi reopened this Sep 18, 2017
@fivdi
Copy link
Owner

fivdi commented Sep 18, 2017

Fixed by 1f745d2 in pigpio@0.6.2.

@fivdi fivdi closed this as completed Sep 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants