Cannot get reply from a CimPak300 print & apply equipment, from Markem Imaje, using CimComms communication protocol. I can connect with the equipment on Ethernet, using sockets, I send messages but it doesn't respond. Maybe I'm doing something wrong when sending the message to the equipment.
So I'm using Python 3.9.4 and here is my test script:
import socket
# function to calculate header checksum
def head_check(frame_header):
frame_header_lenght = len(frame_header)
i = 0
hexintdata = []
while i < frame_header_lenght:
j = i + 2
hexintdata.append(hex(int(frame_header[i:j], 16)))
i += 2
sum = 0
for j in hexintdata:
k = int(j, 16)
sum = sum + k
ffvalue = 0xff
checksum = ffvalue - sum
checksum_decoded = hex((checksum + (1 << 32)) % (1 << 32))
header_checksum = checksum_decoded[-2:]
return header_checksum
labeler_connect_status = False
# starting a socket object and connect to CimPak300
s = socket.socket()
while True:
if not labeler_connect_status:
try:
s.connect((TCP_IP, TCP_PORT))
labeler_connect_status = True
print('CONNECTED!')
except Exception as e:
print(f'ERROR_LOG_LABELER: {e}')
labeler_connect_status = False
# send data to labeler
h_data = input('Insert message in hex (q for quit): ')
if h_data == 'q':
s.close()
break
else:
h_checksum = head_check(h_data)
print(f'Calculating header checksum: {h_checksum}')
h_data = h_data + h_checksum
b_data = bytes.fromhex(h_data)
print(f'Data in bytes: {b_data}')
print('Sending message to labeler...')
s.send(b_data)
print('Data sent!')
print('waiting for response...')
message = s.recv(1024)
dec = message.hex()
print(f'Response: {dec}')
print(f'Message: {message}')
I test the data I send with Hercules and it seems right to me, but the P&A system doesn't reply. I try with poll for request message and with other messages with header only.
"The Host uses this command to determine if a printer requires information. The Host is always themaster. The individual printers will not broadcast any data over the network unless they are asked to do so. This may cause a problem when the printer requires information from the Host. To overcome this, the Host should send a ‘Poll for Request’ message approximately every ½ second. The printer treats this message as a “Do you require anything?” message. The Poll for Request message is:
<01hex> SOH - Start Character.
<81hex> Printer Node Number.
<A0hex> Poll for Request
<0> Data section length is 0
<0>
<Header Checksum> Single byte header checksum. See section 5.1.
If the printer needs something, it will respond with the appropriate message. For instance, if it requires a file, it will respond with a ‘Request File Transfer’ message (A3hex)). If it requires nothing then it will respond with an ‘Acknowledge’ message (A1hex)."
- from CimComms documentation
What I'm doing wrong here?