Hi,
I try to communicate with equipment through serial port.
It is slightly order equipment so it requires to send command in a specified format ends CHECKSUM (Like start with 'STX' and end with 'ETX' etc and the command looks something like '020T025F00R000000000000000').
Issue with Python:
For my case they have given the code in TURBO PASCAL to calculate check sum. I copied that code here (sorry to tell, I don't know Turbo Pascal )
But with my limited knowledge I convert in to python ( pls see the code below the Pascal code)
Could anyone help to solve the problem? Also could you please confirm the Python code is right?
Issue with serial programming:
In equipment manual gave an information about sending string and corrosponding answer string:
sending string format is --> {STX}1?CS{ETX}
STX is Start of text and ETX is the end of text. it corospondingli 02 and 03
1 stands for port address
CS stands for checksum (calculated using the above code)
I send string to serial port in the above sending strinng format, but not getting a answer string back from equipment.
Could somebody help on my issue
Thanks in advance...Appreciate reply...
##Code is in Turbo Pascal
FUNCTION CHECKSUM
(TESTER STRING): STRING;
VAR L, I :INTEGER;
B,J,K :BYTE;
CH :STRING[1];
BEGIN
L :=LENGTH(TESTSTR);
B :=0;
FOR I := 1 TO L DO BEGIN
CH := COPY(TESTSTR,I,1);
J := ORD(CH[1]);
B := B-J;
END;
J := B DIV 16;
IF J<10
THEN J:=J+48
ELSE J:= J+55;
K :=B MOD 16;
IF K<10
THEN K:= K + 48
ELSE K:= K + 55;
CHECKSUM:= CHR(J) + CHR(K);
END;
Converted to Python code
tempset = '020T025.0FR00R0000000000000000'
def checksum(tempset):
b = 0
for ch in tempset:
j = ord(ch)
b = (b - j) & 255
j = (b /16)
if j<10:
j = j + 48
else:
j = j+ 55
k = (b % 16)
if k < 10:
k = k + 48
else:
k = k + 55
return chr(j) + chr(k)
print checksum(tempset)