How to modify, and use Hal_ LED color

More
10 Aug 2021 01:46 #217354 by yi2580
I am using Python and GTK to write a GUI interface. Now I want to use an LED light in the interface to display a signal transmitted from the IO serial port. What should I do? This problem has plagued me for a long time and has not been solved. I hope someone can help me
thank you

Please Log in or Create an account to join the conversation.

More
10 Aug 2021 02:01 #217355 by yi2580
I use the Hal LED component in Hal python. I want to modify its color in the interface and how I should use it. For example, when a signal comes in, it changes from green to red.

Please Log in or Create an account to join the conversation.

More
10 Aug 2021 02:16 #217359 by cmorley
Are you using GLADE editor for the GUI or coding the GUI with python?
This gives some details about the LED widget:
linuxcnc.org/docs/devel/html/gui/gladevcp.html#gladevcp:hal-led

Usually on would set the colors in the GLADE file but you can also use properties in python:

[widget name].set_property("on_color","blue")

Please Log in or Create an account to join the conversation.

More
10 Aug 2021 02:49 #217362 by yi2580
Hello, thank you very much for your reply
I use the glade editor as the GUI. After reading the links you sent, I have a general understanding, but how can I establish a relationship between my trigger signal and the lighting of the LED?

Please Log in or Create an account to join the conversation.

More
10 Aug 2021 02:54 #217364 by cmorley
If you trigger signal is HAL based:
Make sure the 'create_hal_pin' property is true and then a HAL pin will be made that you can connect to and control the LED

otherwise use the python code:
[widgetname].set_active(True)

Please Log in or Create an account to join the conversation.

More
10 Aug 2021 04:53 #217369 by yi2580
Hello!
I used your code, but he gave me the error
"    pin0.set_active(On)
NameError: global name 'pin0' is not defined"
I'm not sure how to define pin0
on_ pinb_ Clicked is my button
Pin0 is the name of my Hal LED light
Attachments:

Please Log in or Create an account to join the conversation.

More
10 Aug 2021 05:02 #217372 by cmorley
you would need to post the whole python file so i can see what you are doing.

Please Log in or Create an account to join the conversation.

More
10 Aug 2021 05:19 #217373 by yi2580
Hello!
The whole Python file may be a little big. I'll send the Python code I'm using now. Please help me have a look,
  def on_pinb_clicked(self,widget, data=None):
    print'pinb'
    pin0.set_active(True)
The picture below is my glade interface
What I want to do is that I click the button and the LED light will change color, or a signal defined in Hal can change the LED color. I don't know how to do it. I don't quite understand how to configure my Hal file to make the LED color change, or how to program in Python
Thank you very much for taking the trouble to answer my questions。
Attachments:

Please Log in or Create an account to join the conversation.

More
10 Aug 2021 05:39 #217375 by cmorley
You are making it difficult for me to help you.
I need to see your python file so I can see what code to use to reference the pin0
usually it's something like:

self.builder.get_object("pin0').set_active(True)

But there are other ways to reference widgets.

Please Log in or Create an account to join the conversation.

More
10 Aug 2021 05:48 #217376 by yi2580
Oh, thank you very much for your answer. I haven't quoted pi0. It may be ridiculous. Now it's OK,
Thank you very much for answering my questions. You make me enlightened

Please Log in or Create an account to join the conversation.

Moderators: HansU
Time to create page: 0.120 seconds
Powered by Kunena Forum