# Revision history [back]

### How to fix the packet exchange between two devices?

I am trying to send the messages shown to the device with the IP address '10.5.33.16' from my pc '10.5.33.42'. The purpose of these commands is to try to get access to a value that the external device has, and I'm trying to receive it with my program with no such luck. Basically I am attempting to replicate the function of an application called Keysight Command Expert in my python program.

Expected packets: https://i.stack.imgur.com/7xeeW.png

Actual packets: https://i.stack.imgur.com/mgZ56.png

Python Code:

import socket

min_msg = ':CALCulate:MARKer:FUNCtion:TYPE MINimum'
exec_msg = ':CALCulate:MARKer:FUNCtion:EXECute'
y_msg = ':CALCulate:SELected:MARKer:Y?'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))

commands = [min_msg, exec_msg, y_msg]
i = 0
while(i<len(commands)):
s.send(bytes(commands[i],'utf-8'))
i += 1

try:
data = s.recv(4096).decode('utf-8')
if(len(data) > 0):
return True
else:
print("No blocking, but no data in packet.")
return False
except socket.timeout as e:
print(e)
return False
finally:
s.close()

pass
else:
raise Exception("Could not receive data.")


There are too many packets being exchanged, and the length is wrong for [PSH, ACK] command in the 'actual packets' image. My code is supposed to connect to a TCP socket, send the commands [min_msg, exec_msg, y_msg] then check if there is a response from the external device, '10.5.33.16'. If the no data is received or data is blocked, it stops. My final goal is for the packets received to match the 'Expected packets'.

### How to fix the packet exchange between two devices?

I am trying to send the messages shown to the device with the IP address '10.5.33.16' from my pc '10.5.33.42'. The purpose of these commands is to try to get access to a value that the external device has, and I'm trying to receive it with my program with no such luck. Basically I am attempting to replicate the function of an application called Keysight Command Expert in my python program.

Expected packets: https://i.stack.imgur.com/7xeeW.png

Actual packets: https://i.stack.imgur.com/mgZ56.png

Python Code:

import socket

min_msg = ':CALCulate:MARKer:FUNCtion:TYPE MINimum'
exec_msg = ':CALCulate:MARKer:FUNCtion:EXECute'
y_msg = ':CALCulate:SELected:MARKer:Y?'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))

commands = [min_msg, exec_msg, y_msg]
i = 0
while(i<len(commands)):
s.send(bytes(commands[i],'utf-8'))
i += 1

try:
data = s.recv(4096).decode('utf-8')
if(len(data) > 0):
return True
else:
print("No blocking, but no data in packet.")
return False
except socket.timeout as e:
print(e)
return False
finally:
s.close()

pass
else: