Preview Tab

More
13 Aug 2020 07:45 #178082 by cmorley
Replied by cmorley on topic Preview Tab
After a quick trial with zmq, it is really easy set up to work between two programs.
I had a small python program changing QTLathe's g20/21 mode every second, by calling a function already inside it's handler file.
I'd recommend exploring it.
The following user(s) said Thank You: phillc54

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

More
13 Aug 2020 17:10 #178118 by newbynobi
Replied by newbynobi on topic Preview Tab
Hallo Chris, can you post your sample code. It is the best way to beginn with stolen code;)

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

More
13 Aug 2020 17:40 #178119 by cmorley
Replied by cmorley on topic Preview Tab
Sure - keeping in mind this has some specific QT code - i'll try to point it out.
The first function initializes listening for messages.
The second gets the raw message, converts it from json object to python object.
The function name and arguments are extracted and then the function is called.
import zmq
import json

    def init_zmq(self):
            self._zmq_context = zmq.Context()
            self._zmq_sock = self._zmq_context.socket(zmq.SUB)
            self._zmq_sock.connect("tcp://127.0.0.1:5690")
            self._zmq_sock.setsockopt(zmq.SUBSCRIBE, self._zmq_suscribe_name)

            # this part qt stuff. It watches the ZMQ socket and calls a function when a message comes.
            self.read_noti = QtCore.QSocketNotifier(self._zmq_sock.getsockopt(zmq.FD),
                                                 QtCore.QSocketNotifier.Read, None)
            self.read_noti.activated.connect(self.on_read_msg)

    def on_read_msg(self):
        self.read_noti.setEnabled(False) # temporarily stop Qt socket watching
        if self._zmq_sock.getsockopt(zmq.EVENTS) & zmq.POLLIN:
            while self._zmq_sock.getsockopt(zmq.EVENTS) & zmq.POLLIN:
                # get raw message
                topic, data = self._zmq_sock.recv_multipart()
                # convert from json object to python object
                y = json.loads(data)
                # get the function name
                function = y.get('FUNCTION')
                # get the arguments
                arguments = y.get('ARGS')
                print('{} Sent ZMQ Message:{} {}'.format(topic,function,arguments))

                # call handler function with arguments
                try:
                     self.[function](*arguments)
                except Exception as e:
                    print('zmq message parcing error: {} failed.'.format(e))
        elif self._zmq_sock.getsockopt(zmq.EVENTS) & zmq.POLLOUT:
            print("[Socket] zmq.POLLOUT")
        elif self._zmq_sock.getsockopt(zmq.EVENTS) & zmq.POLLERR:
            print("[Socket] zmq.POLLERR")
        self.read_noti.setEnabled(True) # resume QT socket watching

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

More
13 Aug 2020 17:44 - 13 Aug 2020 23:13 #178120 by cmorley
Replied by cmorley on topic Preview Tab
here is the sending sample program:
it calls the function 'zmq_function' with the arguments (bool,int)
obviously that function must be available.
but you can call any function available to the message receiver this way.
#!/usr/bin/env python
from time import sleep

import zmq
import json

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://127.0.0.1:5690")

# prebuilt message 1
x = {
  "FUNCTION": "zmq_function",
  "ARGS": [True,100]
}
m1 = json.dumps(x)

# prebuilt message 2
x = {
  "FUNCTION": "zmq_function",
  "ARGS": [False,200],
}
m2 = json.dumps(x)

if __name__ == '__main__':
    while True:
        print 'send True'
        socket.send_multipart(
            [b'GMP', bytes((m1).encode('utf-8'))])
        sleep(ms(1000))

        print 'send false'
        socket.send_multipart(
            [b'GMP', bytes((m2).encode('utf-8'))])
        sleep(ms(1000))
Last edit: 13 Aug 2020 23:13 by cmorley.

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

More
13 Aug 2020 17:48 #178122 by cmorley

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

More
13 Aug 2020 17:51 #178123 by cmorley
Replied by cmorley on topic Preview Tab
Or you could convert Gmoccapy to use Qtvcp :)

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

More
14 Aug 2020 05:18 #178156 by newbynobi
Replied by newbynobi on topic Preview Tab
@Chris,

Thanks for the example, I will take a closer look to that solution.

I thought about converting gmoccapy to QtVCP. I tried several times to get the developers version instlled. I did never get to the end, due to missing files, dependencies etc. So I gave up. I will try again, after the next ISO to install on a recent OS. I do not know, if QtVCP does use already Python 3 or not. If it does not use python 3, I will not invest any time on that, as modern OS do not support python 2 any more.

And yes, I do know, that gmoccapy is also based on a python 2 development kit. I have already done some work to convert to python3, but I stopped it to wait and see where the future development will go.

Norbert

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

More
14 Aug 2020 06:25 #178165 by cmorley
Replied by cmorley on topic Preview Tab
yes qtvcp is currently python2 - as soon as 2.8 is released i will put the effort into converting to python3. I was the same - I partially converted (way back) to python3 then discovered the problem with that... :)

I just installed buster on a machine so can start working on that soon.

as for the Designer dependency problem usually it was because people had both python2 and python3 designer libraries on their machine and it would run the wrong one.

Chris

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

More
14 Aug 2020 08:07 - 14 Aug 2020 08:08 #178175 by newbynobi
Replied by newbynobi on topic Preview Tab
I think we should not put too much affort for converting that in 2.8, but put all effort for converting to python 3 in 2.9
I will support gmoccapy 3.XX for 2.8 and think I will start with a new GUI on 2.9, all based on Qt and Python 3. Rene-Dev has done already a lot of work converting parts of LinuxCNC to pythIon 3. He has an own branch for that, (as far as I remeber)

I will meet him mid August and talk to him about his ideas. After that I will make a layout for a new GUI (minosch = Maschine Interface Norbert Schechner) hoping the new name would be easier to pronounce in the hole world ;-)

I hope we find a way to work all together than to get thinks done.

Norbert
Last edit: 14 Aug 2020 08:08 by newbynobi.
The following user(s) said Thank You: tommylight, Clive S

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

More
14 Aug 2020 10:41 #178178 by rodw
Replied by rodw on topic Preview Tab

newbynobi wrote: After that I will make a layout for a new GUI (minosch = Maschine Interface Norbert Schechner) hoping the new name would be easier to pronounce in the hole world ;-)


I thought you said mishmosh for a moment there :)
www.dictionary.com/browse/mishmosh

There are a few things that annoy me with Gmoccapy GUI with my plasma machine so when you are ready be sure to ask for feedback. I get tired swapping between tabs. With larger screens, it would be nicer to have a flatter GUI.

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

Moderators: newbynobi
Time to create page: 0.112 seconds
Powered by Kunena Forum