|
A
PC Interface for Hand-Held Devices
by Kock Kin Ko
Start
Creating GUI and Menu PC
Interface Software CVI Windows Programming
Basics Working Together
Plotting Performance Graphs How
Serial Com Operates Big Endian Data
Becomes Little Sources
HOW SERIAL COM OPERATES
The callback function Quitcom(),
shown in Listing 4, executes six functions:
GetCtrlVal() to read in the comport value selected by
user; OpenComConfig() to set up the COM port with parameter
2400 bps, 8N1, 512-byte queue size for input and output; DisplayRS232Error()
to display any error in setting up the COM port; SetComTime()
to set 5-s timeout limit on communication with hand-held unit; SetCtrlAttibute()
to turn the "Com Link SetUP" LED green; and InstallComCallback()
to enable comCallback() to intercept serial com events in real
time.
Listing 5
shows the function codes for send_password(), which further
executes the following functions: StringLength() to find out
the length of the password send_data; ComWrt() to write
the password to com port; SetCtrlAttribute() to turn the PassWordSent
LED to green color; and ReturnRS232Err() to check if any RS-232
errors occurred.
The
code for Show_count_down() is shown in Listing
6. The function displays the RxCountDown panel by InstallPopup(),
initializes remain_time to 5-s, displays the remain_time
value on the panel by executing SetCtrlVal(), and enables the
timer to tick by SetCtrlAttribute().
While the timer is on, Count_down(),
shown in Listing 6, intercepts the 0.25-s tick event and executes
the following codes: remain_time is reduced by 0.25 s; SetCtrlVal()
puts the updated remain_time value on the panel:, and when
remain_time is down-counted to zero, quit_count_down()
kills both the panel and the timer.
Listing 7
shows the code for receive_data(). It calls ComRdTerm()
to read the LF-terminated data from the COM port and load the data
into a buffer read_data, CopyString() to append a NULL
to the read_data, SetCtrlVal() to display the NULL-terminated
data on the main-panel textbox, ReturnRS232Err() to check for
RS-232 errors, and SetCtrlAttribute() to turn the main-panel
RxNewData LED green if no RS-232 errors are found.
PREVIOUS
NEXT
Circuit Cellar provides up-to-date information
for engineers. Visit www.circuitcellar.com
for more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe
online. ęCircuit Cellar, the Magazine for Computer Applications.
Posted with permission.
|