Read parallel port input pin from python Handler
07 Feb 2013 07:52 #29747
by amirhadar
Read parallel port input pin from python Handler was created by amirhadar
Hi,
I'm trying to understand how to read parallel port general purpose input pin from python glade gui handler class.
I want to write python program that reacts to input pins and perform operations.
Thanks,
Amir Hadar
I'm trying to understand how to read parallel port general purpose input pin from python glade gui handler class.
I want to write python program that reacts to input pins and perform operations.
Thanks,
Amir Hadar
Please Log in or Create an account to join the conversation.
07 Feb 2013 20:16 #29758
by amirhadar
Replied by amirhadar on topic Read parallel port input pin from python Handler
Hi,
I found the answer myself. I guess its a newbie question.
Two ways to do it:
Method One (a bit awkward):
Through using a led in the UI.
Define a HAL_LED on your panel in glade ui designer.
in custom_postgui.hal connect the input signal to the led
net input1 parport.0.pin-12-in-not => gladevcp.hal_led1
You can add signal handler to the led on_hal_led1_hal_pin_changed
Then add the python method to your handler class
Example:
def on_hal_led1_hal_pin_changed(self,hal_led1,data=None):
pin = hal_led1.hal_pin.get()
print "on_hal_led1_hal_pin_changed ",pin
Method Two (the right way):
In python handler file:
Add import:
import hal_glib
in the constructor of the class (__init__) add new pin definition for the panel hal component
# Define new pin with GPin (hal_glib) wrapper.
self.input_plate_pin = hal_glib.GPin(self.halcomp.newpin("input_plate",hal.HAL_BIT, hal.HAL_IN))
# connect the pin to a callback
self.input_plate_pin.connect('value-changed', self.on_input_plate_pin_value_changed)
# The callback itself:
def on_input_plate_pin_value_changed(self,input_plate_pin,data=None):
print "on_input_plate_pin_value_changed",input_plate_pin.get()
In the custom_postgui hal I have connected the input to both the led and the new pin
net input1 parport.0.pin-12-in-not => gladevcp.hal_led1 gladevcp.input_plate
Great Success!!!
Kind Regards,
Amir Hadar
I found the answer myself. I guess its a newbie question.
Two ways to do it:
Method One (a bit awkward):
Through using a led in the UI.
Define a HAL_LED on your panel in glade ui designer.
in custom_postgui.hal connect the input signal to the led
net input1 parport.0.pin-12-in-not => gladevcp.hal_led1
You can add signal handler to the led on_hal_led1_hal_pin_changed
Then add the python method to your handler class
Example:
def on_hal_led1_hal_pin_changed(self,hal_led1,data=None):
pin = hal_led1.hal_pin.get()
print "on_hal_led1_hal_pin_changed ",pin
Method Two (the right way):
In python handler file:
Add import:
import hal_glib
in the constructor of the class (__init__) add new pin definition for the panel hal component
# Define new pin with GPin (hal_glib) wrapper.
self.input_plate_pin = hal_glib.GPin(self.halcomp.newpin("input_plate",hal.HAL_BIT, hal.HAL_IN))
# connect the pin to a callback
self.input_plate_pin.connect('value-changed', self.on_input_plate_pin_value_changed)
# The callback itself:
def on_input_plate_pin_value_changed(self,input_plate_pin,data=None):
print "on_input_plate_pin_value_changed",input_plate_pin.get()
In the custom_postgui hal I have connected the input to both the led and the new pin
net input1 parport.0.pin-12-in-not => gladevcp.hal_led1 gladevcp.input_plate
Great Success!!!
Kind Regards,
Amir Hadar
Please Log in or Create an account to join the conversation.
Moderators: HansU
Time to create page: 0.083 seconds