
Page 4
eWON500™
The Programmable Gateway
ver 1.0
9/11/05
User Guide
Question/Answer Protocol
Below are detailed the steps required to code a program sending a “question” on the serial port and waiting for
an “answer”:
1 Serial port initialization gosub InitSerial_QA
2Sendingaquestion Q$=”CMD”:gosub SendQuestion
3 Waiting for a delay tset 4,2 + ontimer
4 Reading the answer+displaying goto ReadAnswer
5goto2
Rem --- eWON start section: SERIAL_QA
Rem --- eWON user (start)
InitSerial_QA:
Open "com:1,9600,8n1n" For Binary Input As 1
ontimer 1,"goto Question"
tset 1,10
return
CloseSerial:
Close 1
return
Question:
Q$ = "??"+chr$(13)
gosub SendQuestion
end
SendQuestion:
rem flush the serial input buffer
A$ = GET 1
A$=""
rem send the Question Q$ to serial
put 1,Q$
rem Wait 2 seconds before read the input buffer
rem set a timer handler and a timer of 2 seconds
Ontimer 4,"goto ReadAnswer"
tset 4,2
return
ReadAnswer:
rem stop the timer4
tset 4,0
rem read the serial input
A$ = GET 1
rem process the Answer
a% = len(A$)
print time$;" RxLen: ";a%
print "Rx: ";A$
SerialTag@ = VAL(A$)
end
Rem --- eWON user (end)
End
COM ports special features:
- always 'binary'
The serial ports are always Input/Output even when
opened with Input (input/output does not exist)
Initialiazing a timer to send the Question every 10
seconds
End of the initialization process (QA mode)
Question = “??” + CR
We first empty the read buffer prior to send the question
The question is sent on the serial port
Initializing a timer to wait for the answer
Stop the timer to read only once when timer expires
Reading the entire input buffer (default: 2048 bytes max)
Displaying the answer in ScriptControl
If the answer represents a numeric value, it has to be
converted prior to be assigned to a Tag
To test this Program, insert a Gosub InitSerial_cont in the init_section.