PDA

View Full Version : Is there a neater way to do this



timmers
- 7th September 2015, 22:34
I am revising some old code and was wondering if there was an easier way to do this

PARAM1 VAR WORD
PARAM2 VAR WORD
COMMAND VAR BYTE
TX_BUFF VAR BYTE [20]
LEN VAR BYTE

Old code


IF PARAM1.15 THEN
PARAM1 = ABS PARAM1
SerOut2 TX,6, ["SU ", #COMMAND, " -", #PARAM1]
ELSE
SerOut2 TX,6, ["SU ", #COMMAND, " ", #PARAM1]
ENDIF

IF PARAM2.15 THEN
PARAM2 = ABS PARAM2
SerOut2 TX,6, [" -", #PARAM2]
ELSE
SerOut2 TX,6, [" ", #PARAM2]
ENDIF



Same code but into an array so I can then send by using
HSEROUT [STR TX_BUFF\ LEN]

Is there an easy way to build the array and keep track of the length (LEN)

Thanks for looking,
Tim.

richard
- 7th September 2015, 23:01
arraywrite TX_BUFF,["SU ", #COMMAND, sdec PARAM1,0]



if you look for the null termination chr then you may not need to know the length or write a subby to determine the length if you have to

HenrikOlsson
- 8th September 2015, 19:55
Hi,
Yes, as Richard has shown the SDEC modifier is what you're looking for to get rid of the IF/ELSE/ENDIF stuff but I don't quite understand why you need to build the string, put into an Array and then send it with HSEROUT. Do you need it in the Array for some other purposes? If not, then simply

HSEROUT ["SU ", #COMMAND, " ", SDEC PARAM1]


I'm sure the length of the array, after an arraywrite CAN be extracted from an internal system variable (if done directly after the Arraywrite) but I don't know which. Would need to do some investigation to find out. But again, I don't see the need.

/Henrik.