Hi Guys,
Thanks for your response (Gary and Tri). I have re arranged and modified the code a bit and now it works as required
******CODE******
CLRIO NEXT_CALL
A$ = INPUT$(1) ' CHECK FOR DATA ON COMM PORT 1
IF LEN(A$)= 0
SETLCD 0,0,chr$(1) ' 1 SENT TO LCD WILL CLEAR SCREEN
SETLCD 0,1,CHR$(12) ' NO CURSOR
SETLCD 1,1, "NO TIMING MAP DATA"
B = B + 1 ' COUNTS NO DATA RECEIVED
ENDIF
IF LEN(A$) > 0 ' LOOK TO SEE IF RETURN STRING IS > 0
A = A + 1 ' COUNTS DATA RECEIVED
SETIO RX_LED_RELAY ' SET RX LED
B$ = MID$(A$, LEN(A$)-5, 4) ' COPY LAST FOUR BYTES (-5) AND NUMBER OF BYTES LONG
ENDIF
DM[1] = HEXVAL(B$) 'CONVERT RECEIVED DATA FROM HEX TO DEC
SETLCD 0,0,CHR$(1) ' 1 SENT TO LCD WILL CLEAR SCREEN
SETLCD 0,1,CHR$(12) ' NO CURSOR
SETLCD 1,1, "TIMING MAP = " +STR$(DM[1],2)
IF A = 0
SETIO TX_LED_RELAY ' SET TX LED
PRINT #1 "50002402000E00027A" ' ASK CCM FOR SPEED TIMING MAP 0 -255
ENDIF
IF
A > 0 ' WHEN NUMBER OF REPLIES = 1 MOVE ON TO NEXT CALL
SETIO NEXT_CALL
B = 0
A = 0
ENDIF
*******************
On another note... the following will not compile. I have tried many different permutation with () and "" but cannot get it right!!
PRINT #1 "50003402000E000DFF" + STR$(C$) +"50"
the C$ contains a hex variable I want to add to the string (F).
The other the problem is calculating the new checksum. In this case "50" is the check sum of the whole message. I use =CheckSum(xx) in excel to calculate the whole message CS but was wondering if it can be calculated in the PLC before sending?
Otherwise I could use a load of IF statements i.e
IF
C$ = xx
Print #1 "A"
ENDIF
IF
C$ = xx
Print #1 "B"
ENDIF
etc
Cheers