Line 124: |
Line 124: |
| ====Laptop Code for Robot/Laptop Base Communication ==== | | ====Laptop Code for Robot/Laptop Base Communication ==== |
| <source lang="Python"> | | <source lang="Python"> |
| + | # -*- coding: utf-8 -*- |
| + | #author: joel.martin |
| + | #import the modules required here |
| + | import PySimpleGUI as sg |
| import socket | | import socket |
− | message_from_server = ''
| + | |
− | client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | + | GRAPH_SIZE = (700,300) |
− | client.connect(('192.168.1.43', 13000)) | + | GRAPH_STEP_SIZE = 1 |
− | while True: | + | |
− | message = ''
| + | sg.change_look_and_feel('GreenMono') # give our window a spiffy set of colors |
− | message = input('enter any string to transmit:')
| + | |
− | client.send(message.encode())
| + | layout = [[sg.Text('Robot Message response', size=(30, 1))], |
− | message_from_server = (client.recv(4096)).decode()
| + | [sg.Output(size=(30, 20), font=('Mono 9')), |
− | print (message_from_server)
| + | sg.Graph(GRAPH_SIZE, (0,0), GRAPH_SIZE, key='-GRAPH-', background_color='lightblue')], |
− | if message == "Stop the Server" : break
| + | [sg.Text('Robot Command Entry', size=(30, 1))], |
− | client.close() | + | [sg.InputText(size=(30, 0), key='-QUERY-'), |
− | print ("You ended the session") | + | sg.Button('Send Command',size=(20,1), button_color=(sg.YELLOWS[0], sg.GREENS[0]), bind_return_key=True)], |
| + | [sg.Button('Halt Everything',size=(20,1), button_color=(sg.YELLOWS[0], sg.GREENS[0]))]] |
| + | |
| + | main_window = sg.Window('Robot Window Control', layout, font=('Helvetica', ' 11'), default_button_element_size=(8, 2)) |
| + | |
| + | #start executing here |
| + | if __name__ == '__main__': |
| + | |
| + | message_from_bot = '' |
| + | client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| + | client.connect(('192.168.1.132', 13000)) |
| + | escape = True |
| + | |
| + | while escape == True: |
| + | message_from_bot ='' |
| + | event, value = main_window.read() |
| + | if event == 'Halt Everything': |
| + | message_to_bot = "SRS" |
| + | client.send(message_to_bot.encode()) |
| + | break |
| + | if event == 'Send Command': |
| + | message_to_bot = value['-QUERY-'].rstrip() |
| + | client.send(message_to_bot.encode()) |
| + | |
| + | message_from_bot = (client.recv(4096)).decode() |
| + | print (message_from_bot) |
| + | if message_from_bot == "RxAck:Engaging Robot Shutdown" : escape = False |
| + | |
| + | main_window.close() |
| + | client.close() |
| + | print ("You ended the Robot Server Session") |
| </source> | | </source> |
| | | |