Parameter checking
Sarah Reichelt
sarahr at genesearch.com.au
Mon Jul 4 22:05:47 EDT 2005
Hi All,
I have a stack that contains a set of commands for talking to a
serial device. The commands & functions all get a set of parameters,
each with only one character. The characters vary: some parameters
are numeric, some alphabetic. The ranges vary, so one parameter could
be any letter from A to N while another can be either J, T or E.
Numeric parameters have allowed ranges also. As you can imagine,
sending the wrong info to the serial box causes big problems.
What I am thinking of doing is writing a general parameter checker,
so I can send it each parameter, plus some string defining what is
allowed. If it returned an error, then I would refuse to send the
command to the serial box.
Firstly, has anyone done anything like this? If so, would they be
prepared to share the code or some of their ideas.
Secondly, has anyone any suggestions of the best way to do this? I
can do it in a long-winded manner, but I feel sure that some RegEx
wizard (Ken, are you listening), would be able to come up with a
really neat way to solve this.
Here is pseudo-code is what I want to do:
on sendSerialCommand p1, p2, p3
-- p1 must be A-P or a-p
if paramError(p1,"A-P|a-p") then exit to top
-- p1 must be a number from 1 to 8
if paramError(p2,"1-8") then exit to top
-- p1 must be either S or D
if paramError(p3,"S|D") then exit to top
sendSerialString p1 & p2 & p3
end sendSerialCommand
TIA,
Sarah
More information about the use-livecode
mailing list