Пример #1
0
    def __init__(self, target, port=9000):
        super(OCUCommand, self).__init__(None)
        self.socket = QUdpSocket(self)
        self.socket.bind(QHostAddress('192.168.10.10'), port)
        self.port = port
        self.target = QHostAddress(target)

        self.emergency_led = 0
Пример #2
0
    def __init__(self, parent=None):
        super(BlockingClient, self).__init__(parent)

        self.thread = FortuneThread()
        self.currentFortune = ''

        hostLabel = QLabel("&Server name:")
        portLabel = QLabel("S&erver port:")

        for ipAddress in QNetworkInterface.allAddresses():
            if ipAddress != QHostAddress.LocalHost and ipAddress.toIPv4Address(
            ) != 0:
                break
        else:
            ipAddress = QHostAddress(QHostAddress.LocalHost)

        ipAddress = ipAddress.toString()

        self.hostLineEdit = QLineEdit(ipAddress)
        self.portLineEdit = QLineEdit()
        self.portLineEdit.setValidator(QIntValidator(1, 65535, self))

        hostLabel.setBuddy(self.hostLineEdit)
        portLabel.setBuddy(self.portLineEdit)

        self.statusLabel = QLabel(
            "This example requires that you run the Fortune Server example as well."
        )
        self.statusLabel.setWordWrap(True)

        self.getFortuneButton = QPushButton("Get Fortune")
        self.getFortuneButton.setDefault(True)
        self.getFortuneButton.setEnabled(False)

        quitButton = QPushButton("Quit")

        buttonBox = QDialogButtonBox()
        buttonBox.addButton(self.getFortuneButton, QDialogButtonBox.ActionRole)
        buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole)

        self.getFortuneButton.clicked.connect(self.requestNewFortune)
        quitButton.clicked.connect(self.close)
        self.hostLineEdit.textChanged.connect(self.enableGetFortuneButton)
        self.portLineEdit.textChanged.connect(self.enableGetFortuneButton)
        self.thread.newFortune.connect(self.showFortune)
        self.thread.error.connect(self.displayError)

        mainLayout = QGridLayout()
        mainLayout.addWidget(hostLabel, 0, 0)
        mainLayout.addWidget(self.hostLineEdit, 0, 1)
        mainLayout.addWidget(portLabel, 1, 0)
        mainLayout.addWidget(self.portLineEdit, 1, 1)
        mainLayout.addWidget(self.statusLabel, 2, 0, 1, 2)
        mainLayout.addWidget(buttonBox, 3, 0, 1, 2)
        self.setLayout(mainLayout)

        self.setWindowTitle("Blocking Fortune Client")
        self.portLineEdit.setFocus()
    def __init__(self, parent=None):
        super(BlockingClient, self).__init__(parent)

        self.thread = FortuneThread()
        self.currentFortune = ''

        hostLabel = QLabel("&Server name:")
        portLabel = QLabel("S&erver port:")

        for ipAddress in QNetworkInterface.allAddresses():
            if ipAddress != QHostAddress.LocalHost and ipAddress.toIPv4Address() != 0:
                break
        else:
            ipAddress = QHostAddress(QHostAddress.LocalHost)

        ipAddress = ipAddress.toString()

        self.hostLineEdit = QLineEdit(ipAddress)
        self.portLineEdit = QLineEdit()
        self.portLineEdit.setValidator(QIntValidator(1, 65535, self))

        hostLabel.setBuddy(self.hostLineEdit)
        portLabel.setBuddy(self.portLineEdit)

        self.statusLabel = QLabel(
                "This example requires that you run the Fortune Server example as well.")
        self.statusLabel.setWordWrap(True)

        self.getFortuneButton = QPushButton("Get Fortune")
        self.getFortuneButton.setDefault(True)
        self.getFortuneButton.setEnabled(False)

        quitButton = QPushButton("Quit")

        buttonBox = QDialogButtonBox()
        buttonBox.addButton(self.getFortuneButton, QDialogButtonBox.ActionRole)
        buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole)

        self.getFortuneButton.clicked.connect(self.requestNewFortune)
        quitButton.clicked.connect(self.close)
        self.hostLineEdit.textChanged.connect(self.enableGetFortuneButton)
        self.portLineEdit.textChanged.connect(self.enableGetFortuneButton)
        self.thread.newFortune.connect(self.showFortune)
        self.thread.error.connect(self.displayError)

        mainLayout = QGridLayout()
        mainLayout.addWidget(hostLabel, 0, 0)
        mainLayout.addWidget(self.hostLineEdit, 0, 1)
        mainLayout.addWidget(portLabel, 1, 0)
        mainLayout.addWidget(self.portLineEdit, 1, 1)
        mainLayout.addWidget(self.statusLabel, 2, 0, 1, 2)
        mainLayout.addWidget(buttonBox, 3, 0, 1, 2)
        self.setLayout(mainLayout)

        self.setWindowTitle("Blocking Fortune Client")
        self.portLineEdit.setFocus()
Пример #4
0
 def __init__(self, controller_ip='192.168.10.10',main_board_ip='192.168.10.170', mainboard_port='3030', sensor_board_ip='192.168.10.20', sensor_board_port='3032'):
     super(_ManiPulatorProtocol, self).__init__(None)
     self.direction = Direction()
     self.angularspeed = AngularSpeed()
     self.reset_motor = ResetMotor()
     self.home_position = HomePosition()
     self.emergency_stop = EmergencyStop()
     self.set_led = SetLED()
     # TO DO init should call from class
     self.init_sockets(controller_ip)
     self.main_board_ip = QHostAddress(main_board_ip)
     self.mainboard_port = int(mainboard_port)
     self.sensor_board_ip = QHostAddress(sensor_board_ip)
     self.sensor_board_port = int(sensor_board_port)
Пример #5
0
 def __init__(self):
     super().__init__()
     self.layout = QVBoxLayout()
     self.initUI()
     self.udpSocket = QUdpSocket()
     self.udpSocket.bind(QHostAddress('127.0.0.1'), 7111)
     self.udpSocket.readyRead.connect(self.readPendingDatagrams)
Пример #6
0
    def setUp(self):
        #Acquire resources
        self.called = False
        self.app = QCoreApplication([])

        self.socket = QUdpSocket()

        self.server = QUdpSocket()
        self.server.bind(QHostAddress(QHostAddress.LocalHost), 45454)
Пример #7
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self._tcp_server = QTcpServer(self)
        self._tcp_server.listen(QHostAddress('localhost'))
        self._tcp_server.newConnection.connect(self._handle_new_connection)

        self.port = self._tcp_server.serverPort()
        self.train = False
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent)

        self.server = FortuneServer()

        statusLabel = QLabel()
        statusLabel.setTextInteractionFlags(Qt.TextBrowserInteraction)
        statusLabel.setWordWrap(True)
        quitButton = QPushButton("Quit")
        quitButton.setAutoDefault(False)

        if not self.server.listen():
            QMessageBox.critical(
                self, "Threaded Fortune Server",
                "Unable to start the server: %s." % self.server.errorString())
            self.close()
            return

        for ipAddress in QNetworkInterface.allAddresses():
            if ipAddress != QHostAddress.LocalHost and ipAddress.toIPv4Address(
            ) != 0:
                break
        else:
            ipAddress = QHostAddress(QHostAddress.LocalHost)

        ipAddress = ipAddress.toString()

        statusLabel.setText("The server is running on\n\nIP: %s\nport: %d\n\n"
                            "Run the Fortune Client example now." %
                            (ipAddress, self.server.serverPort()))

        quitButton.clicked.connect(self.close)

        buttonLayout = QHBoxLayout()
        buttonLayout.addStretch(1)
        buttonLayout.addWidget(quitButton)
        buttonLayout.addStretch(1)

        mainLayout = QVBoxLayout()
        mainLayout.addWidget(statusLabel)
        mainLayout.addLayout(buttonLayout)
        self.setLayout(mainLayout)

        self.setWindowTitle("Threaded Fortune Server")
Пример #9
0
 def buttonClick(self):
     button = self.sender()
     if isinstance(button, QPushButton):
         text = f'Button {button.text()}'
         print('button click event from ' + button.text())
         self.line.setText('')
         #datagram = QNetworkDatagram(bytes(text, 'utf-8'), QHostAddress.LocalHost, 45454)
         #self.udpSocket.writeDatagram(datagram)
         datagram = QByteArray(bytes(text, 'utf-8'))
         self.udpSocket.writeDatagram(datagram, QHostAddress('127.0.0.1'),
                                      6010)
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent)

        self.server = FortuneServer()

        statusLabel = QLabel()
        statusLabel.setTextInteractionFlags(Qt.TextBrowserInteraction)
        statusLabel.setWordWrap(True)
        quitButton = QPushButton("Quit")
        quitButton.setAutoDefault(False)

        if not self.server.listen():
            QMessageBox.critical(self, "Threaded Fortune Server",
                    "Unable to start the server: %s." % self.server.errorString())
            self.close()
            return

        for ipAddress in QNetworkInterface.allAddresses():
            if ipAddress != QHostAddress.LocalHost and ipAddress.toIPv4Address() != 0:
                break
        else:
            ipAddress = QHostAddress(QHostAddress.LocalHost)

        ipAddress = ipAddress.toString()

        statusLabel.setText("The server is running on\n\nIP: %s\nport: %d\n\n"
                "Run the Fortune Client example now." % (ipAddress, self.server.serverPort()))

        quitButton.clicked.connect(self.close)

        buttonLayout = QHBoxLayout()
        buttonLayout.addStretch(1)
        buttonLayout.addWidget(quitButton)
        buttonLayout.addStretch(1)

        mainLayout = QVBoxLayout()
        mainLayout.addWidget(statusLabel)
        mainLayout.addLayout(buttonLayout)
        self.setLayout(mainLayout)

        self.setWindowTitle("Threaded Fortune Server")
Пример #11
0
def startServer(addr, port):

    if not checkIPIsValid(addr):
        return SERVER_ERROR_INVALID_ADDRESS

    if addr.upper() == "LOCALHOST":
        addr = QHostAddress(QHostAddress.LocalHost)
    else:
        addr = QHostAddress(addr)

    server = CommandServer()
    if not server.listen(addr, port):
        FreeCAD.Console.PrintLog("Unable to start the server: %s.\n" %
                                 server.errorString())
        return SERVER_ERROR_PORT_OCCUPIED

    else:
        FreeCAD.Console.PrintLog("The server is running on address %s" %
                                 server.serverAddress().toString() +
                                 " and port %d.\n" % server.serverPort())
        return server
Пример #12
0
def startServer(addr, port):
    """
Method used to try to start a `CommandServer` at a valid IP address and port.

This method checks that a chosen `addr` is valid IP address to be used to
create Qt's QHostAddress using `checkIPIsValid()`. If the IP address is valid,
then a `CommandServer` instance is created and tried to be made listen at
selected `addr` and `port`. If it fails, then the used port had to be occupied.

Args:
    addr: A str with a valid IPv4 Address or *"localhost"*.
    port: An int selecting a port to be used for the `CommandServer`.

Returns:
    An integer error code signifying that and error occurred(either
    `ERROR_INVALID ADDRESS` or `ERROR_PORT_OCCUPIED`) or a CommnadServer
    instance if everything went hunky-dory.
    """

    if not checkIPIsValid(addr):
        return SERVER_ERROR_INVALID_ADDRESS

    if addr.upper() == "LOCALHOST":
        addr = QHostAddress(QHostAddress.LocalHost)
    else:
        addr = QHostAddress(addr)

    server = CommandServer()
    if not server.listen(addr, port):
        FreeCAD.Console.PrintLog("Unable to start the server: %s.\n" %
                                 server.errorString())
        return SERVER_ERROR_PORT_OCCUPIED

    else:
        FreeCAD.Console.PrintLog("The server is running on address %s" %
                                 server.serverAddress().toString() +
                                 " and port %d.\n" % server.serverPort())
        return server
Пример #13
0
    def __init__(self, parent=None):
        super(NetworkConnectionClass, self).__init__(parent=parent)
        #self.CommandSocket = QTcpSocket()
        self.CommandSocket = QUdpSocket()
        self.CommandSocket.bind(QHostAddress("192.168.100.2"), 2323)
        self.CommandSocket.connected.connect(self.EventConnectedHandle)
        self.CommandSocket.readyRead.connect(self.RecieveData)

        #self.CommandSocket.connectToHost("192.168.100.5",2323,QIODevice.ReadWrite)
        #self.CommandSocket.connectToHost("127.0.0.1",2323,QIODevice.ReadWrite)
        #self.CommandSocket.connectToHost("192.168.20.196",2323,QIODevice.ReadWrite)
        #print("NETWORK - ",self.CommandSocket.localAddress(),self.CommandSocket.peerAddress())

        self.Display = WindowNetworkConnection()

        self.NetworkDataArray = QByteArray()
        self.NetworkDataArray.resize(2000)
        self.SignalDataRec.connect(self.Display.PrintData)

        self.BufferWrite = QBuffer(self.NetworkDataArray)
        self.BufferWrite.open(QBuffer.WriteOnly)

        self.BufferRead = QBuffer(self.NetworkDataArray)
        self.BufferRead.open(QBuffer.ReadOnly)

        self.ReadDataStream = QDataStream(self.BufferRead)
        self.ReadDataStream.setByteOrder(QDataStream.LittleEndian)

        self.WriteDataStream = QDataStream(self.BufferWrite)
        self.WriteDataStream.setByteOrder(QDataStream.LittleEndian)

        self.SocketDataStream = QDataStream(self.CommandSocket)
        self.SocketDataStream.setByteOrder(QDataStream.LittleEndian)

        self.Timer = QTime()
        self.Timer.start()

        self.BufferRead.seek(0)
        self.BufferWrite.seek(0)

        self.LimitBufferSize = 2000
        self.MinTransferUnit = 7
        self.MaxTransferUnit = 18
        self.bytesAvailable = 0
        self.Display.ui.pushButton.clicked.connect(self.SendData)

        #===================================================== WRITE BUFFER
        self.SendBuffer = QByteArray()
Пример #14
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     ping_message = create_message(SSDPInterface.ADDRESS, SSDPInterface.PORT, 2, SSDPInterface.SERVICE)
     self.broadcast_datagram = QNetworkDatagram(QByteArray(ping_message),
                                                QHostAddress(SSDPInterface.ADDRESS),
                                                SSDPInterface.PORT)
     self.udp_sockets = socks = []
     for host_address in QNetworkInterface.allAddresses():
         if host_address.isLoopback() or host_address.protocol() != QAbstractSocket.IPv4Protocol:
             continue
         sock = QUdpSocket(self)
         sock.bind(host_address, 50000)
         # lambdas will not work in this case as they are late binding.
         func = partial(self.packet_received, sock)
         sock.readyRead.connect(func)
         socks.append(sock)
         print(f"Connected to interface at host address: {host_address.toString()}")
Пример #15
0
 def onSocketReadyRead(self):
     msg = self.udpSocket.readDatagram(self.udpSocket.pendingDatagramSize())
     if msg[0][0:2] == "CB":
         msg_split = msg[0].split('|')
         device_id = msg_split[1].data().decode('ascii')
         device_version = msg_split[2].data().decode('ascii')
         now = datetime.datetime.now()
         ip = QHostAddress(msg[1].toIPv4Address()).toString()
         device = {"id": device_id, "version": device_version, "ip": ip, "last_seen": now}
         self.nodeListMutex.lock()
         if (device_id not in self.connectedNodes.keys()) and \
                 (device_id not in self.visibleNodes.keys()):
             self.visibleNodes[device_id] = device
             self.newNodeDiscovered.emit(device)
             print(f"discovered {device_id}")
         # update timestamps for known visible/connected devices
         if device_id in self.visibleNodes.keys():
             self.visibleNodes[device_id]["last_seen"] = now
             self.nodeAliveMessage.emit(self.visibleNodes[device_id])
         if device_id in self.connectedNodes.keys():
             self.connectedNodes[device_id]["last_seen"] = now
             self.nodeAliveMessage.emit(self.connectedNodes[device_id])
         self.nodeListMutex.unlock()
Пример #16
0
 def init_sockets(self,controller_ip):
     # self.socket_main_board = QUdpSocket(self)
     self.socket_sensor_board = QUdpSocket(self)
     self.socket_old_main_board = QUdpSocket(self)
     self.socket_sensor_board.bind(QHostAddress(controller_ip), 3037)
     self.socket_old_main_board.bind(QHostAddress(controller_ip), 3030)
Пример #17
0
import sys
import os.path
import json

from PySide2 import QtWidgets, QtCore
from PySide2.QtWidgets import QMessageBox, QFileDialog
from PySide2.QtUiTools import QUiLoader
from PySide2.QtNetwork import (QHostAddress)
from pyside_material import apply_stylesheet

from src import text_filter, log_window, session_data, type_filter, event_key, connect_state, event_dispatcher, \
    category_apply_window, category_window, log_server

CURRENT_PATH = os.path.dirname(os.path.join(os.path.abspath(sys.argv[0])))
SERVER_IP = QHostAddress(QHostAddress.LocalHost)
SERVER_PORT = 10001


class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        # load window
        self.ui = QUiLoader().load(
            os.path.join(CURRENT_PATH, "window_layout", "log_window.ui"))
        self.setCentralWidget(self.ui)

        # session log
        self.session_log = session_data.SessionLog()

        # server
        self.server = log_server.Server()
Пример #18
0
 def sendPackage(self):
     addr = QHostAddress(QHostAddress.LocalHost)
     self.socket.writeDatagram('datagram', addr, 45454)