Вы находитесь на странице: 1из 91

Smartphone for Children with Diabetes University of Birmingham

Xiaojia Jiang

BEng Final Year Project


Smartphone for Children with Diabetes

Final Report

Xiaojia Jiang
Student ID:830127
Supervisor:Dr. S. I. Woolley

I
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

SCHOOL OF ELECTRONIC & ELECTRICAL ENGINEERING

BEng Final Year Project


Smartphone for Children with Diabetes

Final Report

Xiaojia Jiang
Student ID:830127
Supervisor:Dr. S. I. Woolley

II
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Final Year Project


Abstract
An innovative smartphone application for children with diabetes was implemented in
this project. This paper presents the development and implementation of this
electronic medical assistant for self monitoring. The prototype smartphone device
includes the following functions:
z Personal Medical Record Information Provider
z Insulin Injection Reminder
z Children’s Diabetic Education
z Emergency Contact
z Real-time Glucose Meter Reading by Bluetooth
and smart feedback of data. More detailed
graphical displays of data could be provided by
the mobile phone for controlling the insulin dose
and modifying diet and exercise.
The system was programmed in Visual basic. Net and has been evaluated in the tests.

Acknowledgements
I would like to extend my sincere thanks and gratitude to the following people who
had supported me throughout the duration of this project.
Firstly I would like to thank Dr. Sandra Woolley for her advices and guidance. She
spent her valuable time for helping me in every crucial stage of my project, and she
also gave her strongest encouragement to me.
I am particularly grateful for the comments and suggestions my assessors gave to me
during the bench inspections. Prof. Bob Stone and Dr. Shiraz gave their best
feedbacks to improve my project.
Last but not the least, I would like to thank all the people who gave me support during
the development of hardware and who tried my application, answered the
questionnaires.

III
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Table of Contents
1. INTRODUCTION ---------------------------------------------------------------------------------1

1.1 DESIGNING BREIF ---------------------------------------------------------------------------- 1

1.2 BASIC MODEL ---------------------------------------------------------------------------------- 2

2. BACKGROUND RESAERCH AND LITERATURE SURVEY ---------------------------3

2.1 DIABETES IN CHILDREN --------------------------------------------------------------------3

2.2 TELEMEDICINE SYSTEM ------------------------------------------------------------------- 3

2.3 BLUETOOTH TECHNOLOGY --------------------------------------------------------------- 4

2.4 CURRENT RESEARCH AND SYSTEMS -------------------------------------------------- 5

2.4.1 PERVASIVE COMPUTING RESEARCH ----------------------------------------------5

2.4.2 DIABETIC INFORMATION APPLIANCE -------------------------------------------- 6

2.4.2 ONE TOUCH DIABETETES MANAGEMENT SOFTWARE ----------------------7

2.4.3 MOBILE DIABETES MANAGEMENT ----------------------------------------------- 7

3 INNOVATIONS -------------------------------------------------------------------------------------- 8

4 PROPOSED SYSTEM SPECIFICATIONS --------------------------------------------------- 9

5 HARDWARE ---------------------------------------------------------------------------------------- 10

5.1 BLOOD GLUCOSE METER ----------------------------------------------------------------- 10

5.1.1 AIM ------------------------------------------------------------------------------------------ 10

5.1.2 THE CHOSEN PRODUCT DESCRIPTION ----------------------------------------- 10

5.1.3 METER’S RS-232 COMMUNICATION PROTOCOL ----------------------------- 10

5.2 BLUETOOTH- RS232 ADAPTER ---------------------------------------------------------- 12

5.2.1 AIM ----------------------------------------------------------------------------------------- 12

5.2.2 THE CHOSEN PRODUCT DESCRIPTION ----------------------------------------- 12

5.3 SMARTPHONE -------------------------------------------------------------------------------- 14

5.3.1 AIM ----------------------------------------------------------------------------------------- 14

5.3.2 THE CHOSEN PRODUCT DESCRIPTION ----------------------------------------- 14

6 INTERFACE SMARTPHONE – BLUETOOTH RS232 ADAPTER -------------------- 15

6.1 AIM ----------------------------------------------------------------------------------------------- 15

6.2 CONNECTION BETWEEN ADAPTER AND SMARTPHONE ----------------------- 15

IV
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

6.2.1 SET UP THE PARTNERSHIP --------------------------------------------------------- 15

6.2.2 SET THE VIRTUAL SERIAL PORT ------------------------------------------------- 16

7 INTERFACE GLUCOSE METER – BLUETOOTH RS232 ADAPTER -------------- 17

7.1 AIM ---------------------------------------------------------------------------------------------- 17

7.2 COMPONENTS ------------------------------------------------------------------------------- 18

7.3 RS232 COMMUNICATION ----------------------------------------------------------------- 18

7.4 TECHNICAL CHALLENGES --------------------------------------------------------------- 19

7.4.1 DESCRIPTION --------------------------------------------------------------------------- 19

7.4.2 DCE-DCE COMMUNICATION SOLUTION --------------------------------------- 21

7.4.3 METHOD ---------------------------------------------------------------------------------- 22

8 METER-ADAPTER-SMARTPHONE DATA TRANSMISSION ------------------------ 22

8.1 AIM ----------------------------------------------------------------------------------------------- 22

8.2 RESULT ----------------------------------------------------------------------------------------- 24

8.2.1 PORT SETTING INTERFACE --------------------------------------------------------- 24

8.2.2 SENDING COMMAND TO THE METER ------------------------------------------- 24

9 SMARTPHONE PLATFORM ------------------------------------------------------------------- 27

9.1 AIM ----------------------------------------------------------------------------------------------- 27

9.2 DESIGN CONSIDERATION ----------------------------- ----------------------------------- 27

9.2.1 SPECIFIC USER GROUP --------------------------------------------------------------- 27

9.2.2 SPECIFIC MOBILE PLATFORM ----------------------------------------------------- 28

9.3 IMPLEMENTATIONS ------------------------------------------------------------------------- 29

9.3.1 IMPLEMENTATION 1: MEDICAL ALERT ----------------------------------------- 29

9.3.1.1 FUNCTION1: PROVIDING MEDICAL INFORMATION ------------------- 29

9.3.1.2 FUNCTION2: INSULIN INJECTION REMINDER --------------------------- 30

9.3.1.3 FUNCTION3: EMERGENCY CONTACT --------------------------------------- 30

9.3.2 IMPLEMENTATION 2: DIABETIC EDUCATION --------------------------------- 31

9.3.2.1 FUNCTION4: READING BOOKS ----------------------------------------------- 31

9.3.2.2 FUNCTION5: PLAYING GAMES ----------------------------------------------- 32

9.3.2.3 FUNCTION6: READING EVERYDAY TIP ------------------------------------ 33

V
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

9.3.3 IMPLEMENTATION 3: TEST DATA INTERPRETATION ----------------------- 33

9.3.3.1 FUNCTION7: GRAPHICAL FEEDBACK ------------------------------------- 33

9.3.3.2 FUNCTION8: SMART ANALYSIS ---------------------------------------------- 36

10 TESTING ------------------------------------------------------------------------------------------- 37

10.1 FUNCTIONALITY TEST ------------------------------------------------------------------- 37

10.2 USABILITY TEST --------------------------------------------------------------------------- 39

10.2.1 USABILITY ----------------------------------------------------------------------------- 39

10.2.2 USABILITY EVALUATION ---------------------------------------------------------- 39

11 FUTURE WORK ---------------------------------------------------------------------------------- 41

12 CONCLUSION ------------------------------------------------------------------------------------ 41

13 REFERENCE -------------------------------------------------------------------------------------- 42

APPENDIX A: USABILITY EVALUATION QUESTIONNAIRE ------------------------- 45

APPENDIX B: VISUAL BASIC CODE ----------------------------------------------------------- I

VI
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

List of Figures

Figure 1: The schematic telemedicine system --------------------------------------------------------1

Figure 2: Data transmission model ---------------------------------------------------------------------2

Figure 3: Technology options for homecare ----------------------------------------------------------5

Figure 4: AwareMedia -----------------------------------------------------------------------------------6

Figure 5: Awarephone -----------------------------------------------------------------------------------6

Figure 6: A schematic view of OneTouch Diabetes Management Software ---------------------7

Figure 7: Adapter’s DB-9 Female Connector Pin-out ----------------------------------------------11

Figure 8: Adapter’s RS232 Interface -----------------------------------------------------------------13

Figure 9: Serial port setting form ---------------------------------------------------------------------16

Figure 10: RS-232 data stream ------------------------------------------------------------------------19

Figure 11: DCE-DCE connection ---------------------------------------------------------------------19

Figure 12: DB9 All-Line Direct Extension ----------------------------------------------------------20

Figure 13: DCE-DCE communication solution -----------------------------------------------------21

Figure 14: Flow of data --------------------------------------------------------------------------------22

Figure 15: Data transmission flow chart -------------------------------------------------------------23

Figure 16: the RS-232 signal from PC’S COM Port -----------------------------------------------24

Figure 17: Steps to implement data transmission ---------------------------------------------------26

Figure 18: Personal Information ----------------------------------------------------------------------29

Figure 19: Medical Record ----------------------------------------------------------------------------29

Figure 20: Time Settings -------------------------------------------------------------------------------30

Figure 21: Reminder ------------------------------------------------------------------------------------30

Figure 22: Alarm Message -----------------------------------------------------------------------------30

Figure 23: Emergency Contact ------------------------------------------------------------------------31

Figure 24: Book Reading1 -----------------------------------------------------------------------------31

Figure 25: Book Reading 2 ----------------------------------------------------------------------------31

Figure 26: Quiz ------------------------------------------------------------------------------------------32

Figure 27: Quiz Feedback 1 ---------------------------------------------------------------------------32

VII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Figure 28: Quiz Feedback2 ----------------------------------------------------------------------------32

Figure 29: Everyday tip --------------------------------------------------------------------------------33

Figure 30: Choosing the favourite report form -----------------------------------------------------33

Figure 31: Direct received data show ----------------------------------------------------------------34

Figure 32: Visualized data show ----------------------------------------------------------------------34

Figure 33: Graphical Bars -----------------------------------------------------------------------------35

Figure 34: Standard Day -------------------------------------------------------------------------------35

Figure 35: Trend -----------------------------------------------------------------------------------------35

Figure 36: Smart analysis 1 ----------------------------------------------------------------------------36

Figure 37: Smart analysis 2 ----------------------------------------------------------------------------36

Figure 38: Whole interface evaluation -------------------------------------------------------------- 40

Figure 39: Multifunction evaluation ------------------------------------------------------------------40

List of Tables
Table 1: Meter’s port settings -------------------------------------------------------------------------10

Table 2: Meter’s cabling -------------------------------------------------------------------------------10

Table 3: Adapter’s general specification -------------------------------------------------------------13

Table 4: Adapter’s Pin-out -----------------------------------------------------------------------------13

Table 5: Standard signal connection ------------------------------------------------------------------20

Table 6: Functionality testing --------------------------------------------------------------------------38

List of Abbreviations:

DCE: Data circuit-terminating equipment

DTE: Data terminal equipment

SMS: Short Message Service

LED: Light-emitting diode

WHO: World Health Organization

VIII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

1 Introduction
1.1 Design Brief
For nearly two decades, electronic and communication technologies have been
proposed as means of supporting medical applications. This project is concerned with
using these technologies to create a personal health device which can benefit children
with diabetes.
This application combines multifunction from simple information-giving to
sophisticated real-time monitoring. The information-giving function serves as a
convenient way for professionals to track the medical history and personal
information of the child; the insulin-injection-reminder function is an alert tool to
assist children and their parents best control the daily injection; The education
function can greatly help children know about diabetes through interesting books and
games; The function of emergency contact gives the quickest way to contact a family
member in the event of an incident; As for the sophisticated function of real-time
monitoring, it integrates data transmission by Bluetooth and data analyzing by the
computing power within the phone. Bluetooth technology offers a technically
attractive solution to establish data transfer between a Glucose Meter and the mobile
phone. The aim of the real-time meter reading lets the patients monitor their real-time
blood glucose level, which can support the required frequency of insulin dose
adjustment for better diabetic management.
The innovative personal health
device is based on mobile platform
and Bluetooth technology. Further
details will be discussed in this
report.

Figure1: the schematic telemedicine


system

-1-
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

1.2 Basic Model


The whole system comprises a blood glucose meter, a Bluetooth RS-232 adapter and a
mobile phone. The blood glucose meter is used to collect the sample blood and test
the glucose level. The adapter replaces traditional serial cables and negotiates the
wireless communication between the meter and the mobile phone. The mobile
platform can implement the ultimate powerful functions with its embedded windows
mobile system.
Once the mobile platform sends the transmission command, the two Bluetooth
devices- adapter and mobile phone will be paired through secure partnership. Then,
the adapter will send the command to the glucose meter. If it is the correct command,
the meter will respond to the command and send back the stored information. Again,
the adapter changes the traditional serial communication to wireless communication
and sends the information to the mobile phone. Finally, data will be stored in database
and analyzed by the mobile platform. In addition, the mobile phone can implement
other functions to achieve the best medical assists to children with diabetes.
The basic model of this system can be illustrated in Figure 2.

Blood Glucose Meter Bluetooth RS232 Adapter Mobile Phone

Figure 2: Data transmission model

-2-
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

2 Background Research and Literature Survey


2.1 Diabetes in Children
Defined by the World Health Organization (WHO), the term diabetes mellitus
describes a metabolic disorder of multiple aetiology characterized by chronic
hyperglycaemia with disturbances of carbohydrate, fat and protein metabolism
resulting from defects in insulin secretion, insulin action, or both. “Diabetes is a
chronic, incurable disease that causes an array of serious medical complications and
premature death.” [2] And it’s thought that in the UK alone there are around 2 million
people who are diabetic. However, more worryingly is this figure may likely to
double within the next 10 years.
“Diabetes in children usually presents with severe symptoms, very high blood
glucose levels, marked glycosuria, and ketonuria.”[9] Children who suffer this
life-long disease require additional care from their families and the whole society. To
keep their blood glucose in tight control would be the first aim for their families.
Meanwhile, their special mental and physical condition requires the additional
medical aid.

2.2 Telemedicine System


There is an exceptionally important role for diabetic education and self glucose
monitoring, with the goal of keeping both short-term and long-term blood glucose
levels in control.
“Increasingly in health care, the burden of responsibility for day-to-day treatment
falls upon patients and other non-professionals.”
[http://www.bodytel.com/overview.html] For diabetics, it is particularly important to
track their blood glucose level. Better monitoring of blood glucose levels is crucial
for the diabetes sufferers. “The easier it is for individuals to follow that treatment,
the more likely the treatment will be followed properly and the more effective it will
be.” [http://www.bodytel.com/overview.html]
Technology innovation encourages the invasive and ubiquitous computing in the

-3-
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

medical system. And “telemedicine system has been proposed for nearly two decades
as a means of supporting people with diabetes to achieve improved outcomes.”[3]
Mobile phones with wireless communication offer a technically attractive solution to
data transmission. “Smart phone’s emerging capabilities are fueling a rise in the use of
mobile phones as input devices to such resources as situated displays, vending
machines, and home appliance. Mobile phone’s prevalence gives them great potential
to be the default physical interface for ubiquitous computing appliance.”[4]
In a word, telemedicine is an ideal system for the management of people with chronic
disease. “Integration of management between primary and secondary care,
encouragement of self-management of disease, and systematic monitoring of
measures of disease progression and control are complex issues and may lead to
problems that are difficult to resolve. Telemedicine system can incorporate innovative
approaches that may address these problems.” [3]

2.3 Bluetooth Technology


“Wireless technologies operating within the 2.4 Ghz frequency range, provide
engineers with an ever growing panel of technologies. This raises the possibility of
interference issues but it also makes it possible to find the best candidate in terms of
data rate, power consumption, ranges and network configuration.” [5] Bluetooth is
now widely used, particularly for mobile devices, with unit sales to top 500 million in
2006. And the Bluetooth technology will further accelerate the acceptance of
telemedicine monitoring system.
“Body area networks centered around modular groups of physiological sensors
combined with mobile Internet and web services are opening new modes of health
care and wellness monitoring.”[6] [7] [8]
Because Bluetooth only requires a Serial Port profile as its gateway, it leaves a lot of
freedom for deployment and implementation. As shown by figure 3, the architecture is
established on the homecare application. Farther more, this architecture with a
wireless interface for blood glucose measurement can be used to simplify home

-4-
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

monitoring. The real-time data transmission and immediate data analysis can greatly
support the self-management of the diabetes.

Figure3: Technology options for homecare

2.4 Current system and projects


There have been numerous literatures and website resources about using electronic
and communication technology in the area of medical health care. Some research and
projects are carried or carrying out by technicians, scientists and clinicians. The
following summary is some related research and deployments from the broad concept
of pervasive computing to more specifically and narrowed down research about
glucose monitoring

2.4.1 Pervasive Computing research: [11]


Researchers have been working on ubiquitous and pervasive computing for more than
a decade. A real-pervasive computing application or system could contain different
traits- that is, for example, with sensors, embedded, context-aware or mobile phone
included. And increasingly, this technology is changing the history of not only the
area of medical care but also almost every fields of human activity.
Figure below shows AwareMedia in use in the central coordinating station. Three
nurses and a doctor are discussing and updating the schedule.

-5-
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Figure 4: AwareMedia
AwareMedia is an application that
shows information about the work
in the different operating rooms. “A
video stream provides overall
awareness of a given operation’s
state, a progress bar shows more
detailed information about the
progress, a chat area lets people communicate in a less intrusive manner”

Awarephone is a program that runs on Symbian mobile


phones. It enhances the presence information about people at
work or on operation. With this information, users can check
the surgery’s status by a mobile phone

Figure5 shows a doctor use the Aware-Phone client to check


the surgery’s status. Here the clinician is running it on Nokia
6600 mobile phone.
Figure 5: Awarephone

2.4.2 Diabetic Information Appliance


The project is carried out by Lucian Ngalamou, Harold Campbell from the University
of the West Indies. This system with an embedded microcomputer is called
“Information Appliance for Diabetic Patients”, which designed for the monitoring of
diabetic patients. The system offers the user several non-intrusive and user-friendly
functions that can help them achieve a normal healthy life. The features are shown as
follows:
-Interface features to a personal computer
-Achieve of balance diabetes care

-6-
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

-Close monitoring of type 1 and 2 diabetes


-Patient Database (Blood glucose, Diet, Urinalysis, Physical Activity)
-Monitoring of Critical situations
-Direct connection to Internet (via modem) for data transfer

2.4.3 One touch Diabetes Management Software


The LifeScan One Touch glucose meter with its data port can support data
downloading to a PC. This Diabetes Management software is for transmitting data to
a PC and visualizing the way to track key factors that affect diabetes and help patient
take control. (see http://www.lifescaneurope.com/uk/products/meters/ultra2/)

Figure 6: A Schematic view of OneTouch Diabetes Management Software

This software optimizes the discussions with doctors


z Provide doctor with an accurate and easy-to-read record, to make it easier to
discuss user’s diabetes management
z Share the results with doctor in between appointments using the e-mail and fax
features.
However, the software only works on the PC, and data can only be downloaded to the
PC.

-7-
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

2.4.4 Mobile Diabetes Management


A number of companies are rolling out mobile devices to help the rapidly growing
number of people suffering from diabetes. A few of the companies are Think Positive
Diabetes, Welldoc Communications, and Diabetes mobile from Symbian. (See link:
http://credibility.stanford.edu/captology/notebook/archives.new/2006/08/mobile_diab
etes.html)
On August 29, 2006, the Stanford persuasive Technology Lab planned a Boomer
Mobile Health project, which perspective is the considerable development of mobile
health devices, applications and services to influence behaviors of older adults in the
area of physical and mental fitness, disease management and education.
Meanwhile, in the University Of Oxford, UK, similar research called “A real-time,
mobile phone-based telemedicine system” was carried out. The system was developed
at the Department of Engineering Science, University of Oxford in collaboration with
e-San Ltd. Motorola T720i phone and a One Touch Ultra blood glucose meter were
used. However, the connection between mobile phone and blood glucose meter was
made with a USB cable connection.

3. Innovations
A deep research of the related papers and projects reveals the potential further
improvements in the telemedicine system for diabetic management. Real application
of the mobile diabetic management should consider different user age group,
constrained mobile platform interface as well as special communication protocol
required by the meter. However, neither of the existent project nor the products can
combine all the considered characteristics to fit for all the potential users and mobile
platforms.
The project Smartphone for Children with Diabetes has such innovations with the fact
that it joins the functions of Diabetic Information Appliance, OneTouch Diabetes
software and Mobile Diabetes Management System as mentioned previously with
other useful features. It can not only download data from a glucose meter, provide

-8-
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

patient profile but also serves as a medical alert and education tool.
This project targets at a unique age group and unique mobile phone, more specifically,
the children and Vodafone V1240. Technical innovations should be made to enable the
neither USB-host nor serial port supported Vodafone V1240. As a result, substitutable
communication should be designed. As a solution, a wireless communication was
developed in this project. Bluetooth connection substitutes the conventional cable
connection to achieve the most effect of real-time data transmission.
Further more, technical challenge for establishing communication between two DCE
devices requires the innovation in this prototype. The DCE-DCE connection expels
the possibility of the simple and standard pin connection and requires indirect and
interrupted pin connection. Detailed description of the challenge and its solution can
be seen in sector 7.4.2.

4 Proposed System Specifications


The specification for this project is to produce an electronic medical device based on a
mobile platform. This device can assist children with diabetes to monitor their
glucose level and gain other medical assistance.
The prototype smartphone device includes the following functions:
z Real-time Glucose Meter Reading: data are transmitted wirelessly by Bluetooth
from the blood glucose meter to the mobile phone. More detailed graphical
displays or data were provided by the mobile phone to control insulin dose and
modify diet and exercise.
z Medical Alert & Medical Record: Keep the Electronic Personal Health Record
(PHR) and allows the Emergency Contact. The additional alarm function can
remind children to inject insulin at the pre-set time.
z Children’s Diabetic Education: Let children with diabetes gain knowledge about
their disease through interesting books and games

-9-
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

5 Hardware
5.1 Blood Glucose Meter System
5.1.1 Aim
This meter system is used to test patients’ blood glucose level. This system
should support easy testing and data transmission. It also requires large memory to
store the test results and information about test dates.

5.1.2 The Chosen Product Description


By a wide investigation in glucose meter market, the specific meter by
LifeScan Company was elected. The OneTouch Ultra 2 Blood Glucose Meter system
suits perfectly with the suggested aim.
The meter system kit includes
z OneTouch Ultra2 Meter (with a serial data port)
z OneTouch Ultra Test Strips
z Control Solution
z Lancets
z The OneTouch Interface Cable (9-pin serial)

5.1.3 Meter’s RS-232 Communication Protocol


a. Port Settings

Baud Rate=9600 bps Data Bits=8

Stop Bits=1 Parity = none

Flow Control= None Com Port= port # utilized

Table1: Meter’s port settings

- 10 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

b. Command
The command text file should be prepared using a HEX Editor and saved. All
command should be preceded by HEX values 11, 0d, 0a, (Meter Acknowledgement
Command) and followed by the Data Management Command (DM command).
To run the DM command it will have to be in the form of a “.txt” file.
RS-232 Data Management Command Summary
These are the text commands that follow the meter acknowledgement command
z DM?-send the Meter’s software version and date
z DM@-send the Meter’s serial number
z DMF-send date and time from the Meter’s clock
z DMP-upload blood and control records from the Meter’s memory
z DMSU?-display the glucose units
RS-232 Data Management Commands

DB-9 pin RS-232 Signal Description


2 RXD Received data from Meter to other device
3 TXD Transmitted data from other device to Meter
4 DTR Data terminal read from other device

5 GND Signal ground

6 DSR Data set ready to other device


7 RTS Request to send from other device
8 CTS Clear to send to other device

Table 2: Meter’s cabling

Figure 7: Adapter’s DB-9 Female Connector Pin-out

- 11 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Serial commands and responses are encoded as ASCII Characters. A checksum is


generated for all messages and the hexadecimal representation of the least significant
16 bits of the checksum is placed at the end of each response message, just before the
carriage return (<CR>), line feed (<LF>) pair.
Commands are handled in the order they are received. They must be sent in the upper
case only.
All commands sent to the meter will be queried. If it is found to be an unrecognized
command then the meter will not respond and return to sleep mode.

5.2 Bluetooth-RS232 Adapter


5.2.1 Aim
In the designed mobile phone telemedicine system, the adapter is indispensable for
facilitating the communication between the Serial-supported meter and the
Bluetooth-supported mobile phone. Because of the specific mobile phone and meter
used in the system, direct communication between them seems impossible. The
mobile phone has wireless Bluetooth but no serial port; the blood glucose meter has
serial port but no Bluetooth. How to transmit data between these two devices becomes
a technical challenge in this project. An adapter who can change the role between
serial communication and wireless communication suits perfectly with the system’s
prototype. Meanwhile, the adapter can eliminate the conventional RS232 serial cables,
providing an easy-to-use, invisible connection with superior freedom movement.

5.2.2 The Chosen Product Description


After the consideration of the specific requirement, the LM Technologies Bluetooth-
RS232 adapter was selected from the adapter market.
The package includes:
z Bluetooth serial adapter
z Antenna
z USB cable for power supply

- 12 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Specifications
General:
Specification Description
Baud Rate Supports 4.8/9.6/19.2/38.4/57.6/115.2/230.4 Kbps
Coverage Up to 100m
Connection Point-to-point (pico net)
Signal TxD, RxD, GND, CTS, and RTS
RS-232 Interface D_SUB 9-pin female
Standard Bluetooth specification version 2.0+EDR
Power Supply +5 to +9V DC
Modulation GFSK-1 Mbps, DQPSK-2 Mbps, and 8-DPSK-3
Mbps
Table 3: Adapter’s general specification

Figure 8: Adapter’s RS232


Interface

Table 4: Adapter’s Pin-out


Signals
Pin Signal Direction Description
1 CD Not connected
2 TxD Output Transmitted data
3 RxD Input Received data
4 DSR Not connected
5 GND N/A Signal ground
6 DTR Not connected
7 CTS Input Clear to send
8 RTS Output Request to send
9 Vcc Input Power supply

- 13 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

5.3 Smartphone
5.3.1 Aim
This smartphone is the kernel of this telemedicine system, it is in charge of collecting
data transmitted from the meter; it has the computational power to draw graphics ,
analyze the test data and other information to adjust the insulin dose; it also has to
handle other useful medical assistant functions like information giving and emergency
contact.

5.3.2 The Chosen Product Description


The platform used in the project is Vodafone V1240, which was supplied by
Dr. Sandra Woolley.
Specifications
Operation system: Windows Mobile 5.0 for Smartphone
CPU: 32bit Texas Instruments OMAP 850
ROM capacity: 128 MB
RAM capacity: 32 MB
Serial: Not supported
Bluetooth: Bluetooth 1.2

- 14 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

6 Interface Smartphone – Bluetooth RS 232 Adapter


6.1 Aim
Mobile phone is the data terminal device, it has the function to receive, store and
interpret the test data from blood glucose meter; Bluetooth-RS232 Adapter is the
medium to facilitate the communication between the meter and mobile phone. The
interface which comprises these two devices should have the specifications listed
below:
z Establish the secure partnership to ensure the privacy of the personal medical
information
z When command was sent from the mobile phone, the adapter can change the
Bluetooth communication to Serial RS-232 communication; when Meter data
was sent to the adapter, it can change the Serial RS-232 communication to
Bluetooth
z The code on the mobile phone can reach the requirement of RS-232
communication. Different settings like the Port No., Baud Rate, Stopbits, and
Databits can be chosen in the user interface. As a default setting, Port No.
=COM 6, Baud Rate= 9600, Stopbits=1, Databits=8.
z The adapter should be tested and configured by HyperTerminal

6.2 Connection between Adapter and Smartphone


6.2.1 Set up the Partnership
A Bluetooth partnership is a relationship between the mobile phone and the other
Bluetooth-enabled device in order to exchange information in a secure manner. In
this telemedicine system, the security is extremely important. Patients’ glucose
testing data should be sent to a secured and stabled terminal device to ensure the
patients’ privacy.

- 15 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Steps:
1. Enter the same personal identification number on both devices, set the adapter’s
PIN by HyperTerminal
2. On the mobile phone, search for other Bluetooth-enabled devices, select the
desired device and enter the adapter’s PIN to establish the secure connection.
3. If the two devices are paired, a virtual port will be available on the mobile phone.
It is a virtual serial port generated by Bluetooth. The virtual port used in this
system is COM6.

6.2.2 Set the Virtual Serial Port

The prototype of the whole system’s serial communication is 9600-8-N-1, which


means 9600 Baud rate, 8 bits, none parity and 1 Stopbits.
User should be able to adjust the settings of the serial port, such as the port number,
baud rate, byte length, parity and stop bit. The user interface of the setting can be seen
in Figure 9.

Because Windows Mobile 5.0 supports .Net


Compact Work 2.0, the Class called
System.IO.Ports can be imported in the serial port
setting code. Different serial driver properties are
pre-set in the designed code to make it easy to use
the virtual serial port.

Figure 9: Serial port setting form

- 16 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

User interface description:


z Open Port: open the selected virtual serial port on the mobile phone
z Close Port: close the opened port
z Send Command: different command in .txt format can be sent to the meter to
obtain the needed information.
z Settings: different Port No., baud rate, stop bit, byte length, parity can be adjusted
by the user. As a default setting, COM6, 9600-8-N-1 is used in the port setting.
z Clear Send: Clear the send file in the sending text box.
z Clear Receive: Clear the received data in the received text box.
z Save Receive: Save the received data in the specific file folder selected by the
user.
z Exit: Exit the form of Port setting.

7 Interface Glucose Meter- Bluetooth RS232 Adapter


7.1 Aim
Blood glucose meter is the device which can test patient’s glucose level and store
some test data in its storage. However, it has limited storage space and limited
capacity to interpret the data. As a result, the glucose meter should transmit the stored
test result to a more functional device like the mobile phone. In this system’s
prototype, the meter serves as a medical testing tool and the source of information.
Again, in the communication between the glucose meter and the mobile phone, a
Bluetooth- RS232 adapter can solve the problem of different communication
prototype. This part of the interface is focused on the meter, using the meter’s RS232
communication protocol to implement the data transmission.

- 17 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

7.2 Components
This part of interface includes:
z Two DCE devices: blood glucose meter and the adapter
z OneTouch Interface Cable (9-pin serial)
z Self soldered board
z +5V power supplied by batteries

7.3 RS232 Communication


In telecommunications, RS-232 is a standard for serial binary data interconnection
between a DTE (Data terminal equipment) and a DCE (Data Circuit-terminating
Equipment). It is a common used standard for transmitting data both in
communication and interface.
Serial communication RS232 was used in the communication for the consideration of
following factors:
z The mobile phone Vodafone V1240 does not support the function of USB host.
Using USB interface cable, neither the meter nor the mobile phone can lead the
master role of communication; as a result the communication cannot be realized.
z The mobile phone platform supports Bluetooth communication, which uses
wireless RS-232. The wireless RS-232 has the advantage of extended range
capabilities, portability and flexibility. During the process of data transmission,
RS-232 can be the standard protocol unifying the whole system.
z RS-232 is a simple protocol that provides easy interface. In the programming,
implementing an RS-232 interface will simplify the data interpretation process.
z By contacting the meter’s manufacture, the technical details about the OneTouch
Ultra2 meter RS-232 communication protocol was obtained. If the protocol is
used appropriately, data transmission can be implemented between two specific
devices, not limited between a DCE device (meter) and a DTE device (PC).
z “RS-232 compatible” can use non-standard pin assignment of circuits on
connectors, which can facilitate the communication between two DCE devices.

- 18 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

For the consideration of this technical challenge in this system, “RS-232


compatible” was used.

Figure 10: RS-232 data stream

http://pinouts.ru/SerialPorts/RS232_pinout.shtml

The figure above represents an asynchronous RS-232 data transfer. The data stream is
characterized with one start bit, 8 bits, one parity bit and a final 2 stop bits. The data
stream in the designed prototype is 8-N-1, which means a start bit, 8 bits, none parity
and 1 stop bit.

7.4 Technical Challenges


7.4.1 Description
The standard RS-232 communication is between a DCE device and a DTE device.
Figure 11 below represents the typical RS-232 prototype.
(http://www.camiresearch.com/Data_Com_Basics/RS232_standard.html)

Figure 11: DCE-DTE connection

- 19 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

In the standard RS-232 communication, two devices can be connected directly and
handshaking signal can be used to negotiate the communication. A handshaking signal
from the receiving device (DCE) tells the transmitter (DTE) whether it is ready for
data. Usually, “RTS and CTS are the handshake signals. A DTE device asserts the
"request to send" (RTS) signal when it is ready to receive data and disapproves it
when it cannot accept data. Likewise, a DCE device asserts "clear to send" (CTS)
when it is ready to receive data. The RTS and CTS signals form a handshaking pair,
and their use constitutes RTS/CTS handshaking. ”
DCE- DTE
Table 5: Standard signal connection
TXD - RXD
However, in this designed telemedicine system, communication
RXD - TXD
RTS - CTS should be established between two DCE devices- the meter and
CTS- RTS the adapter. There are two reasons to call it a technical challenge
GND-GND to negotiate the DCE-DCE communication. First, the two DCE
devices can not be connected directly because both of them use 9-Pin female
connector. Second, neither of the two DCE devices can initiate the first step of
handshake, which means “open their mouth to speak first”. They both wait for other’s
CTS signal to “open their mouth to speak”. Neither of the devices can gain access to
transmit data through the standard pin connection.

Left Side: Connect to DTE Right Side: Connect to DCE

Figure 12: DB9 All-Line Direct Extension


http://www.camiresearch.com/Data_Com_Basics/RS232_standard.html

- 20 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

7.4.2 DCE-DCE Communication Solution


The solution of two DCE devices’ communication is using male-to –male cables and
manually connecting the correct pins. Normal pin connection is disrupted in this
interface. Figure shows the self-soldered chip and the improved pin connection.

Figure 13: DCE-DCE communication solution

The established pin connections are as follows:


DCE (Meter) DCE(Adapter)
RXD (Pin No.3) ------- TXD(Pin No.2)
TXD (Pin No.2) ------- RXD(Pin No.3)
GND (Pin No.5) ------- GND(Pin No.5)
CTS (Pin No.7) ------- CTS(Pin No.7)

In this designed RS-232 communication prototype, handshake signal RTS-CTS is


abandoned. Instead, both the meter and adapter’s CTS are asserted logic ‘0’ by
supplying a positive voltage. If the CTS signal is kept logic ‘0’, both device can
initiate the beginning of data transmission without waiting for each other to send the
RTS signal .Communication can be established once either side has the data to
transmit. It is the easiest way to negotiate the data transmission process since the
handshake signal is abandoned and separated CTS signal can be used.

- 21 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

7.4.3 Method
z Power supply: to make it portable, batteries are used to supply the positive
voltage. 3 batteries with 3.3V capacity can reach the positive voltage requirement
of the RS232 signal.
z Male-to-male cable: use a chip as an extension of the connection between meter
and the adapter. Solder the necessary pins from male converter to an extension
board with lead. Designed pin connection can be established in the extension
board.

8. Data transmission
8.1 Aim

The flow of data in the real communication system can be seen in Figure 13

Send
HEX
Command Command

Meter

Meter Data

Data

Figure 14: Flow of data

To view the data transmission process more clearly, a flow chart show was listed
below. Figure 14 summarizes the data transmission process.

- 22 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Figure 15: Data transmission flow chart

- 23 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

8.2 Result
8.2.1 Mobile-Adapter Interface
Once the two devices are paired with secure password, connection can be used by
opening the virtually generated serial port. In the serial port setting user interface,
choose “open port” and these two devices will be connected by default port settings.
Turn the adapter’s switch to the mode of DCE (towards RS232 connector). When it
is not connected, the link LED will be blinking. When the user chooses the submenu
“open port” in the mobile phone form, the link LED will be steadily on which means
the connection is established.

8.2.2 Sending Command to the Meter


Using HyperTerminal to send Command to the meter
As a test, the software HyperTerminal is used to send the .txt command to the glucose
meter, the glucose meter can respond to the correct command and send back the data
to the PC.
Use the oscilloscope to test the actual RS-232 signal sent from the PC COM Port Pin
No. 3
Test result:
Send the .txt file DMP
(bit0) (bit7)
S S S S S
T T T T T
A 1 0 0 1 0 0 0 O A 1 0 1 1 0 0 0 O A
R 0 P R 0 P R
T T T

Figure 16: the RS-232 signal from PC’s COM Port, detected by the oscilloscope (the
first 20 bits)

- 24 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

The complete data stream:


1 10001000 0 1 10110000 0 1 00100010 0 1 10110010 0 1
00001010
Start stop
Bit bit
ASCII code: 11 0D 44 4D 50
Conclusion: when sending the meter acknowledge HEX code 11 0D 0A, the PC
automatically omit the value 0A.

Using CommPort to send Command from PC to the meter


CommPort is a self-written code for testing the meter’s response when transmitting
command from PC’s COM Port. Communication between meter and PC is easier to
implement, so it is the first step to test the elementary programming.

According to the meter’s technical specification sheet provided by the manufacturer,


the meter acknowledgement command is 11 0D 0A (HEX value). But in the test,
when Command DMP in .txt format with meter acknowledgement command (HEX 11
0D 0A) is sent, the meter can not turn itself on nor send back data. However,
concluded from last test by HyperTerminal (omit 0A), the meter should immediately
respond to the command and send back the data.

Further test was carried out using CommPort. In this test, normal connection between
meter and PC was interrupted; instead, the connection was extended by a self-soldered
board. The method is used to test the output of pins. The indirect pin connection uses
five pins: RXD-TXD, TXD-RXD, GND-GND, RTS-CTS, and CTS-RTS. The test
result shows that the handshake signal RTS-CTS is not fully functional. RTS and CTS
should be set to logic ‘0’ either by hardware control or software code.
Combine the above two consideration, improvement are made in the code- omit OA
and set the CTS high. With all the effort, communication between PC and the meter is

- 25 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

successful.
For example, when the meter receive the command of DMF, it will send back the
current time “SAT”, “03/03/07”, “12:58:50” 0606.

Using the serial port to transmit data between meter and the mobile
It is a final and whole interface test. The test result was satisfactory and it permitted to
add incrementally all the functionality. The diagram below shows the completed
program implemented on the mobile phone to carry out the task of interfacing. The
code can be found on Appendix.

Figure 17: Steps to implement data transmission

- 26 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

9 Smartphone Platform
9.1 Aim:
This part of the project is a data processing terminal with different functions. The
platform provides medical assistance for diabetics with its superb wireless
communication, powerful calculate capacity, SMS function and user friendly interface.
Sending commands or collecting data is only part of its function as it has been
explained before. It also has to turn data into more readable graphics, provide personal
information and emergency contact, and even educate children with basic ideas about
diabetes.
The code is written on Visual Basic .NET on the Windows Mobile 5.0 Platform.
Special usability and interface consideration will be discussed in following sections.

9.2 Design Consideration


In this designed prototype, several considerations should be kept in mind to improve
the usability.
9.2.1 Specific User Group
The target users are children with diabetes, whose age would be between 8 and 16.
For the consideration of their capacities, specific learning habit and cognition, the
mobile interface must be carefully designed.
People in the specific age group have relatively less concentration, poor vocabulary,
visual, and motor skills, which all constrains the complexity of the user interface. The
user interface must be designed in an easy and clear way with little new word; it also
should be very easy to learn and manipulate the software. Memory load should be
minimized to achieve the best effect. For example, graphics can replace the words to
benefit children understanding glucose level; Different colors of the bar can indicate
the changes of glucose test result in a more direct and recognizable way.
Meanwhile, the target users have the characteristics which can be used to maximize
the effect. They are quick to learns things and have strong flexibilities. The
educational function of this system should utilize all these merits to benefit the

- 27 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

potential users. Vivid pictures, interesting games and little bonus can be crucial to
attract the users and achieve the most effect of elementary education.

9.2.2 Specific Mobile Platform


The prototype is developed on a handheld device Vodafone V1240, which is a
smartphone. Its embedded operating system is Windows Mobile 5.0 for smartphone.
The first limitation that has to be borne in mind while designing an application for a
smartphone is the small screen size [13] [14]. Constrained by its limited display size
(34.2×45.6 millimeters), information displayed on a form should be concise enough
to fit the screen size.
The second limitation is the embedded system, and more specifically, the smartphone
platform. Compared to PDA and Pocket PC devices, smartphone has fewer controllers.
For example, button control is not available in the smartphone application.
Manipulating the system’s numerous controllers only by the keyboard would result
some difficulty.
The third limitation is the limited storage space. According to the technical
specifications of Vodafone v1240, the RAM capacity is 32 MB and the ROM capacity
is 128 MB. Limited information can be stored in the smartphone. But in the desired
design, in order to be more attractive to children, many pictures and .txt files must be
used. In [13] it is suggested to handle data in file instead of database. In consideration
of all these factors, blood glucose record and patients’ log are stored in .txt file, and all
the pictures used in the design are compressed and resized. A record in standard
format including16 test results occupies 4kb, and the average compressed picture
takes 18kb storage space.

- 28 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

9.3 Implementations
This section details how the program functions and the method used when the
program was developed and implemented from the design. During the design process,
many changes are made to improve the usability and functionality.
The whole program and user interface are shown in following sections sorted by
different functions

9.3.1 Implementation 1: Medical Alert


9.3.1.1 Function1: Providing Personal and Medical Condition Information
This function can provide a life-saving identification system for individuals with
hidden medical conditions and allergies. In an emergency, vital information is
available on the smartphone. Adults and doctors can receive details about the specific
Smartphone user. For example: name and address, GP ID and medical condition.
Medical record standard was considered during the design. “UK standard 9 for
admission entry” was used as a reference.
The screen shot of the emulator can be seen below, the left one shows personal
information interface while the one on the right shows the medical record interface.

Figure 18: Personal Information Figure 19: Medical Record

- 29 -
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

9.3.1.2 Function2: Insulin Injection Reminder


After the user, who is preferably the child’s parent, has set the insulin injection time,
child can check the time for the next shot. When the injection time arrives, alarm will
be sounded and message box will be popped up to remind the child to inject insulin.
The figures below are the screen shots of this function, the forms of time setting,
reminder and alarm message box are shown.

Time
setting
format
: 09:00

Three
different
time can
be set

Figure20:TimeSettings Figure 21: Reminder


Whenever the child uses this function,
the reminder form is shown. Current
time and next time for injection are both
shown on this form to gain explicit
understanding.
If the child neglects the alarm message,
it will keep popping up for one minute.

Figure 22: Alarm Message

9.3.1.3 Function 3: Emergency Contact


The easy and at-hand contact service is to deal with the potential emergency situation.
Children are so vulnerable in the emergency cases and they may be too panicky to
make the proper save-life actions. Therefore the emergency contact function should
be very easy to implement. The contact should go to a secure adult who can make the

30
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

immediate reactions to help the child.

The left figure shows the interface for emergency


contact. A SMS will be sent to the designated
people simply by pressing a control key. The
phone number and message are pre-set in the code
to expedite the emergency communication. The
designated people can be family members or
personal doctor.
Figure 23: Emergency Contact
In the programming, the function of sending SMS is implemented by using
system.runtime.interopservices namespace, which is supported by the .Net compact
frame work 2.0. Microsoft text SMS protocol was used in this communication. The
programming code can be seen in Appendix.

9.3.2 Implementation2: Diabetic Education


9.3.2.1 Function 4: Reading Books
Reading books by mobile phone can be implemented by special programming. With
vivid cartoons and easy word description, the interesting and enlightened book
becomes young patients’ access to understanding their special health condition.
Figure24: Book Reading1 Figure 25: Book Reading2

31
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

The screen shots (Figure 21 and Figure 22) are some pages of the children diabetic
education book.
The book was downloaded from website http://www.grandmasandy.com/

9.3.2.2 Function 5: Playing Games


Figure 27: Quiz Feedback1

Figure 26: Quiz

Figure 28: Quiz Feedback2


The quizzes were downloaded from website http://www.grandmasandy.com/
Thanks to the specific design of the key control and consideration of the bonus,
children can enjoy the original paper-medium games in a smartphone platform. The
smartphone, with its unique multimedia function can serves as a better educational
medium than plain paper.
Each quiz has two choices. By picking up the right one, children can get some bonus
and fun.
Codes which implement this function can be seen in Appendix.

32
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

9.3.2.2 Function 6: Reading Everyday Tip

Everyday, the user can see a diabetic tip by


entering the “tips everyday” interface. Tips about
glucose testing, diet and exercises are stored in the
smartphone storage space. Sorted by different dates,
a special tip will show up and give children the
convenient health guidance. A pool of different tips
are kept recorded for this function, children can
learn the calendar tip using this portable device at
Figure 29: Everyday tip any place and any time.

Figure above is an example of showing tips on a message box.


The pool of tips is excerpted on professional diabetic education websites.
http://www.lifeclinic.com/focus/diabetes/tips.asp

9.3.3 Implementation 3: Test Data Interpretation


9.3.3.1 Function 7: Graphical Feedback

Figure 30: Choosing the favorite report form

The mobile platform’s aim is not only collecting data


from the glucose meter, as described in the last section,
but also converting data into more readable graphics
and giving smart analysis to adjust the insulin
injection amount. This part of the design is analyzing
the glucose test result with patient’s daily food
consumption and activity, giving the user the direct
graphic show of the test result and suggesting the insulin adjustment.

33
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

To interpret the collected data into report format or graphic show is for following
considerations. First, the screen size limits the total word number which can be shown
on the screen. Narrow word and paragraph space would be a reading obstacle for the
users, adults may take time to read these information and children may lose interest to
knowing their test result.
Second, minimizing user’s memory load could benefit their understanding. Colors and
graphics are visual tools to help them gain the direct perception of data. In order to
learn the meaningful blood glucose test result, the visual attraction is indispensable for
children.
The collected data from meter are in the .txt format, which uses Lifescan’s specific
data communication protocol. Without the technical specification sheet explaining the
protocol, the received data could be meaningless. If the collected data are directly
shown on the textbox on the screen, user can neither see nor understand clearly. The
figure below simulates the direct data show on the screen.

Figure 31: Direct received data show Figure 32: Visualized data show

P
005,"VVZ0C78BY","MMOL/
L" 0618
P
"WED","03/21/07","08:45:06
"," 108 ","N","00", 00
09AD
P
"TUE","03/20/07","19:06:35
"," 094 ","N","00", 00 09BF
P

For the consideration of all the factors, data interpretation should be carried out to
make it meaningful, readable and attractive. In this design, different showing format
can be chosen by the users. They can choose their favorite reading format to match
different reading habit and unique learning style. Different formats can be seen in the
format of datalist, barshow, trend, standard day
34
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Figure 29 shows the situation when received data are sorted out by different columns
with specific titles to describe their meanings. Pages can be shown in continuous order
to convenient the user to read all the recorded data. More professional time
classification (before meal or after meal) is given to satisfy the special need of
diabetics, because of the different blood glucose level standards for before-meal and
after-meal.
The next screens displayed a color-coded histogram of blood glucose values
transmitted from the meter. (See Figure 30,31,32). Different graphical display format
could be chosen by the user: Graphical Bars, Standard Day Data or Trend Show.

Figure 33: Graphical Bars Figure 34: Standard Day Figure 35: Trend

In the “graphical bar” show, by aiming to make data more readable, different colors of
the histogram bars could make the data more meaningful, with red representing high
levels, light coral representing low levels, blue and lime representing normal level.
Control threshold values are set to determine normal control target area. In this design,
5 mmol/L is the control lower limit while 10 mmol/L is the control upper limit. The
gray area in these screens means the target control area, which has the function to
remind user to keep control of their blood glucose level.
In the “Standard Day” display form, blood glucose data are displayed by different time
of the day, with the aim to show user the changes of daily glucose level.
In the “Trend” display form, the time-series displays of all blood glucose readings are
35
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

available to the user. This trend show supports the users in their attempts to improve
the blood glucose control.
9.3.3.2 Function 8: Smart Analysis

The left figure shows the simple analysis of the


received blood glucose data. Maxvalue, Minvalue,
Mean values are calculated from the tested
samples. The value of “percentage in control” is a
judgment to enhance the motivation to reinforce
the blood glucose control.

Figure 36: Smart analysis 1

Figure 37: Smart analysis 2


“Tight control requires frequent blood glucose
measurement, which provides the information
needed to administer insulin or glucose properly” [2]
but blood glucose level is not the only element to
determine the insulin dose. Other information like
the food intake, exercise should also be considered to
establish the optimal dose of the insulin therapy.
The user of the phone would be asked to record a log
for daily food consumption and exercise. (See figure 37) This log would be stored in
the phone together with patients’ blood sugar record to establish the patient database.
With its computing capacity of the phone, it can give the user suggestions to adjust the
insulin amount. “Once regular testing was established, most patients then moved to
establishing the optimal dose of the basal insulin therapy” [3]
This function requests the user to keep a log of their daily activity and enable them to
maximize the effect of glucose monitor.

36
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

10 Testing
The primary goal of the system deployment is to implement all the specifications and
the ultimate goal is for the user community to accept it. To accomplish these two goals,
functionality testing and usability testing are two indispensable parts of the complete
project. They can improve the designed function and make it easier for users to accept.

10.1 Functionality Test


All components were tested individually to ensure the integrated whole system. Some
detailed description were explained in section 5 hardware, here is the summary of the
testing method and result

Part Testing Areas Testing Method Testing Result

Glucose Data output 1. Sending Command by 1. using the self-written


Meter HyperTerminal and code, different command
(see 5.1) receive data by should be used
HyperTerminal 2. no errors were
2. Sending Command by detected
self-written software and In data transmission
receive data by it
3. Testing signal by
oscilloscope

Smartphone Connection Pair these two devices Successful secure paring


-Adapter
Interface
(see
Section 6 )

Meter- Connection Send .txt format 1. meter respond


Smartphone and data command form the immediately when it
Interface transmission smartphone to meter receive the command
(see 2. successful data
Section 8 ) transmission
3. no errors were
received

37
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang
Part Testing Areas Testing Method Testing Result
Meter data 1.correct 1.compare the data in 1. data conversion
processing conversion from mmol/ml in the without errors
mg/dl to more smartphone with the 2. graph representation
commonly used reading from the meter without errors
mmol/ml 2.compare the graphs
2.correct graph with the changes of data
display
Insulin 1.Correct set proper alarm time 1. alarm arrives at the
Injection next-time show and wait for the alarm pre-set time
Reminder 2.correct alarm information show 2. can only be
information show implemented in this
application on the
smartphone, can not use as
a background-working
alarm

Emergency Sending SMS by Set an available mobile 1. SMS can be received


Contact pressing a button phone number in the by the other mobile
code, check whether it phone immediately
can receive the *2. severely delayed when
emergency message the signal is weak

Quizzes Correct responses Compare the Right feedback was shown


to the user’s Smartphone’s answer to deal with correct or
answer feedback to the correct wrong answers
answer

* means the negative test result


Table 6: Functionality testing

38
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

10.2 Usability Test


10.2.1 Usability
In the user- oriented design paradigm, usability is a big issue. It is extremely important
to keep usability in mind during the whole process of designing. The whole system
should be efficient, easy and satisfying to use; the software application should be
suitable for the target users to best achieve their goals.
According to ISO 9241-11, usability is “the extent to which a product can be used by
specified users to achieve specific goals with effectiveness, efficiency, and satisfaction
in a specified context of use.”
ANSI/Human factors Ergonomics Society and ISO have been working on standards of
usability.
Part of the ISO standards is based on the following seven principles of usability:
z Self-descriptiveness
z Controllability
z Suitability for task
z Conformity with user expectations
z Error to tolerance
z Suitability for individualization
z Suitability for learning

10.2.2 Usability Evaluation


The first few steps to prepare usability testing are identifying the purpose of the test,
defining the user group, specifying problem statements, identifying user tasks, and
specifying the performance data to be collected. [1]
Then the real evaluation process began with users answering a questionnaire and using
the software. The questionnaire consists of simple instructions about the device and 9
questions regarding the overall or independent functions about the system. Users were
asked to rate the interface from 1 to 5 (higher score is preferable) and more preferably
to give feedback and suggestions.
The ideal usability test should be implemented in real clinical trials to the targeted user
39
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

group. However, due to the constrained condition for trial and limited approaches to
the clinical resources, the first part of the usability test only carried out in small group.
It involves 10 students as users, which is not an indicative of the targeted diabetic
children, but which is requested to imitate the behaviors of children. During the whole
process of evaluation, they set themselves in the situation of children with diabetes and
were kept reminding this important fact. However, this short-term solution can not
replace a large-scaled real clinical test.

Figure shows the summation of user rating about the whole interface and the
multifunction. The average score for the whole interface is 4.3 out of 5.0 and the
average score for the system’s multifunction is 4.1 out of 5.0. More detailed graphic
analysis about each independent function and the questionnaire used are shown in
Appendix.

Figure 38: Whole interface evaluation Figure 39: multifunction evaluation

Together with the satisfactory overall rating, positive comments were received as the
user’s feedback. These comments include “Most functional controllers can be found in
menu easily”, “Quite useful to the certain kind of patient”, “The program has a strong
function in general” and “Graphics are easy to understand”; However, critics and
constructive suggestions were collected from the user evaluation. The feedback
includes “You’d better keep it always with you”, “Operating the hardware and
software together is difficult and setting the transmission parameter is difficult too”,
“Need several minutes to learn at the first time”. Further more, some software design
40
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

bugs were also detected in the usability test. Some user gave their opinions regarding
the more favorable and convenient key control.
By analyzing the test result, some improvement should be made to enhance the
usability. In fact, the system was tested and re-designed many times to maximize its
function.

11. Future work


Due to the limited research and clinical resources, the designed system could not be
deployed in a real clinical trial environment or to a more sophisticated web-based
server.
The future work will include the major two improvements:
z Patients’ data should be transmitted with a secure connection to a central server.
Web-based feedback can be made by clinicians to give patients’ professional
decision support.
z Large datasets of clinical data should be collected and large scaled clinical trial
should be carried out to check the effect of glucose management. A trial to the
targeted users would help this system to be developed further.

12. Conclusion
In comparison with previous telemedicine systems described in the literature, this
system has its innovative approach to provide the user with personal health assistance.
Multifunction was implemented in this prototype with the aim to enhance
self-management of diabetes. The major functions include medical alert, emergency
contact, diabetic education and blood glucose data transmission. Technical challenges
of wireless communication and DCE-DCE connection were solved as described in this
paper. Usability issues have been studied with the aim to create easy user interface and
satisfactory control result. Some problems encountered in the usability test were
addressed, however, larger clinical trial is crucial to enhance its capacity for
commercial use.

41
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Reference

Papers:
[1] Nancy J. Wahl, Student –Run Usability Testing, Middle Tennessee State University,

Computer Science

[2] Kiran kanukurthy and Usha Viswanathan, Controller for a continuous near infrared glucose

sensor, Sensors for Industry Conference, Houston, Texas, USA, 8-10 February, 2005.

[3] Andrew Farmer, Oliver Gibson, Paul Hayton et al, a real-time, mobile phone-based

telemedicine system to support young adults with type 1 diabetes, Informatics in Primary

Care 2005; 13:171-7

[WHO] Definition, Diagnosis and Classification of Diabetes Mellitus and its Complications of

Diabetes Mellitus and its Complications

[4] R. Ballaga, J. Borcher, M. Rohs, Jennifer G. Sheridan, The smart phone: A Ubiquitous Input

Device, Pervasive Computing, January-March 2006

[5] Michael Setton, Regis Guignier, Wael labidi, Cyberfab, Bluetooth sensors for wireless

home and hospital healthcare monitoring, 452 rue des sources, France

[6] A. Milenkovic, C. Otto, E. Jovanov, Wireless Sensor Networks for Personal Health

Monitoring: Issues and Implementation, Computer Communication, Vol.29, No. 13 14, 2006,

pp. 2521-2533

[7] C.Otto, A. Milenkovic, C. Sanders, E. jovanov, System Architecture of a wireless body area

sensor network for ubiquitous health monitoring, Journal of Mobile Multimedia, Vol. 1, No. 4,

2006, pp. 307-326

[8] Aziz, O.; B. King, Darzi, A; Guang-Zhong Yang, Pervasive body sensor network: an

approach to monitoring the post-operative surgical patient, International Workshop on

Wearable and Implantable Body Sensor networks, April 2006 pages 13-18

[9]Definition, Diagnosis and Classification of Diabetes Mellitus and its Complications of

Diabetes Mellitus and its Complications

[10] Mikael Drugge, Josef Hallberg, Peter Parnes and Kare Synnes, Wearable Systems in

Nursing Home Care: Prototyping Experience, Pervasive Computing, January-March 2006

42
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

[11] Thomas R. Hansen, Jakob E. Bardram, and Mads Soegaard, “Moving Out of the

Lab:Deploying Pervasive Technologies in a Hospital”, Pervasive Computing, July-September

2006

[12]. Karat, J., “Evolving the Scope of User-Centered Design,” Communications of ACM, 42,5,

May 1999, pp. 87-90

[13] Yu.P, Yu.H, Lessons learned from the practice of mobile health application development,

Computer Software and Applications Conference, 2004. COMPSAC 2004

[14] Hassanein, F.: Head, M.M., Ubiquitous Usability: Exploring Mobile Interfaces within the

Context of a Theoretical Model, Proceedings of the 15th Conference on Advanced Information

Systems Enginerring (CAISE 2003)

Other Papers
Lucien Ngalamou, Harold Campbell, Diabetic Information Appliance, University of the West

Indies, Department of Physics

Alexia Rodriguez Ruano, Environmental Sensing for Personal Health, University of

Birmingham

Richard D. Beach, Senior Member, IEEE, Falko v. Kuster, and Francis Moussy, Member, IEEE,

Subminiature Implantable Potentiostat and Modified Commercial Telemetry Device for

Remote Glucose Monitoring

Peter Leijdekker, Valerie Gay, Personal Heart Monitoring System Using Smart Phones to

Detect Life Threatening Arrhythmias, University of Technology Sydney

Books
Burkherdt, Pervasive Computing- Technology and Architecture of Mobile Internet

Applications, 2002, ISBN 0201722151

Douglas Boling, Programming Microsoft Windows CE. Net, Third Edition, ISBN 0735618844

Thearon Wills, Bryan Newsome, Beginning Visual Basic 2005, ISBN: 0-7645-7401-9

43
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Useful Links:

Programming:

http://www. Znkfw.com/shoujiyuanma

http://msdn.microsoft.com/mobility

http://www.opennetcf.org

http://msdn.microsoft.com/vstudio

http://forums.devbuzz.com

Research on Glucose Monitoring

https://www.thinkdiabetes.com/tpdiabetes/

http://www.welldoc-communications.com/index.html

http://my-symbian.com/s80/software/applications.php?faq=25&fldAuto=74

44
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Appendix A: User Evaluation Questionnaire


First of all, thank you for your collaboration in this user evaluation.
This project is a smartphone-based system that provides several useful functions for children

with diabetes. Functions are as follows:

-Information Provider- Personal information & Medical Records

-Insulin Injection Reminder

-Children’s Diabetic Education- book, quiz ,logbook & tips everyday

-Emergency Contact- Sending SMS

-Meter Reading-Download data from glucose meter and get immediate feedback.

During this part of the evaluation you are going to be guided through the basic use of the

Smartphone interface.

The first screen is the main interface. Functions like emergency and meter-reading can be

directly entered. Other functions can be shown when you click “Menu”.

In the SerialPort form, you can open the port as defaulted setting, no need to change the

settings like baudrate and databits .etc.

Rate from 1 to 5 the following aspects about the GUI on the smartphone.
1. How easy to use did you find the program in general?
Very difficult OK Very easy
1 2 3 4 5

Comments:

2. How would you rate the whole interface of the program?


I don’t like it OK I like it very much
1 2 3 4 5

Comments:

45
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang
3. How would you rate the multifunction of the program?
Not useful at all OK Very useful
1 2 3 4 5

Comments:

4. How would you rate the function of Personal Information and Medical Records?
I don’t like it OK I like it very much
1 2 3 4 5

Comments:

5. How easy did you find to use the function of “Diabetic Reminder”?
Very difficult OK Very easy
1 2 3 4 5

Comments:

6. How interesting would you rate the “Children’s Corner”?


Not interesting at all OK Very interesting
1 2 3 4 5

Comments:

46
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang
7. How useful would you rate the “Emergency Contact”?
Not useful at all OK Very useful
1 2 3 4 5

Comments:

8. How easy did you find to read the meter data?


Very difficult OK Very easy
1 2 3 4 5

Comments:

9. How easy did you find to interpret graphics and tables about meter data?
Very difficult OK Very easy
1 2 3 4 5

Comments:

47
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Appendix B: Visual Basic Code B.1 Main Interface


Public Class main_interface
NB. The code in Black was written entirely by myself Private Sub maininterface_Load(ByVal sender As System.Object, ByVal e As
The code in Red was taken from others and modified by myself System.EventArgs) Handles MyBase.Load
The code in orange was taken from others without modification 'load image to the picturebox
Dim MyImage As New Bitmap("\my documents\main interface.jpg")
PictureBox1.Image = CType(MyImage, Image)
Code lists: End Sub
B.1 Main Interface --------------------------------------------------------- I
B.2 Show Every Day Tip -------------------------------------------------II Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
B.3 Emergency Contact- Sending SMS --------------------------------IV System.EventArgs) Handles MenuItem1.Click
B.4 Book Reading Example ---------------------------------------------XI Form1.Show()
B.5 Quiz Example --------------------------------------------------------XI End Sub
B.6 Insulin Injection Reminder ----------------------------------------XII
B.7 Serial Port Setting -------------------------------------------------XVII Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
B.8.1 Graphical Data Show- Overall Bar --------------------------XXIV System.EventArgs) Handles MenuItem2.Click
B.8.2 Graphical Data Show-Datalist --------------------------------XXVI emergency.Show()
B.8.3 Graphical Data Show-Standard Day -------------------------XXX End Sub
B.8.4 Graphical Data Show- Trend ---------------------------------XXXI
B.9.1 Smart Data Analysis- Insulin Dose Suggestion ----------XXXIII
B.9.2 Smart Data Analysis- Data Analyzer -----------------------XXXV Private Sub TextBox2_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
'show the new form
emergency.Show()
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As

I
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

System.EventArgs) Handles MenuItem4.Click B.2 Show Everyday Tip


SerialPort.Show()
End Sub Imports System.io
Imports System.data
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As Public Class Form1
System.EventArgs) Handles MenuItem3.Click Inherits System.Windows.Forms.Form
emergency.Show() Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
End Sub Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
ExampleOrReal.Show() Friend WithEvents Label1 As System.Windows.Forms.Label
End Sub Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
End Class Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents TextBox6 As System.Windows.Forms.TextBox

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim frmform12 As New Form2
frmform12.Show()
End Sub

Private Sub TextBox2_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
Dim frmform13 As New Form3

II
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

frmform13.Show() Dim context As String


End Sub line = DateTime.Now.Day
' select tip by the date
Private Sub TextBox3_KeyPress(ByVal sender As System.Object, ByVal e As Do While line > 0
System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress line = line - 1
Form4.Show() context = file.ReadLine()
End Sub Loop
Private Sub TextBox4_KeyPress(ByVal sender As System.Object, ByVal e As 'show messagebox
System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress MessageBox.Show(context, "Tips Everyday", MessageBoxButtons.OK,
lifeclinic.Show() MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End Sub file.Close()
End Sub
Private Sub TextBox5_KeyPress(ByVal sender As System.Object, ByVal e As Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress System.EventArgs) Handles MenuItem2.Click
showtip() If TextBox1.Focused Then
End Sub Dim frmform12 As New Form2
frmform12.Show()
Private Sub TextBox6_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress ElseIf TextBox2.Focused Then
ExampleOrReal.Show() Dim frmform13 As New Form3
End Sub frmform13.Show()
Public Sub showtip()
' show everyday tip ElseIf TextBox3.Focused Then
Dim file As New System.IO.StreamReader("my documents\tips.txt") Dim frmform14 As New Form4
Dim line As Integer frmform14.Show()
Dim i As New Int16

III
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

ElseIf TextBox4.Focused Then B.3 Emergency Contact-Sending SMS


Dim frmform14 As New lifeclinic
frmform14.Show() Public Class emergency
Inherits System.Windows.Forms.Form
ElseIf TextBox5.Focused = True Then Friend WithEvents Button1 As System.Windows.Forms.Button
showtip()
Private Sub textbox1_keypress(ByVal sender As System.Object, ByVal e As
ElseIf TextBox6.Focused = True Then System.EventArgs) Handles Button1.Click
Dim frm1e As New ExampleOrReal SMS.SendMessage(txtPhoneNumber.Text, txtMessage.Text)
frm1e.Show() End Sub
End If
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
End Sub System.EventArgs) Handles MenuItem1.Click
Me.Close()
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As End Sub
System.EventArgs) Handles MenuItem1.Click
Dim frm1m As New main_interface Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As
frm1m.Show() System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
End Sub SMS.SendMessage(txtPhoneNumber.Text, txtMessage.Text)
End Sub

End Class Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MenuItem2.Click
SMS.SendMessage(txtPhoneNumber.Text, txtMessage.Text)
End Sub
End Class

IV
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

SMS Class Private Shared SMS_OPTION_DELIVERY_NO_RETRY As Long = &H1


Private Shared PS_MESSAGE_OPTION_NONE As Long = &H0
Imports System.Runtime.InteropServices
Imports interopserv = System.Runtime.InteropServices Private Enum SMS_DATA_ENCODING
SMSDE_OPTIMAL = 0
Public Enum SMS_ADDRESS_TYPE SMSDE_GSM
SMSAT_UNKNOWN = 0 SMSDE_UCS2
SMSAT_INTERNATIONAL End Enum 'SMS_DATA_ENCODING
SMSAT_NATIONAL
SMSAT_NETWORKSPECIFIC Public Enum PROVIDER_SPECIFIC_MESSAGE_CLASS
SMSAT_SUBSCRIBER PS_MESSAGE_CLASS0 = 0
SMSAT_ALPHANUMERIC PS_MESSAGE_CLASS1
SMSAT_ABBREVIATED PS_MESSAGE_CLASS2
End Enum 'SMS_ADDRESS_TYPE PS_MESSAGE_CLASS3
End Enum 'PROVIDER_SPECIFIC_MESSAGE_CLASS
Public Structure PhoneAddress
'/ <summary>The address type.</summary> Private Enum PROVIDER_SPECIFIC_REPLACE_OPTION
Public AddressType As SMS_ADDRESS_TYPE PSRO_NONE = 0
'/ <summary>The phone number in string format.</summary> PSRO_REPLACE_TYPE1
Public Address() As Char PSRO_REPLACE_TYPE2
End Structure 'PhoneAddress PSRO_REPLACE_TYPE3
PSRO_REPLACE_TYPE4
Public Class SMS PSRO_REPLACE_TYPE5
Private Shared SMS_MSGTYPE_TEXT As String = "Microsoft Text SMS Protocol" PSRO_REPLACE_TYPE6
Private Shared SMS_MODE_SEND As Long = &H2 PSRO_REPLACE_TYPE7
Private Shared SMS_OPTION_DELIVERY_NONE As Long = &H0 PSRO_RETURN_CALL

V
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

PSRO_DEPERSONALIZATION <StructLayout(LayoutKind.Sequential)> _
End Enum 'PROVIDER_SPECIFIC_REPLACE_OPTION Public Structure ProviderDataSize
Public ProvDataSize As Int32
Private Structure TEXT_PROVIDER_SPECIFIC_DATA End Structure
Public dwMessageOptions As Long
Public psMessageClass As PROVIDER_SPECIFIC_MESSAGE_CLASS Public Shared Sub SendMessage(ByVal sPhoneNumber As String, ByVal
Public psReplaceOption As PROVIDER_SPECIFIC_REPLACE_OPTION sMessage As String)
End Structure 'TEXT_PROVIDER_SPECIFIC_DATA Dim retVal As IntPtr = IntPtr.Zero
Dim smsHandle As IntPtr = IntPtr.Zero
<System.Runtime.InteropServices.DllImport("sms.dll")> _ Dim smsProviderData As IntPtr = IntPtr.Zero
Private Shared Function SmsOpen(ByVal ptsMessageProtocol As [String], _ Dim smsMessage As IntPtr = IntPtr.Zero
End Function Dim ProvData(12) As Byte

<System.Runtime.InteropServices.DllImport("sms.dll")> _ Try
Private Shared Function SmsSendMessage(ByVal smshHandle As IntPtr, _ retVal = SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, smsHandle,
End Function IntPtr.Zero)
If retVal.ToInt32 <> 0 Then
<System.Runtime.InteropServices.DllImport("sms.dll")> _ Throw New Exception("Could not open SMS.")
Private Shared Function SmsClose(ByVal smshHandle As IntPtr) As IntPtr End If
End Function
'Set address structure
<StructLayout(LayoutKind.Sequential)> _ Dim smsatAddressType As Byte() =
Public Structure MsgSize BitConverter.GetBytes(SMS_ADDRESS_TYPE.SMSAT_UNKNOWN)
Public MsgSz As Int32 Dim ptsAddress As Byte() =
End Structure System.Text.Encoding.Unicode.GetBytes(sPhoneNumber)
Dim smsAddressTag(smsatAddressType.Length + ptsAddress.Length)

VI
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

As Byte Try
Array.Copy(smsatAddressType, 0, smsAddressTag, 0, retVal = SmsClose(smsHandle)
smsatAddressType.Length) Catch ex As Exception
Array.Copy(ptsAddress, 0, smsAddressTag, MessageBox.Show(ex.Message)
smsatAddressType.Length, ptsAddress.Length) End Try
Dim smsAddress As IntPtr = End Sub
Marshal.AllocHLocal(smsAddressTag.Length) End Class
System.Runtime.InteropServices.Marshal.Copy(smsAddressTag, 0,
smsAddress, smsAddressTag.Length) Class Marsha
Imports System
'Set message Imports interopserv = System.Runtime.InteropServices
Dim smsMessageTag As Byte() = Imports System.ComponentModel
System.Text.Encoding.Unicode.GetBytes(sMessage)
smsMessage = Marshal.AllocHLocal(smsMessageTag.Length) 'Namespace NetCF.Runtime.InteropServices
System.Runtime.InteropServices.Marshal.Copy(smsMessageTag, 0,
smsMessage, smsMessageTag.Length) Public NotInheritable Class Marshal

retVal = SmsSendMessage(smsHandle, 0, smsAddress, 0, smsMessage, Private Class WinApi


smsMessageTag.Length, _
ProvData, 12, SMS_DATA_ENCODING.SMSDE_OPTIMAL, Public Const LMEM_FIXED As Long = 0
SMS_OPTION_DELIVERY_NONE, 0) Public Const LMEM_MOVEABLE As Long = 2
Public Const LMEM_ZEROINIT As Long = &H40
Catch ex As Exception Public Const LPTR As Long = LMEM_FIXED Or LMEM_ZEROINIT
MessageBox.Show(ex.Message)
End Try 'private constructor prevents instantiation
Private Sub New()

VII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

End Sub '/ Allocates a block of memory using LocalAlloc.


'/ <param name="cb">The number of bytes in memory required.</param>
' imported functions '/ <returns>
<System.Runtime.InteropServices.DllImport("coredll.dll", '/ An IntPtr to the newly allocated memory. This memory must be
SetLastError:=True)> _ '/ released using the Marshal.FreeHLocal method.
Public Shared Function LocalAlloc(ByVal uFlags As System.Int32, ByVal '/ </returns>
uBytes As System.Int32) As IntPtr '/ <exception cref="OutOfMemoryException">
End Function '/ There is insufficient memory to satisfy the request.
'/ </exception>
<System.Runtime.InteropServices.DllImport("coredll.dll", '/ <remarks>
SetLastError:=True)> _ '/ AllocHlocal exposes the LocalAlloc WinCE API from CoreDll.dll.
Public Shared Function LocalFree(ByVal hMem As IntPtr) As IntPtr '/ For additional information about LocalAlloc, see the MSDN Library.
End Function Public Shared Function AllocHLocal(ByVal cb As Int32) As IntPtr
Try
<System.Runtime.InteropServices.DllImport("coredll.dll", Return WinApi.LocalAlloc(WinApi.LPTR, cb)
SetLastError:=True)> _ Catch ex As Exception
Public Shared Function LocalReAlloc(ByVal hMem As IntPtr, ByVal End Try
uBytes As System.Int64, ByVal fuFlags As System.Int64) As IntPtr End Function
End Function
End Class 'WinApi '/ Frees memory previously allocated from the unmanaged memory
'/ of the process with AllocHLocal.
'private contructor prevents instantiation '/ <param name="hlocal">The handle returned by the original matching call
Private Sub New() to AllocHLocal.</param>
End Sub '/ <exception cref="Win32Exception">
'/ Indicates failure. The exception contains the error code obtained from
'memory allocation / deallocation methods GetLastError.

VIII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

'/ </exception> '/ <param name="pv">A pointer to memory allocated with


'/ <remarks> AllocHLocal.</param>
'/ You can use FreeHlocal to free any memory from the heap allocated by '/ <param name="cb">The new size of the allocated block.</param>
AllocHLocal or '/ <returns>
'/ ReAllocHLocal, or any equivalent unmanaged API method. If the hlocal '/ An IntPtr to the reallocated memory. This memory must be released
parameter is a '/ using Marshal.FreeHLocal.
'/ null reference (Nothing in Visual Basic), the method does nothing. '/ </returns>
FreeHlOCAL exposes '/ <exception cref="OutOfMemoryException">
'/ the LocalFree function from CoreDll.DLL, which frees all bytes so that '/ There is insufficient memory to satisfy the request.
you can no longer '/ </exception>
'/ use the memory pointed to by <paramref name="hLocal"/>. For additional '/ <remarks>
information about '/ ReAllocHLocal exposes the LocalRealloc WinCE API method from
'/ LocalFree, see the MSDN Library. CoreDll.dll.
Public Shared Sub FreeHLocal(ByVal hlocal As IntPtr) '/ The returned pointer can differ from the original. For additional
'If hlocal <> IntPtr.Zero Then information
If hlocal.ToInt32 <> 0 Then '/ about LocalAlloc, see the MSDN Library.
'If IntPtr.Zero <> WinApi.LocalFree(hlocal) Then '/ </remarks>
If WinApi.LocalFree(hlocal).ToInt32 <> 0 Then Public Shared Function ReAllocHLocal(ByVal pv As IntPtr, ByVal cb As
Throw New Integer) As IntPtr
Win32Exception(interopserv.Marshal.GetLastWin32Error()) Dim newMem As IntPtr = WinApi.LocalReAlloc(pv, CType(cb,
End If System.Int64), WinApi.LMEM_MOVEABLE)
hlocal = IntPtr.Zero 'If newMem = IntPtr.Zero Then
End If If newMem.ToInt32 = 0 Then
End Sub Throw New OutOfMemoryException
End If
'/ Resizes a block of memory previously allocated with AllocHLocal. Return newMem

IX
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

End Function
Public Shared Function IntToHLocalUni(ByVal s As Int32) As IntPtr
'/ Copies the contents of a managed String into unmanaged memory. If s = 0 Then
'/ <param name="s">A managed string to be copied.</param> Return IntPtr.Zero
'/ <returns> Else
'/ The address, in unmanaged memory, to where the s was copied, or 0 if Dim nc As Integer = interopserv.Marshal.SizeOf(s)
a null reference Dim len As Integer = 2 * (1 + nc)
'/ (Nothing in Visual Basic) string was supplied. Dim hLocal As IntPtr = AllocHLocal(len)
'/ </returns> 'If hLocal = IntPtr.Zero Then
Public Shared Function StringToHLocalUni(ByVal s As String) As IntPtr If hLocal.ToInt32 = 0 Then
If s Is Nothing Then Throw New OutOfMemoryException
Return IntPtr.Zero Else
Else 'interopserv.Marshal.Copy(s.ToString, 0, hLocal, nc)
Dim nc As Integer = s.Length Return hLocal
Dim len As Integer = 2 * (1 + nc) End If
Dim hLocal As IntPtr = AllocHLocal(len) End If
'If hLocal = IntPtr.Zero Then End Function 'StringToHLocalUni
If hLocal.ToInt32 = 0 Then End Class 'Marshal
Throw New OutOfMemoryException 'End Namespace 'NetCF.Runtime.InteropServices
Else
interopserv.Marshal.Copy(s.ToCharArray(), 0, hLocal,
s.Length)
Return hLocal
End If
End If
End Function 'StringToHLocalUni

X
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

B.4 Book Reading example B.5 Quiz Example


Imports System.Windows.forms
Public Class book111 Public Class quize1
Private Sub book111_Load(ByVal sender As System.Object, ByVal e As Private Sub quize1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load System.EventArgs) Handles MyBase.Load
' load book picture ' show quiz
Dim MyImage As New Bitmap("\my documents\book111.jpg") Dim MyImage As New Bitmap("\my documents\quize1.jpg")
PictureBox1.Image = CType(MyImage, Image) PictureBox1.Image = CType(MyImage, Image)
End Sub End Sub

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MenuItem1.Click Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
'view first page System.EventArgs) Handles MenuItem2.Click
book11.Show() ‘show next quiz
End Sub quize2.Show()
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click Private Sub quize1_KeyDown(ByVal sender As System.Object, ByVal e As
'view next page System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
book112.Show() If (e.KeyCode = System.Windows.Forms.Keys.Enter) Then
End Sub If TextBox1.Focused Then
right1.Show()
End Class 'MessageBox.Show("binggo", "congradulations!")
'quize2.Show()
ElseIf TextBox2.Focused Then
wrong.Show()

XI
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

' MessageBox.Show("Wrong!", "Consider Again!") B.6 Insulin Injection Reminder


'quize2.Show() Setting
End If
'Enter Imports System
End If Imports System.IO

End Sub Public Class Form5


Inherits System.Windows.Forms.Form
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
System.EventArgs) Handles MenuItem1.Click Friend WithEvents Label1 As System.Windows.Forms.Label
lifeclinic.Show() Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
End Sub Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
End Class Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Shared context1 As String
Shared context2 As String
Shared context3 As String
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click
Dim frmform54 As New Form4

XII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

frmform54.Show() Dim file2 As New System.IO.StreamReader("my documents\time2.txt")


End Sub Dim file3 As New System.IO.StreamReader("my documents\time3.txt")
TextBox1.Text = file1.ReadLine
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As TextBox2.Text = file2.ReadLine
System.EventArgs) Handles MenuItem3.Click TextBox3.Text = file3.ReadLine
Dim file As New System.IO.StreamWriter("my documents\time1.txt") file1.Close()
Dim context As String file2.Close()
context = TextBox1.Text file3.Close()
file.WriteLine(context) End Sub
file.Close()
'save time setting 1 Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As
End Sub System.EventArgs) Handles MenuItem5.Click
Dim file As New System.IO.StreamWriter("my documents\time3.txt")
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As Dim context As String
System.EventArgs) Handles MenuItem4.Click context = TextBox3.Text
Dim file As New System.IO.StreamWriter("my documents\time2.txt") file.WriteLine(context)
Dim context As String file.Close()
context = TextBox2.Text 'savetime setting 3
file.WriteLine(context) End Sub
file.Close() End Class
'save time setting 2
End Sub

Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Dim file1 As New System.IO.StreamReader("my documents\time1.txt")

XIII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Show Current Time and Next Shot Time & Show Alarm at the Set context2 = file2.ReadLine().Substring(0, 5)
Time context3 = file3.ReadLine().Substring(0, 5)
file1.Close()
Public Class Form4 file2.Close()
Inherits System.Windows.Forms.Form file3.Close()
Public Sub GetTime() If result = Windows.Forms.DialogResult.OK Then
msgbox1.Text = Convert.ToString(System.DateTime.Now.TimeOfDay) Timer1.Enabled = False
End Sub End If

Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As If (hour > Convert.ToInt16(context3.Substring(0, 2))) Then
System.EventArgs) Handles MyBase.Load TextBox1.Text = context1
Timer1.Enabled = True ElseIf hour = Convert.ToInt16(context3.Substring(0, 2)) Then
Timer1.Interval = 1000 If minute > context3.Substring(3, 2) Then
End Sub TextBox1.Text = context1
ElseIf minute < Convert.ToInt16(context3.Substring(3, 2)) Then
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As TextBox1.Text = context3
System.EventArgs) Handles Timer1.Tick Else : TextBox1.Text = "Inject Now!!!"
GetTime() Dim mySound As New Sound("becauseimagirl.wav")
Dim file1 As New System.IO.StreamReader("my documents\time1.txt") mySound.Play()
Dim file2 As New System.IO.StreamReader("my documents\time2.txt") result = MessageBox.Show("time to inject insulin", "message
Dim file3 As New System.IO.StreamReader("my documents\time3.txt") from Medical Assistant", MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
Dim hour As Int16 = System.DateTime.Now.Hour MessageBoxDefaultButton.Button1)
Dim minute As Int16 = System.DateTime.Now.Minute If result = Windows.Forms.DialogResult.OK Then
Dim context1, context2, context3 As String Timer1.Enabled = False
Dim result As DialogResult Form1.Show()
context1 = file1.ReadLine().Substring(0, 5) End If

XIV
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

TextBox1.Text = context2
End If ElseIf hour = Convert.ToInt16(context1.Substring(0, 2)) Then
ElseIf hour < Convert.ToInt16(context3.Substring(0, 2)) Then If minute > Convert.ToInt16(context1.Substring(3, 2))
If hour > Convert.ToInt16(context2.Substring(0, 2)) Then Then
TextBox1.Text = context3 TextBox1.Text = context2
ElseIf hour = Convert.ToInt16(context2.Substring(0, 2)) Then ElseIf minute < Convert.ToInt16(context1.Substring(3,
If minute > Convert.ToInt16(context2.Substring(3, 2)) Then 2)) Then
TextBox1.Text = context3 TextBox1.Text = context1
ElseIf minute < Convert.ToInt16(context2.Substring(3, 2)) Else : TextBox1.Text = "Inject Now!!!"
Then Dim mySound As New Sound("becauseimagirl.wav")
TextBox1.Text = context2 mySound.Play()
Else : TextBox1.Text = "Inject Now!!!" result = MessageBox.Show("time to inject insulin",
Dim mySound As New Sound("becauseimagirl.wav") "message from Medical Assistant", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
mySound.Play() If result = Windows.Forms.DialogResult.OK Then
Timer1.Enabled = False
result = MessageBox.Show("time to inject insulin", Form1.Show()
"message from Medical Assistant", MessageBoxButtons.OK, End If
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) End If
If result = Windows.Forms.DialogResult.OK Then ElseIf hour < Convert.ToInt16(context1.Substring(0, 2)) Then
Timer1.Enabled = False TextBox1.Text = context1
Form1.Show() End If
End If End If
End If End If
ElseIf hour < Convert.ToInt16(context2.Substring(0, 2)) Then ' compare the current time with the 3 set time, get the next time for
If hour > Convert.ToInt16(context1.Substring(0, 2)) Then insulin shot,

XV
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

'when comes the set time, alarm will sound and messagebox will pop SND_ALIAS = &H10000 ' name is a registry alias
up
SND_ALIAS_ID = &H110000 ' alias is a predefined ID
End Sub SND_FILENAME = &H20000 ' name is file name
Public Class Sound SND_RESOURCE = &H40004 ' name is resource name or atom
End Enum
Private m_soundBytes() As Byte
' Construct the Sound object to play sound data from the specified
Private m_fileName As String file.
Public Sub New(ByVal fileName As String)
Public Declare Function WCE_PlaySound Lib "CoreDll.dll" Alias m_fileName = fileName
"PlaySound" (ByVal szSound As String, ByVal hMod As IntPtr, ByVal flags As End Sub
Integer) As Integer
' Construct the Sound object to play sound data from the specified
Public Declare Function WCE_PlaySoundBytes Lib "CoreDll.dll" Alias stream.
"PlaySound" (ByVal szSound() As Byte, ByVal hMod As IntPtr, ByVal flags As Public Sub New(ByVal stream As System.IO.Stream)
Integer) As Integer ' read the data from the stream
m_soundBytes = New Byte(stream.Length) {}
Private Enum Flags stream.Read(m_soundBytes, 0, Fix(stream.Length))
SND_SYNC = &H0 ' play synchronously (default) End Sub 'New
SND_ASYNC = &H1 ' play asynchronously
SND_NODEFAULT = &H2 ' silence (!default) if sound not found ' Play the sound
SND_MEMORY = &H4 ' pszSound points to a memory file Public Sub Play()
SND_LOOP = &H8 ' loop the sound until next sndPlaySound ' If a file name has been registered, call WCE_PlaySound,
SND_NOSTOP = &H10 ' don't stop any currently playing sound ' otherwise call WCE_PlaySoundBytes.
SND_NOWAIT = &H2000 ' don't wait if the driver is busy If Not (m_fileName Is Nothing) Then

XVI
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

WCE_PlaySound(m_fileName, IntPtr.Zero, Fix(Flags.SND_SYNC B.7 Serial Port Setting


Or Flags.SND_FILENAME))
Imports System.Runtime.InteropServices
Else Imports System.IO.Ports
WCE_PlaySoundBytes(m_soundBytes, IntPtr.Zero, Imports Microsoft.VisualBasic.FileAttribute
Fix(Flags.SND_ASYNC Or Flags.SND_MEMORY)) Imports system.io
End If Imports System
End Sub Imports System.Xml
End Class Imports System.Xml.Serialization
Imports Microsoft.VisualBasic
Private Sub MenuItem2_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click Public Class SerialPort
Dim frmform45 As New Form5 Dim WithEvents Serialport As New IO.Ports.SerialPort
frmform45.Show() Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
End Sub System.EventArgs) Handles MyBase.Load
With Serialport
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As .BaudRate = 9600
System.EventArgs) Handles MenuItem1.Click .DataBits = 8
Form1.Show() .PortName = "COM6"
End Sub .Parity = Parity.None
.StopBits = StopBits.One
End Class End With
' set the default serial port parameter
End Sub

XVII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Public Function stringToByteArray _ .Open() 'calls the routine implemented in IO.ports


(ByVal str As String) As Byte() Return True
Dim s As Char() Catch ex As Exception
s = str.ToCharArray If .IsOpen = False Then
Dim b(s.Length - 1) As Byte 'if error when opening, message and close port
Dim i As Integer MsgBox("Port open failed", MsgBoxStyle.Exclamation)
For i = 0 To s.Length - 1 .Close()
b(i) = Convert.ToByte(s(i)) End If
Next End Try
Return b End With
' change string to bytearray End Function
End Function Function ClosePort() As Boolean
'called to close the port
Public Shared Sub WriteAllText( _ With Serialport
ByVal file As String, _ Dim isOpen As Boolean = .IsOpen
ByVal text As String, _ Try
ByVal append As Boolean _ .Close()
) Return True
End Sub Catch ex As Exception
Public Class SerialDataReceivedEventArgs 'if error when closing,show message
Inherits EventArgs If .IsOpen = True Then
End Class MsgBox("Port close failed", MsgBoxStyle.Exclamation)
End If
Function OpenPort() As Boolean End Try
With Serialport End With
Try End Function

XVIII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Public Delegate Sub StringSubPointer(ByVal Buffer As String) As System.EventArgs) Handles MenuItem_Close.Click


ClosePort()
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As MenuItem_Open.Enabled = True
_ MenuItem_Close.Enabled = False
System.IO.Ports.SerialDataReceivedEventArgs) Handles End Sub
Serialport.DataReceived
Dim RecString As String = Serialport.ReadExisting Private Sub MenuItem10_Click(ByVal sender As System.Object, ByVal e As
'If Serialport.ReadBufferSize > 0 Then System.EventArgs) Handles MenuItem_Command_SN.Click
' Me.Invoke(New EventHandler(AddressOf DisplayData)) Dim DMAT As New System.IO.StreamReader("My documents\Meter-DM@.txt")
'End If Dim Context As String
Context = DMAT.ReadToEnd()
TextRec.BeginInvoke(New StringSubPointer(AddressOf DisplayData), TextSend.Text = "Commands Sending:" + Context
RecString) Serialport.Write(Context)
End Sub ' send command DM@
Private Sub DisplayData(ByVal Buffer As String) End Sub
TextRec.Text += Buffer
End Sub Private Sub MenuItem2_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem_Command_DT.Click
Private Sub MenuItem_Open_Click(ByVal sender As System.Object, ByVal e Dim DMF As New System.IO.StreamReader("My documents\Meter-DMF.txt")
As System.EventArgs) Handles MenuItem_Open.Click Dim Context As String
OpenPort() Context = DMF.ReadToEnd()
MenuItem_Open.Enabled = False TextSend.Text = "Commands Sending:" + Context
MenuItem_Close.Enabled = True Serialport.Write(Context)
End Sub ' send command DMF
End Sub
Private Sub MenuItem_Close_Click(ByVal sender As System.Object, ByVal e

XIX
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

MenuItem_COM9.Click
Private Sub MenuItem11_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem_Command_Records.Click With Serialport
Dim DMP As New System.IO.StreamReader("My documents\Meter-DMP.txt") Select Case MenuItem_Ports.MenuItems.IndexOf(sender)
Dim Context As String Case 0
Context = DMP.ReadToEnd() .PortName = "COM1"
TextSend.Text = "Commands Sending:" + Context Case 1
Serialport.Write(Context) .PortName = "COM2"
' send command DMP Case 2
End Sub .PortName = "COM3"
Case 3
Private Sub MenuItem12_Click(ByVal sender As System.Object, ByVal e As .PortName = "COM4"
System.EventArgs) Handles MenuItem_Command_Units.Click Case 4
Dim DMSU As New System.IO.StreamReader("My .PortName = "COM5"
documents\Meter-DMSU.txt") Case 5
Dim Context As String .PortName = "COM6"
Context = DMSU.ReadToEnd() Case 6
TextSend.Text = "Commands Sending:" + Context .PortName = "COM7"
Serialport.Write(Context) Case 7
' send command DMSU .PortName = "COM8"
End Sub Case 8
.PortName = "COM9"
Private Sub MenuItem_Ports_Click(ByVal sender As Object, ByVal e As End Select
EventArgs) Handles MenuItem_COM1.Click, MenuItem_COM2.Click, End With
MenuItem_COM3.Click, MenuItem_COM4.Click, MenuItem_COM5.Click, 'Selecting the COM number
MenuItem_COM6.Click, MenuItem_COM7.Click, MenuItem_COM8.Click, End Sub

XX
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Private Sub MenuItem_Exit_Click(ByVal sender As System.Object, ByVal e Case 7


As System.EventArgs) Handles MenuItem_Exit.Click .BaudRate = 115200
ClosePort() End Select
ExampleOrReal.Show() End With
End Sub ' selecting the Baudrate
End Sub
Private Sub MenuItem_Baudrate_Click(ByVal sender As System.Object, ByVal Private Sub MenuItem_databits_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MenuItem_115200.Click, MenuItem_1200.Click, e As System.EventArgs) Handles MenuItem_Databits_7.Click,
MenuItem_19200.Click, MenuItem_2400.Click, MenuItem_38400.Click, MenuItem_Databits_8.Click
MenuItem_4800.Click, MenuItem_57600.Click, MenuItem_9600.Click With Serialport
With Serialport Select Case MenuItem_Databits.MenuItems.IndexOf(sender)
Select Case MenuItem_Baudrate.MenuItems.IndexOf(sender) Case 0
Case 0 .DataBits = 7
.BaudRate = 1200 Case 1
Case 1 .DataBits = 8
.BaudRate = 2400 End Select
Case 2 ' selceting the databits
.BaudRate = 4800 End With
Case 3 End Sub
.BaudRate = 9600
Case 4 Private Sub MenuItem_stopbits_Click(ByVal sender As System.Object, ByVal
.BaudRate = 19200 e As System.EventArgs) Handles MenuItem_Stopbits_1.Click,
Case 5 MenuItem_Stopbits_15.Click, MenuItem_Stopbits_2.Click
.BaudRate = 38400 With Serialport
Case 6 Select Case MenuItem_Stopbits.MenuItems.IndexOf(sender)
.BaudRate = 57600 Case 0

XXI
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

.StopBits = StopBits.One End Select


Case 1 End With
.StopBits = StopBits.OnePointFive ' selecting the parity
Case 2 End Sub
.StopBits = StopBits.Two
End Select Private Sub MenuItem_CLRSend_Click(ByVal sender As System.Object, ByVal
End With e As System.EventArgs) Handles MenuItem_CLRSend.Click
'selecting the stopbits TextSend.Text = ""
End Sub 'clear send
End Sub
Private Sub MenuItem_Parity_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MenuItem_Parity_Even.Click, Private Sub MenuItem_CLRREC_Click(ByVal sender As System.Object, ByVal
MenuItem_Parity_Mark.Click, MenuItem_Parity_None.Click, e As System.EventArgs) Handles MenuItem_CLRREC.Click
MenuItem_Parity_Odd.Click, MenuItem_Parity_Space.Click TextRec.Text = ""
With Serialport 'clear receive
Select Case MenuItem_Parity.MenuItems.IndexOf(sender) End Sub
Case 0
.Parity = Parity.None Private Sub MenuItem_SaveREC_Click(ByVal sender As System.Object, ByVal
Case 1 e As System.EventArgs) Handles MenuItem_SaveRec_DT.Click,
.Parity = Parity.Odd MenuItem_SaveRec_Records.Click, MenuItem_SaveRec_SN.Click,
Case 2 MenuItem_SaveRec_Units.Click
.Parity = Parity.Even Select Case MenuItem_SaveREC.MenuItems.IndexOf(sender)
Case 3 Case 0
.Parity = Parity.Mark Dim SN As FileStream
Case 4 Dim bt1() As Byte
.Parity = Parity.Space 'Open the stream and write to it.

XXII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

SN = File.OpenWrite("my documents\meterdata\SN.txt") Units.Close()


bt1 = stringToByteArray(TextRec.Text) End Select
' Add some information End Sub
SN.Write(bt1, 0, bt1.Length)
SN.Close() Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
Case 1 System.EventArgs) Handles MenuItem2.Click
Dim DT As FileStream RecordsBar.Show()
Dim bt2() As Byte End Sub
DT = File.OpenWrite("my documents\meterdata\DT.txt")
bt2 = stringToByteArray(TextRec.Text) Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As
DT.Write(bt2, 0, bt2.Length) System.EventArgs) Handles MenuItem3.Click
DT.Close() Recordsline.Show()
Case 2 End Sub
Dim Records As FileStream
Dim bt3() As Byte End Class
Records = File.OpenWrite("my
documents\meterdata\Records.txt")
bt3 = stringToByteArray(TextRec.Text)
Records.Write(bt3, 0, bt3.Length)
Records.Close()
Case 3
Dim Units As FileStream
Dim bt4() As Byte
Units = File.OpenWrite("my documents\meterdata\Units.txt")
bt4 = stringToByteArray(TextRec.Text)
Units.Write(bt4, 0, bt4.Length)

XXIII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

B.8.1 Graphic Data Show- Overall Bar Loop


Imports System.Drawing.Graphics records.Close()
Imports System.IO End Sub

Public Class OverallBar


Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics As Drawing.Graphics Private Sub CalculateGraph(ByVal data() As Single)
Dim Max As New Single 'calculate the max, min, average values to represent in the graphic
Dim Min As New Single Max = data(0)
Dim sum As New Single Min = data(0)
Dim avg As New Single sum = 0
Public number As Int64 For i = 1 To number - 1
Dim Records As New System.IO.StreamReader("my If Max < data(i) Then
documents\meterdata\BGTest.txt") Max = data(i)
Dim i As Int64 = 0 End If
Dim line As String Next
Dim data(500) As Single For i = 1 To number - 1
Private Sub getdata(ByVal records As System.IO.StreamReader) If Min > data(i) Then
'Dim converter As String Min = data(i)
line = records.ReadLine() End If
line = records.ReadLine() Next
Do While (line <> "") For i = 0 To number - 1
data(i) = line.Substring(36, 3) / 18 sum += data(i)
i = i + 1 Next
number = number + 1 avg = sum / number
line = records.ReadLine() End Sub

XXIV
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As If data(m) > 10 Then


System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint g.FillRectangle(mybrush4, ret(m))
'called to paint in the picture box the blood suger leverls and the ElseIf data(m) > avg Then
boundaries g.FillRectangle(mybrush2, ret(m))
Dim g As Graphics = e.Graphics ElseIf data(m) > 5 Then
Dim RedPen As Pen = New Pen(Color.Red) g.FillRectangle(myBrush1, ret(m))
Dim myBrush1 As Brush = New SolidBrush(Color.Lime) Else : g.FillRectangle(mybrush5, ret(m))
Dim mybrush2 As Brush = New SolidBrush(Color.Blue) End If
Dim mybrush3 As Brush = New SolidBrush(Color.LightGray) Next
Dim mybrush4 As Brush = New SolidBrush(Color.Red) End Sub
Dim mybrush5 As Brush = New SolidBrush(Color.LightCoral)
Dim w As Integer = PictureBox1.Width Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
Dim h As Single = PictureBox1.Height System.EventArgs) Handles MenuItem1.Click
Call getdata(Records) example.Show()
Call CalculateGraph(data) End Sub
Dim Width As Integer = (w - 20) / number
Dim Height As Integer = h / 15 End Class
Dim ret(500) As Rectangle
'targeted Area
ret(400) = New Rectangle(0, PictureBox1.Height - Height * 10,
PictureBox1.Width, 5 * Height)
g.FillRectangle(mybrush3, ret(400))
Dim m As Int64
For m = 0 To number - 1
ret(m) = New Rectangle(Width * m + 10 * m / number + 5,
PictureBox1.Height - Height * data(m), Width, data(m) * Height)

XXV
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

B.8.2 Graphical Data Show- Datalist afdin = Convert.ToInt16(setup.ReadLine().Substring(0, 2))


setup.Close()
Imports System.IO ' read the time slot
Public Class DataList End Sub
Public bfbf As Int16 Public Sub getrecord5()
Public afbf As Int16 Dim i As Int64 = 0
Public bfluc As Int16 Dim record As New System.IO.StreamReader("my
Public afluc As Int16 documents\meterdata\BGTest.txt")
Public bfdin As Int16 'read the Serial Number Information
Public afdin As Int16 record.ReadLine()
Public line(500) As String line(i) = record.ReadLine()
Public TestDate(500) As String Do While (line(i) <> "")
Public Time(500) As String TestDate(i) = line(i).Substring(3, 3)
Public Slot(500) As String Time(i) = line(i).Substring(9, 8)
Public Slotdata(500) As Int16 Slotdata(i) = Convert.ToInt16(line(i).Substring(20, 2))
Public Value(500) As Single Value(i) = line(i).Substring(36, 3) / 18
Public number As Int64 = 0 i = i + 1
Public m As Integer = 0 number = number + 1
Public Sub getdata() line(i) = record.ReadLine()
Dim setup As New System.IO.StreamReader("my Loop
documents\meterdata\setup.txt") record.Close()
bfbf = Convert.ToInt16(setup.ReadLine().Substring(0, 2)) End Sub
afbf = Convert.ToInt16(setup.ReadLine().Substring(0, 2)) Public Sub DealWithSchedule()
bfluc = Convert.ToInt16(setup.ReadLine().Substring(0, 2)) Dim s As Int64
afluc = Convert.ToInt16(setup.ReadLine().Substring(0, 2)) getdata()
bfdin = Convert.ToInt16(setup.ReadLine().Substring(0, 2)) getrecord5()

XXVI
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

For s = 0 To number - 1 Me.TextBox5.Text = TestDate(x * 5 + 1)


'determine the time slot Me.TextBox9.Text = TestDate(x * 5 + 2)
If ((bfbf < Slotdata(s) And Slotdata(s) < afbf) Or Slotdata(s) Me.TextBox13.Text = TestDate(x * 5 + 3)
= bfbf) Then Me.TextBox17.Text = TestDate(x * 5 + 4)
Slot(s) = "Before Breakfast" Me.TextBox2.Text = Time(x * 5)
ElseIf ((afbf < Slotdata(s) And Slotdata(s) < bfluc) Or Slotdata(s) Me.TextBox6.Text = Time(x * 5 + 1)
= afbf) Then Me.TextBox10.Text = Time(x * 5 + 2)
Slot(s) = "After Breakfast" Me.TextBox14.Text = Time(x * 5 + 3)
ElseIf ((bfluc < Slotdata(s) And Slotdata(s) < afluc) Or Me.TextBox18.Text = Time(x * 5 + 4)
Slotdata(s) = bfluc) Then Me.TextBox4.Text = Value(x * 5)
Slot(s) = "Before Lunch" Me.TextBox8.Text = Value(x * 5 + 1)
ElseIf ((afluc < Slotdata(s) And Slotdata(s) < bfdin) Or Me.TextBox12.Text = Value(x * 5 + 2)
Slotdata(s) = afluc) Then Me.TextBox16.Text = Value(x * 5 + 3)
Slot(s) = "After Lunch" Me.TextBox20.Text = Value(x * 5 + 4)
ElseIf ((bfdin < Slotdata(s) And Slotdata(s) < afdin) Or Me.TextBox3.Text = Slot(x * 5)
Slotdata(s) = bfdin) Then Me.TextBox7.Text = Slot(x * 5 + 1)
Slot(s) = "Before Dinner" Me.TextBox11.Text = Slot(x * 5 + 2)
ElseIf (Slotdata(s) = afdin Or Slotdata(s) > afdin Or Slotdata(s) Me.TextBox15.Text = Slot(x * 5 + 3)
< bfbf) Then Me.TextBox19.Text = Slot(x * 5 + 4)
Slot(s) = "After Dinner" ' show the data on that page
End If End Sub
Next Private Sub DataList_Load(ByVal sender As System.Object, ByVal e As
End Sub System.EventArgs) Handles MyBase.Load
Public Sub ShowRecords5(ByVal x As Integer) ShowRecords5(m)
DealWithSchedule() End Sub
Me.TextBox1.Text = TestDate(x * 5)

XXVII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As Set the Time Slot
System.EventArgs) Handles MenuItem2.Click Imports System.IO
'only show the existed records in limited pages Public Class patient_setup
If (TextBox4.Text = "0" Or TextBox8.Text = "0" Or TextBox12.Text = Public bfbf As String
"0" Or TextBox16.Text = "0" Or TextBox20.Text = "0") Then Public afbf As String
MenuItem2.Enabled = False Public bfluc As String
Else Public afluc As String
m = m + 1 Public bfdin As String
ShowRecords5(m) Public afdin As String
End If Public Sub getdata()
End Sub Dim setup As New System.IO.StreamReader("my
documents\meterdata\setup.txt")
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As bfbf = setup.ReadLine()
System.EventArgs) Handles MenuItem1.Click afbf = setup.ReadLine()
example.Show() bfluc = setup.ReadLine()
End Sub afluc = setup.ReadLine()
End Class bfdin = setup.ReadLine()
afdin = setup.ReadLine()
setup.Close()
'get the already set data
End Sub
Public Sub savedata()
Dim setup As New System.IO.StreamWriter("my
documents\meterdata\setup.txt")
setup.WriteLine(Me.TextBox1.Text)
setup.WriteLine(Me.TextBox2.Text)

XXVIII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

setup.WriteLine(Me.TextBox3.Text) Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As


setup.WriteLine(Me.TextBox4.Text) System.EventArgs) Handles MenuItem1.Click
setup.WriteLine(Me.TextBox5.Text) example.Show()
setup.WriteLine(Me.TextBox6.Text) End Sub
setup.Close()
' reset the data Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
End Sub System.EventArgs) Handles MenuItem2.Click
savedata()
Private Sub patient_setup_Load(ByVal sender As System.Object, ByVal e As getdata()
System.EventArgs) Handles MyBase.Load Me.TextBox1.Text = bfbf
getdata() Me.TextBox2.Text = afbf
Me.TextBox1.Text = bfbf Me.TextBox3.Text = bfluc
Me.TextBox2.Text = afbf Me.TextBox4.Text = afluc
Me.TextBox3.Text = bfluc Me.TextBox5.Text = bfdin
Me.TextBox4.Text = afluc Me.TextBox6.Text = afdin
Me.TextBox5.Text = bfdin Me.Label1.Text = afbf
Me.TextBox6.Text = afdin Me.Label11.Text = bfluc
Me.Label1.Text = afbf Me.Label12.Text = afluc
Me.Label11.Text = bfluc Me.Label13.Text = bfdin
Me.Label12.Text = afluc Me.Label14.Text = afdin
Me.Label13.Text = bfdin Me.Label15.Text = bfbf
Me.Label14.Text = afdin End Sub
Me.Label15.Text = bfbf End Class
End Sub

XXIX
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

B.8.3 Graphical Data Show-Trend System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint


Public Class Recordsline ' Draw line to screen.
Dim line As String Dim g As Graphics = e.Graphics
Dim Max As New Single 'creat pen
Dim Min As New Single Dim bluePen As Pen = New Pen(Color.Blue)
Dim sum As New Single Dim RedPen As Pen = New Pen(Color.Red)
Dim avg As New Single Dim brushgray As New SolidBrush(Color.LightGray)
Public number As Int64 Dim w As Integer = PictureBox1.Width
Dim Records As New System.IO.StreamReader("my Dim h As Integer = PictureBox1.Height
documents\meterdata\records.txt") Call getdata(Records)
Dim i As Int64 = 0 Dim Width As Integer = (w - 10) / number
Dim data(500) As Single Dim Height As Single = h / 15
Private Sub getdata(ByVal records As System.IO.StreamReader) Dim m As Int64
line = records.ReadLine() Dim x(500) As Single
line = records.ReadLine() Dim y(500) As Single
Do While (line <> "") For m = 0 To number - 1
data(i) = line.Substring(36, 3) / 18 x(m) = PictureBox1.Left + Width * m
' read each glucose data and change mg/dl to mmol/l y(m) = PictureBox1.Height - Height * data(m)
i = i + 1 Next
number = number + 1 Dim ret As New Rectangle(0, PictureBox1.Height - Height * 10,
line = records.ReadLine() PictureBox1.Width, 5 * Height)
Loop g.FillRectangle(brushgray, ret)
records.Close() For m = 0 To number - 2
End Sub e.Graphics.DrawLine(bluePen, x(m), y(m), x(m + 1), y(m + 1))
' draw the lines between each points
Public Sub DrawLinePoint(ByVal sender As Object, ByVal e As e.Graphics.DrawEllipse(RedPen, x(m), y(m), 5, 5)

XXX
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

' draw the data point B.8.4 Graphical Data Show- Standard Day
Next
e.Graphics.DrawEllipse(RedPen, x(number - 1), y(number - 1), 5, 5) Public Class StandardDay
Dim line As String
End Sub Dim Max As New Single
Dim Min As New Single
Dim sum As New Single
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As Dim avg As New Single
System.EventArgs) Handles MenuItem1.Click Public number As Int64
SerialPort.Show() Dim Records As New System.IO.StreamReader("my
End Sub documents\meterdata\BGTest.txt")
Dim i As Int64 = 0
End Class Dim data(500) As Single
Dim hour(500) As Int16
Dim mint(500) As Int16
Private Sub getdata(ByVal records As System.IO.StreamReader)
line = records.ReadLine()
line = records.ReadLine()
Do While (line <> "")
data(i) = line.Substring(36, 3) / 18
' read each test data
hour(i) = Convert.ToInt16(line.Substring(20, 2))
'read each test hour
mint(i) = Convert.ToInt16(line.Substring(23, 2))
'read each test minute
i = i + 1

XXXI
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

number = number + 1 If hour(m) > 6 Or hour(m) = 6 Then


line = records.ReadLine() x(m) = ((hour(m) - 6) * PictureBox1.Width / 24) + (mint(m)
Loop * PictureBox1.Width / (24 * 60))
records.Close() ' set the value of x-cordinator by the time
End Sub Else : x(m) = ((hour(m) - 6) * PictureBox1.Width / 24) + (mint(m)
* PictureBox1.Width / (24 * 60))
Public Sub DrawLinePoint(ByVal sender As Object, ByVal e As End If
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint y(m) = PictureBox1.Bottom - Height * data(m)
' Draw line to screen. ' set the value of y-cordinator by the test data
Dim g As Graphics = e.Graphics Next
'creat pen For m = 0 To number - 1
Dim bluePen As Pen = New Pen(Color.Blue) e.Graphics.DrawEllipse(RedPen, x(m), y(m), 2, 2)
Dim RedPen As Pen = New Pen(Color.Red) Next
Dim graybrush As Brush = New SolidBrush(Color.LightGray)
Dim w As Integer = PictureBox1.Width
Dim h As Integer = PictureBox1.Height End Sub
Call getdata(Records)
Dim Width As Integer = (w - 10) / number
Dim Height As Integer = h / 15 Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
Dim m As Int64 System.EventArgs) Handles MenuItem1.Click
Dim x(500) As Single example.Show()
Dim y(500) As Single End Sub
Dim ret As New Rectangle(0, PictureBox1.Bottom - Height * 10, End Class
PictureBox1.Width, 5 * Height)
g.FillRectangle(graybrush, ret)
For m = 0 To number - 1

XXXII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

B.9.1 Smart Data Analysis – Insuline Dose Suggestion food = food2


Imports System.IO.file End If
Imports System.IO If CheckBox3.CheckState Then
Public Class Suggestion food = food3
Public food As String End If
Public Ex As String If CheckBox4.CheckState Then
Dim food1 As String = "Not Enough Food " Ex = Ex1
Dim food2 As String = "Adequate Food" End If
Dim food3 As String = "Too Much Food" If CheckBox5.CheckState Then
Dim data As System.DateTime = System.DateTime.Today Ex = Ex2
Dim Ex1 As String = "No Exercise" End If
Dim Ex2 As String = "Mild Exercise" If CheckBox6.CheckState Then
Dim Ex3 As String = "Hard Exercise" Ex = Ex3
Dim i1 As Single = 1 End If
Dim i2 As Single = 1 Dim path As String = "my documents\logbook.txt"
Dim i3 As Single = 1 Dim sw As system.IO.StreamWriter
Dim i As Single 'append the context
sw = File.AppendText(path)
sw.WriteLine(DateTime.Today.Date + " " + food + " " + Ex)
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As sw.Flush()
System.EventArgs) Handles MenuItem3.Click sw.Close()
End Sub
If CheckBox1.CheckState Then
food = food1
End If Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As
If CheckBox2.CheckState Then System.EventArgs) Handles MenuItem4.Click

XXXIII
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

If CheckBox3.CheckState Then
Dim record As New System.IO.StreamReader("my i1 = 2
documents\meterdata\BGTest.txt") End If
Dim BGdate As String If CheckBox4.CheckState Then
Dim value As Single i2 = 2
'read the Serial Number Information End If
record.ReadLine() If CheckBox6.CheckState Then
Dim line As String = record.ReadLine() i2 = 0.5
Dim data As String = (Convert.ToString(DateTime.Today.Date)) End If
BGdate = line.Substring(9, 8) i = i1 * i2 * i3
If i > 1 Then
If (data.Substring(0, 2) = BGdate.Substring(3, 2) And TextBox1.Text = "Suggestion:You need a little more insulin today"
data.Substring(3, 2) = BGdate.Substring(0, 2) And data.Substring(8, 2) = ElseIf i < 1 Then
BGdate.Substring(6, 2)) Then TextBox1.Text = "Suggestion: You need a little less insulin today"
value = line.Substring(36, 3) / 18 Else : TextBox1.Text = "You are perfect in control today!"
If value > 10 Then i3 = 2 End If
If value < 5 Then i3 = 0.5 ' combine the information of daily food consumption, activity and
Else : MessageBox.Show("No Blood Glucose Record Today", "No BG Test glucose level to adjust the insuline dose
Today?", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, End Sub
MessageBoxDefaultButton.Button1)
' if no blood glucose tested today, then messagebox shows Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
End If System.EventArgs) Handles MenuItem1.Click
record.Close() lifeclinic.Show()
If CheckBox1.CheckState Then End Sub
i1 = 0.5
End If End Class

XXXIV
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

B.9.2 Smart Data Analysis – Data Analyzer data(i) = line.Substring(36, 3) / 18


Imports System.Drawing.Graphics i = i + 1
Imports System.IO number = number + 1
line = records.ReadLine()
Public Class Analyzer Loop
records.Close()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red) End Sub
Dim formGraphics As Drawing.Graphics
Dim Max As New Single Private Sub Calculate(ByVal data() As Single)
Dim Min As New Single 'calculate the max, min, average values to represent in the graphic
Dim sum As New Single Max = data(0)
Dim avg As New Single Min = data(0)
Public number As Int64 sum = 0
Dim Records As New System.IO.StreamReader("my For i = 1 To number - 1
documents\meterdata\BGTest.txt") If Max < data(i) Then
Dim i As Int64 = 0 Max = data(i)
Dim line As String End If
Dim data(500) As Single Next
Dim controlNo As Int64
Dim Percentage As New Single For i = 1 To number - 1
If Min > data(i) Then
Private Sub getdata(ByVal records As System.IO.StreamReader) Min = data(i)
'Dim converter As String End If
line = records.ReadLine() Next
line = records.ReadLine()
Do While (line <> "")

XXXV
Smartphone for Children with Diabetes University of Birmingham
Xiaojia Jiang

For i = 0 To number - 1 ElseIf (Percentage > 0.95 Or Percentage = 0.95) Then


sum += data(i) TextBox7.Text = "Good in Control"
Next Else : TextBox7.Text = "More Attention"
avg = sum / number End If
For i = 0 To number - 1 End Sub
If (5 < data(i) Or 5 = data(i)) And (data(i) < 10 Or data(i) =
10) Then Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
controlNo = controlNo + 1 System.EventArgs) Handles MenuItem1.Click
End If example.Show()
Next End Sub
Percentage = (controlNo / number) * 100%
End Sub End Class

Private Sub analyzer_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
getdata(Records)
Calculate(data)
TextBox1.Text = Max
TextBox2.Text = Min
TextBox3.Text = avg
TextBox4.Text = number
TextBox5.Text = controlNo
TextBox6.Text = Percentage & "%"
' give different comments
If Percentage = 1.0 Then
TextBox7.Text = "Perfect in Control"

XXXVI

Вам также может понравиться