final report xiaojia jiang

91
Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang I BEng Final Year Project Smartphone for Children with Diabetes Final Report Xiaojia Jiang Student ID830127 SupervisorDr. S. I. Woolley

Upload: suleman-jamil

Post on 27-Nov-2014

151 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

I

BEng Final Year Project Smartphone for Children with Diabetes

Final Report

Xiaojia Jiang Student ID:830127

Supervisor:Dr. S. I. Woolley

Page 2: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

II

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

Page 3: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

III

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:

Personal Medical Record Information Provider

Insulin Injection Reminder

Children’s Diabetic Education

Emergency Contact

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.

Page 4: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

IV

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

Page 5: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

V

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

Page 6: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

VI

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

Page 7: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

VII

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

Page 8: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

VIII

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

Page 9: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 1 -

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

Page 10: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 2 -

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.

Figure 2: Data transmission model

Blood Glucose Meter Bluetooth RS232 Adapter Mobile Phone

Page 11: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 3 -

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

Page 12: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 4 -

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

Page 13: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 5 -

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.

Page 14: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 6 -

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

Page 15: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 7 -

-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

Provide doctor with an accurate and easy-to-read record, to make it easier to

discuss user’s diabetes management

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.

Page 16: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 8 -

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

Page 17: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 9 -

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:

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.

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.

Children’s Diabetic Education: Let children with diabetes gain knowledge about

their disease through interesting books and games

Page 18: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 10 -

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

OneTouch Ultra2 Meter (with a serial data port)

OneTouch Ultra Test Strips

Control Solution

Lancets

The OneTouch Interface Cable (9-pin serial)

5.1.3 Meter’s RS-232 Communication Protocol

a. Port Settings

Table1: Meter’s port settings

Baud Rate=9600 bps Data Bits=8

Stop Bits=1 Parity = none

Flow Control= None Com Port= port # utilized

Page 19: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 11 -

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

DM?-send the Meter’s software version and date

DM@-send the Meter’s serial number

DMF-send date and time from the Meter’s clock

DMP-upload blood and control records from the Meter’s memory

DMSU?-display the glucose units

RS-232 Data Management Commands

Table 2: Meter’s cabling

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

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

Page 20: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 12 -

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:

Bluetooth serial adapter

Antenna

USB cable for power supply

Page 21: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 13 -

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

Page 22: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 14 -

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

Page 23: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 15 -

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:

Establish the secure partnership to ensure the privacy of the personal medical

information

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

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.

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.

Page 24: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 16 -

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

Page 25: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 17 -

User interface description:

Open Port: open the selected virtual serial port on the mobile phone

Close Port: close the opened port

Send Command: different command in .txt format can be sent to the meter to

obtain the needed information.

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.

Clear Send: Clear the send file in the sending text box.

Clear Receive: Clear the received data in the received text box.

Save Receive: Save the received data in the specific file folder selected by the

user.

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.

Page 26: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 18 -

7.2 Components

This part of interface includes:

Two DCE devices: blood glucose meter and the adapter

OneTouch Interface Cable (9-pin serial)

Self soldered board

+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:

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.

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.

RS-232 is a simple protocol that provides easy interface. In the programming,

implementing an RS-232 interface will simplify the data interpretation process.

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).

“RS-232 compatible” can use non-standard pin assignment of circuits on

connectors, which can facilitate the communication between two DCE devices.

Page 27: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 19 -

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

Page 28: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 20 -

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

However, in this designed telemedicine system, communication

should be established between two DCE devices- the meter and

the adapter. There are two reasons to call it a technical challenge

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

TXD - RXD RXD - TXD RTS - CTS CTS- RTS GND-GND

Page 29: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 21 -

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.

Page 30: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 22 -

7.4.3 Method

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.

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

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.

HEX Command

Send

Command

Meter

Data

Meter

Data

Page 31: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 23 -

Figure 15: Data transmission flow chart

Page 32: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 24 -

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 T A R T

1

0 0 0

1

0 0 0

STOP

START

1

0

1 1

0 0 0 0

S T O P

START

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

first 20 bits)

Page 33: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 25 -

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

Page 34: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 26 -

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

Page 35: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 27 -

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

Page 36: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 28 -

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.

Page 37: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

- 29 -

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

Page 38: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

30

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.

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

Time setting format: 09:00

Three different time can be set

Page 39: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

31

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

Page 40: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

32

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.

Page 41: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

33

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.

Page 42: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

34

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

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

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

Page 43: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

35

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

Page 44: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

36

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.

Page 45: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

37

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 Meter (see 5.1)

Data output 1. Sending Command by HyperTerminal and receive data by HyperTerminal 2. Sending Command by self-written software and receive data by it 3. Testing signal by oscilloscope

1. using the self-written code, different command should be used

2. no errors were detected

In data transmission

Smartphone -Adapter Interface (see Section 6 )

Connection Pair these two devices Successful secure paring

Meter- Smartphone Interface (see Section 8 )

Connection and data transmission

Send .txt format command form the smartphone to meter

1. meter respond immediately when it receive the command

2. successful data transmission

3. no errors were received

Page 46: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

38

* means the negative test result

Table 6: Functionality testing

Part Testing Areas Testing Method Testing Result Meter data processing

1.correct conversion from mg/dl to more commonly used mmol/ml 2.correct graph display

1.compare the data in mmol/ml in the smartphone with the reading from the meter 2.compare the graphs with the changes of data

1. data conversion without errors

2. graph representation without errors

Insulin Injection Reminder

1.Correct next-time show 2.correct alarm information show

set proper alarm time and wait for the alarm information show

1. alarm arrives at the pre-set time

2. can only be implemented in this application on the smartphone, can not use as a background-working alarm

Emergency Contact

Sending SMS by pressing a button

Set an available mobile phone number in the code, check whether it can receive the emergency message

1. SMS can be received by the other mobile phone immediately

*2. severely delayed when the signal is weak

Quizzes Correct responses to the user’s answer

Compare the Smartphone’s answer feedback to the correct answer

Right feedback was shown to deal with correct or wrong answers

Page 47: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

39

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:

Self-descriptiveness

Controllability

Suitability for task

Conformity with user expectations

Error to tolerance

Suitability for individualization

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

Page 48: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

40

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

Page 49: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

41

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:

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.

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.

Page 50: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

42

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

Page 51: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

43

[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

Page 52: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

44

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

Page 53: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

45

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

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:

Comments:

Page 54: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

46

3. How would you rate the multifunction of the program? Not useful at all OK Very useful

1 2 3 4 5

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

5. How easy did you find to use the function of “Diabetic Reminder”?

Very difficult OK Very easy 1 2 3 4 5

6. How interesting would you rate the “Children’s Corner”? Not interesting at all OK Very interesting

1 2 3 4 5

Comments:

Comments:

Comments:

Comments:

Page 55: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

47

7. How useful would you rate the “Emergency Contact”? Not useful at all OK Very useful

1 2 3 4 5

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

Very difficult OK Very easy 1 2 3 4 5

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:

Comments:

Comments:

Page 56: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

I

Appendix B: Visual Basic Code NB. The code in Black was written entirely by myself

The code in Red was taken from others and modified by myself The code in orange was taken from others without modification

Code lists: B.1 Main Interface --------------------------------------------------------- I B.2 Show Every Day Tip -------------------------------------------------II B.3 Emergency Contact- Sending SMS --------------------------------IV B.4 Book Reading Example ---------------------------------------------XI B.5 Quiz Example --------------------------------------------------------XI B.6 Insulin Injection Reminder ----------------------------------------XII B.7 Serial Port Setting -------------------------------------------------XVII B.8.1 Graphical Data Show- Overall Bar --------------------------XXIV B.8.2 Graphical Data Show-Datalist --------------------------------XXVI B.8.3 Graphical Data Show-Standard Day -------------------------XXX 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

B.1 Main Interface Public Class main_interface

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

System.EventArgs) Handles MyBase.Load

'load image to the picturebox

Dim MyImage As New Bitmap("\my documents\main interface.jpg")

PictureBox1.Image = CType(MyImage, Image)

End Sub

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

System.EventArgs) Handles MenuItem1.Click

Form1.Show()

End Sub

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

System.EventArgs) Handles MenuItem2.Click

emergency.Show()

End Sub

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

Page 57: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

II

System.EventArgs) Handles MenuItem4.Click

SerialPort.Show()

End Sub

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

System.EventArgs) Handles MenuItem3.Click

emergency.Show()

End Sub

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

System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

ExampleOrReal.Show()

End Sub

End Class

B.2 Show Everyday Tip

Imports System.io

Imports System.data

Public Class Form1

Inherits System.Windows.Forms.Form

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

Friend WithEvents TextBox2 As System.Windows.Forms.TextBox

Friend WithEvents TextBox3 As System.Windows.Forms.TextBox

Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents TextBox5 As System.Windows.Forms.TextBox

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

Page 58: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

III

frmform13.Show()

End Sub

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

System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress

Form4.Show()

End Sub

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

System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress

lifeclinic.Show()

End Sub

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

System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress

showtip()

End Sub

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

System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress

ExampleOrReal.Show()

End Sub

Public Sub showtip()

' show everyday tip

Dim file As New System.IO.StreamReader("my documents\tips.txt")

Dim line As Integer

Dim i As New Int16

Dim context As String

line = DateTime.Now.Day

' select tip by the date

Do While line > 0

line = line - 1

context = file.ReadLine()

Loop

'show messagebox

MessageBox.Show(context, "Tips Everyday", MessageBoxButtons.OK,

MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)

file.Close()

End Sub

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

System.EventArgs) Handles MenuItem2.Click

If TextBox1.Focused Then

Dim frmform12 As New Form2

frmform12.Show()

ElseIf TextBox2.Focused Then

Dim frmform13 As New Form3

frmform13.Show()

ElseIf TextBox3.Focused Then

Dim frmform14 As New Form4

frmform14.Show()

Page 59: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

IV

ElseIf TextBox4.Focused Then

Dim frmform14 As New lifeclinic

frmform14.Show()

ElseIf TextBox5.Focused = True Then

showtip()

ElseIf TextBox6.Focused = True Then

Dim frm1e As New ExampleOrReal

frm1e.Show()

End If

End Sub

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

System.EventArgs) Handles MenuItem1.Click

Dim frm1m As New main_interface

frm1m.Show()

End Sub

End Class

B.3 Emergency Contact-Sending SMS

Public Class emergency

Inherits System.Windows.Forms.Form

Friend WithEvents Button1 As System.Windows.Forms.Button

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

System.EventArgs) Handles Button1.Click

SMS.SendMessage(txtPhoneNumber.Text, txtMessage.Text)

End Sub

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

System.EventArgs) Handles MenuItem1.Click

Me.Close()

End Sub

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

System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown

SMS.SendMessage(txtPhoneNumber.Text, txtMessage.Text)

End Sub

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

Page 60: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

V

SMS Class

Imports System.Runtime.InteropServices

Imports interopserv = System.Runtime.InteropServices

Public Enum SMS_ADDRESS_TYPE

SMSAT_UNKNOWN = 0

SMSAT_INTERNATIONAL

SMSAT_NATIONAL

SMSAT_NETWORKSPECIFIC

SMSAT_SUBSCRIBER

SMSAT_ALPHANUMERIC

SMSAT_ABBREVIATED

End Enum 'SMS_ADDRESS_TYPE

Public Structure PhoneAddress

'/ <summary>The address type.</summary>

Public AddressType As SMS_ADDRESS_TYPE

'/ <summary>The phone number in string format.</summary>

Public Address() As Char

End Structure 'PhoneAddress

Public Class SMS

Private Shared SMS_MSGTYPE_TEXT As String = "Microsoft Text SMS Protocol"

Private Shared SMS_MODE_SEND As Long = &H2

Private Shared SMS_OPTION_DELIVERY_NONE As Long = &H0

Private Shared SMS_OPTION_DELIVERY_NO_RETRY As Long = &H1

Private Shared PS_MESSAGE_OPTION_NONE As Long = &H0

Private Enum SMS_DATA_ENCODING

SMSDE_OPTIMAL = 0

SMSDE_GSM

SMSDE_UCS2

End Enum 'SMS_DATA_ENCODING

Public Enum PROVIDER_SPECIFIC_MESSAGE_CLASS

PS_MESSAGE_CLASS0 = 0

PS_MESSAGE_CLASS1

PS_MESSAGE_CLASS2

PS_MESSAGE_CLASS3

End Enum 'PROVIDER_SPECIFIC_MESSAGE_CLASS

Private Enum PROVIDER_SPECIFIC_REPLACE_OPTION

PSRO_NONE = 0

PSRO_REPLACE_TYPE1

PSRO_REPLACE_TYPE2

PSRO_REPLACE_TYPE3

PSRO_REPLACE_TYPE4

PSRO_REPLACE_TYPE5

PSRO_REPLACE_TYPE6

PSRO_REPLACE_TYPE7

PSRO_RETURN_CALL

Page 61: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

VI

PSRO_DEPERSONALIZATION

End Enum 'PROVIDER_SPECIFIC_REPLACE_OPTION

Private Structure TEXT_PROVIDER_SPECIFIC_DATA

Public dwMessageOptions As Long

Public psMessageClass As PROVIDER_SPECIFIC_MESSAGE_CLASS

Public psReplaceOption As PROVIDER_SPECIFIC_REPLACE_OPTION

End Structure 'TEXT_PROVIDER_SPECIFIC_DATA

<System.Runtime.InteropServices.DllImport("sms.dll")> _

Private Shared Function SmsOpen(ByVal ptsMessageProtocol As [String], _

End Function

<System.Runtime.InteropServices.DllImport("sms.dll")> _

Private Shared Function SmsSendMessage(ByVal smshHandle As IntPtr, _

End Function

<System.Runtime.InteropServices.DllImport("sms.dll")> _

Private Shared Function SmsClose(ByVal smshHandle As IntPtr) As IntPtr

End Function

<StructLayout(LayoutKind.Sequential)> _

Public Structure MsgSize

Public MsgSz As Int32

End Structure

<StructLayout(LayoutKind.Sequential)> _

Public Structure ProviderDataSize

Public ProvDataSize As Int32

End Structure

Public Shared Sub SendMessage(ByVal sPhoneNumber As String, ByVal

sMessage As String)

Dim retVal As IntPtr = IntPtr.Zero

Dim smsHandle As IntPtr = IntPtr.Zero

Dim smsProviderData As IntPtr = IntPtr.Zero

Dim smsMessage As IntPtr = IntPtr.Zero

Dim ProvData(12) As Byte

Try

retVal = SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, smsHandle,

IntPtr.Zero)

If retVal.ToInt32 <> 0 Then

Throw New Exception("Could not open SMS.")

End If

'Set address structure

Dim smsatAddressType As Byte() =

BitConverter.GetBytes(SMS_ADDRESS_TYPE.SMSAT_UNKNOWN)

Dim ptsAddress As Byte() =

System.Text.Encoding.Unicode.GetBytes(sPhoneNumber)

Dim smsAddressTag(smsatAddressType.Length + ptsAddress.Length)

Page 62: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

VII

As Byte

Array.Copy(smsatAddressType, 0, smsAddressTag, 0,

smsatAddressType.Length)

Array.Copy(ptsAddress, 0, smsAddressTag,

smsatAddressType.Length, ptsAddress.Length)

Dim smsAddress As IntPtr =

Marshal.AllocHLocal(smsAddressTag.Length)

System.Runtime.InteropServices.Marshal.Copy(smsAddressTag, 0,

smsAddress, smsAddressTag.Length)

'Set message

Dim smsMessageTag As Byte() =

System.Text.Encoding.Unicode.GetBytes(sMessage)

smsMessage = Marshal.AllocHLocal(smsMessageTag.Length)

System.Runtime.InteropServices.Marshal.Copy(smsMessageTag, 0,

smsMessage, smsMessageTag.Length)

retVal = SmsSendMessage(smsHandle, 0, smsAddress, 0, smsMessage,

smsMessageTag.Length, _

ProvData, 12, SMS_DATA_ENCODING.SMSDE_OPTIMAL,

SMS_OPTION_DELIVERY_NONE, 0)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

Try

retVal = SmsClose(smsHandle)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

End Class

Class Marsha

Imports System

Imports interopserv = System.Runtime.InteropServices

Imports System.ComponentModel

'Namespace NetCF.Runtime.InteropServices

Public NotInheritable Class Marshal

Private Class WinApi

Public Const LMEM_FIXED As Long = 0

Public Const LMEM_MOVEABLE As Long = 2

Public Const LMEM_ZEROINIT As Long = &H40

Public Const LPTR As Long = LMEM_FIXED Or LMEM_ZEROINIT

'private constructor prevents instantiation

Private Sub New()

Page 63: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

VIII

End Sub

' imported functions

<System.Runtime.InteropServices.DllImport("coredll.dll",

SetLastError:=True)> _

Public Shared Function LocalAlloc(ByVal uFlags As System.Int32, ByVal

uBytes As System.Int32) As IntPtr

End Function

<System.Runtime.InteropServices.DllImport("coredll.dll",

SetLastError:=True)> _

Public Shared Function LocalFree(ByVal hMem As IntPtr) As IntPtr

End Function

<System.Runtime.InteropServices.DllImport("coredll.dll",

SetLastError:=True)> _

Public Shared Function LocalReAlloc(ByVal hMem As IntPtr, ByVal

uBytes As System.Int64, ByVal fuFlags As System.Int64) As IntPtr

End Function

End Class 'WinApi

'private contructor prevents instantiation

Private Sub New()

End Sub

'memory allocation / deallocation methods

'/ Allocates a block of memory using LocalAlloc.

'/ <param name="cb">The number of bytes in memory required.</param>

'/ <returns>

'/ An IntPtr to the newly allocated memory. This memory must be

'/ released using the Marshal.FreeHLocal method.

'/ </returns>

'/ <exception cref="OutOfMemoryException">

'/ There is insufficient memory to satisfy the request.

'/ </exception>

'/ <remarks>

'/ AllocHlocal exposes the LocalAlloc WinCE API from CoreDll.dll.

'/ For additional information about LocalAlloc, see the MSDN Library.

Public Shared Function AllocHLocal(ByVal cb As Int32) As IntPtr

Try

Return WinApi.LocalAlloc(WinApi.LPTR, cb)

Catch ex As Exception

End Try

End Function

'/ Frees memory previously allocated from the unmanaged memory

'/ of the process with AllocHLocal.

'/ <param name="hlocal">The handle returned by the original matching call

to AllocHLocal.</param>

'/ <exception cref="Win32Exception">

'/ Indicates failure. The exception contains the error code obtained from

GetLastError.

Page 64: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

IX

'/ </exception>

'/ <remarks>

'/ You can use FreeHlocal to free any memory from the heap allocated by

AllocHLocal or

'/ ReAllocHLocal, or any equivalent unmanaged API method. If the hlocal

parameter is a

'/ null reference (Nothing in Visual Basic), the method does nothing.

FreeHlOCAL exposes

'/ the LocalFree function from CoreDll.DLL, which frees all bytes so that

you can no longer

'/ use the memory pointed to by <paramref name="hLocal"/>. For additional

information about

'/ LocalFree, see the MSDN Library.

Public Shared Sub FreeHLocal(ByVal hlocal As IntPtr)

'If hlocal <> IntPtr.Zero Then

If hlocal.ToInt32 <> 0 Then

'If IntPtr.Zero <> WinApi.LocalFree(hlocal) Then

If WinApi.LocalFree(hlocal).ToInt32 <> 0 Then

Throw New

Win32Exception(interopserv.Marshal.GetLastWin32Error())

End If

hlocal = IntPtr.Zero

End If

End Sub

'/ Resizes a block of memory previously allocated with AllocHLocal.

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

AllocHLocal.</param>

'/ <param name="cb">The new size of the allocated block.</param>

'/ <returns>

'/ An IntPtr to the reallocated memory. This memory must be released

'/ using Marshal.FreeHLocal.

'/ </returns>

'/ <exception cref="OutOfMemoryException">

'/ There is insufficient memory to satisfy the request.

'/ </exception>

'/ <remarks>

'/ ReAllocHLocal exposes the LocalRealloc WinCE API method from

CoreDll.dll.

'/ The returned pointer can differ from the original. For additional

information

'/ about LocalAlloc, see the MSDN Library.

'/ </remarks>

Public Shared Function ReAllocHLocal(ByVal pv As IntPtr, ByVal cb As

Integer) As IntPtr

Dim newMem As IntPtr = WinApi.LocalReAlloc(pv, CType(cb,

System.Int64), WinApi.LMEM_MOVEABLE)

'If newMem = IntPtr.Zero Then

If newMem.ToInt32 = 0 Then

Throw New OutOfMemoryException

End If

Return newMem

Page 65: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

X

End Function

'/ Copies the contents of a managed String into unmanaged memory.

'/ <param name="s">A managed string to be copied.</param>

'/ <returns>

'/ The address, in unmanaged memory, to where the s was copied, or 0 if

a null reference

'/ (Nothing in Visual Basic) string was supplied.

'/ </returns>

Public Shared Function StringToHLocalUni(ByVal s As String) As IntPtr

If s Is Nothing Then

Return IntPtr.Zero

Else

Dim nc As Integer = s.Length

Dim len As Integer = 2 * (1 + nc)

Dim hLocal As IntPtr = AllocHLocal(len)

'If hLocal = IntPtr.Zero Then

If hLocal.ToInt32 = 0 Then

Throw New OutOfMemoryException

Else

interopserv.Marshal.Copy(s.ToCharArray(), 0, hLocal,

s.Length)

Return hLocal

End If

End If

End Function 'StringToHLocalUni

Public Shared Function IntToHLocalUni(ByVal s As Int32) As IntPtr

If s = 0 Then

Return IntPtr.Zero

Else

Dim nc As Integer = interopserv.Marshal.SizeOf(s)

Dim len As Integer = 2 * (1 + nc)

Dim hLocal As IntPtr = AllocHLocal(len)

'If hLocal = IntPtr.Zero Then

If hLocal.ToInt32 = 0 Then

Throw New OutOfMemoryException

Else

'interopserv.Marshal.Copy(s.ToString, 0, hLocal, nc)

Return hLocal

End If

End If

End Function 'StringToHLocalUni

End Class 'Marshal

'End Namespace 'NetCF.Runtime.InteropServices

Page 66: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XI

B.4 Book Reading example

Public Class book111

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

System.EventArgs) Handles MyBase.Load

' load book picture

Dim MyImage As New Bitmap("\my documents\book111.jpg")

PictureBox1.Image = CType(MyImage, Image)

End Sub

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

System.EventArgs) Handles MenuItem1.Click

'view first page

book11.Show()

End Sub

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

System.EventArgs) Handles MenuItem2.Click

'view next page

book112.Show()

End Sub

End Class

B.5 Quiz Example Imports System.Windows.forms

Public Class quize1

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

System.EventArgs) Handles MyBase.Load

' show quiz

Dim MyImage As New Bitmap("\my documents\quize1.jpg")

PictureBox1.Image = CType(MyImage, Image)

End Sub

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

System.EventArgs) Handles MenuItem2.Click

‘show next quiz

quize2.Show()

End Sub

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

System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

If (e.KeyCode = System.Windows.Forms.Keys.Enter) Then

If TextBox1.Focused Then

right1.Show()

'MessageBox.Show("binggo", "congradulations!")

'quize2.Show()

ElseIf TextBox2.Focused Then

wrong.Show()

Page 67: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XII

' MessageBox.Show("Wrong!", "Consider Again!")

'quize2.Show()

End If

'Enter

End If

End Sub

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

System.EventArgs) Handles MenuItem1.Click

lifeclinic.Show()

End Sub

End Class

B.6 Insulin Injection Reminder

Setting

Imports System

Imports System.IO

Public Class Form5

Inherits System.Windows.Forms.Form

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem

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

Page 68: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XIII

frmform54.Show()

End Sub

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

System.EventArgs) Handles MenuItem3.Click

Dim file As New System.IO.StreamWriter("my documents\time1.txt")

Dim context As String

context = TextBox1.Text

file.WriteLine(context)

file.Close()

'save time setting 1

End Sub

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

System.EventArgs) Handles MenuItem4.Click

Dim file As New System.IO.StreamWriter("my documents\time2.txt")

Dim context As String

context = TextBox2.Text

file.WriteLine(context)

file.Close()

'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")

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

Dim file3 As New System.IO.StreamReader("my documents\time3.txt")

TextBox1.Text = file1.ReadLine

TextBox2.Text = file2.ReadLine

TextBox3.Text = file3.ReadLine

file1.Close()

file2.Close()

file3.Close()

End Sub

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

System.EventArgs) Handles MenuItem5.Click

Dim file As New System.IO.StreamWriter("my documents\time3.txt")

Dim context As String

context = TextBox3.Text

file.WriteLine(context)

file.Close()

'savetime setting 3

End Sub

End Class

Page 69: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XIV

Show Current Time and Next Shot Time & Show Alarm at the Set Time

Public Class Form4

Inherits System.Windows.Forms.Form

Public Sub GetTime()

msgbox1.Text = Convert.ToString(System.DateTime.Now.TimeOfDay)

End Sub

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

System.EventArgs) Handles MyBase.Load

Timer1.Enabled = True

Timer1.Interval = 1000

End Sub

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

System.EventArgs) Handles Timer1.Tick

GetTime()

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

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

Dim file3 As New System.IO.StreamReader("my documents\time3.txt")

Dim hour As Int16 = System.DateTime.Now.Hour

Dim minute As Int16 = System.DateTime.Now.Minute

Dim context1, context2, context3 As String

Dim result As DialogResult

context1 = file1.ReadLine().Substring(0, 5)

context2 = file2.ReadLine().Substring(0, 5)

context3 = file3.ReadLine().Substring(0, 5)

file1.Close()

file2.Close()

file3.Close()

If result = Windows.Forms.DialogResult.OK Then

Timer1.Enabled = False

End If

If (hour > Convert.ToInt16(context3.Substring(0, 2))) Then

TextBox1.Text = context1

ElseIf hour = Convert.ToInt16(context3.Substring(0, 2)) Then

If minute > context3.Substring(3, 2) Then

TextBox1.Text = context1

ElseIf minute < Convert.ToInt16(context3.Substring(3, 2)) Then

TextBox1.Text = context3

Else : TextBox1.Text = "Inject Now!!!"

Dim mySound As New Sound("becauseimagirl.wav")

mySound.Play()

result = MessageBox.Show("time to inject insulin", "message

from Medical Assistant", MessageBoxButtons.OK, MessageBoxIcon.Exclamation,

MessageBoxDefaultButton.Button1)

If result = Windows.Forms.DialogResult.OK Then

Timer1.Enabled = False

Form1.Show()

End If

Page 70: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XV

End If

ElseIf hour < Convert.ToInt16(context3.Substring(0, 2)) Then

If hour > Convert.ToInt16(context2.Substring(0, 2)) Then

TextBox1.Text = context3

ElseIf hour = Convert.ToInt16(context2.Substring(0, 2)) Then

If minute > Convert.ToInt16(context2.Substring(3, 2)) Then

TextBox1.Text = context3

ElseIf minute < Convert.ToInt16(context2.Substring(3, 2))

Then

TextBox1.Text = context2

Else : TextBox1.Text = "Inject Now!!!"

Dim mySound As New Sound("becauseimagirl.wav")

mySound.Play()

result = MessageBox.Show("time to inject insulin",

"message from Medical Assistant", MessageBoxButtons.OK,

MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

If result = Windows.Forms.DialogResult.OK Then

Timer1.Enabled = False

Form1.Show()

End If

End If

ElseIf hour < Convert.ToInt16(context2.Substring(0, 2)) Then

If hour > Convert.ToInt16(context1.Substring(0, 2)) Then

TextBox1.Text = context2

ElseIf hour = Convert.ToInt16(context1.Substring(0, 2)) Then

If minute > Convert.ToInt16(context1.Substring(3, 2))

Then

TextBox1.Text = context2

ElseIf minute < Convert.ToInt16(context1.Substring(3,

2)) Then

TextBox1.Text = context1

Else : TextBox1.Text = "Inject Now!!!"

Dim mySound As New Sound("becauseimagirl.wav")

mySound.Play()

result = MessageBox.Show("time to inject insulin",

"message from Medical Assistant", MessageBoxButtons.OK,

MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)

If result = Windows.Forms.DialogResult.OK Then

Timer1.Enabled = False

Form1.Show()

End If

End If

ElseIf hour < Convert.ToInt16(context1.Substring(0, 2)) Then

TextBox1.Text = context1

End If

End If

End If

' compare the current time with the 3 set time, get the next time for

insulin shot,

Page 71: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XVI

'when comes the set time, alarm will sound and messagebox will pop

up

End Sub

Public Class Sound

Private m_soundBytes() As Byte

Private m_fileName As String

Public Declare Function WCE_PlaySound Lib "CoreDll.dll" Alias

"PlaySound" (ByVal szSound As String, ByVal hMod As IntPtr, ByVal flags As

Integer) As Integer

Public Declare Function WCE_PlaySoundBytes Lib "CoreDll.dll" Alias

"PlaySound" (ByVal szSound() As Byte, ByVal hMod As IntPtr, ByVal flags As

Integer) As Integer

Private Enum Flags

SND_SYNC = &H0 ' play synchronously (default)

SND_ASYNC = &H1 ' play asynchronously

SND_NODEFAULT = &H2 ' silence (!default) if sound not found

SND_MEMORY = &H4 ' pszSound points to a memory file

SND_LOOP = &H8 ' loop the sound until next sndPlaySound

SND_NOSTOP = &H10 ' don't stop any currently playing sound

SND_NOWAIT = &H2000 ' don't wait if the driver is busy

SND_ALIAS = &H10000 ' name is a registry alias

SND_ALIAS_ID = &H110000 ' alias is a predefined ID

SND_FILENAME = &H20000 ' name is file name

SND_RESOURCE = &H40004 ' name is resource name or atom

End Enum

' Construct the Sound object to play sound data from the specified

file.

Public Sub New(ByVal fileName As String)

m_fileName = fileName

End Sub

' Construct the Sound object to play sound data from the specified

stream.

Public Sub New(ByVal stream As System.IO.Stream)

' read the data from the stream

m_soundBytes = New Byte(stream.Length) {}

stream.Read(m_soundBytes, 0, Fix(stream.Length))

End Sub 'New

' Play the sound

Public Sub Play()

' If a file name has been registered, call WCE_PlaySound,

' otherwise call WCE_PlaySoundBytes.

If Not (m_fileName Is Nothing) Then

Page 72: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XVII

WCE_PlaySound(m_fileName, IntPtr.Zero, Fix(Flags.SND_SYNC

Or Flags.SND_FILENAME))

Else

WCE_PlaySoundBytes(m_soundBytes, IntPtr.Zero,

Fix(Flags.SND_ASYNC Or Flags.SND_MEMORY))

End If

End Sub

End Class

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

System.EventArgs) Handles MenuItem2.Click

Dim frmform45 As New Form5

frmform45.Show()

End Sub

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

System.EventArgs) Handles MenuItem1.Click

Form1.Show()

End Sub

End Class

B.7 Serial Port Setting

Imports System.Runtime.InteropServices

Imports System.IO.Ports

Imports Microsoft.VisualBasic.FileAttribute

Imports system.io

Imports System

Imports System.Xml

Imports System.Xml.Serialization

Imports Microsoft.VisualBasic

Public Class SerialPort

Dim WithEvents Serialport As New IO.Ports.SerialPort

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

System.EventArgs) Handles MyBase.Load

With Serialport

.BaudRate = 9600

.DataBits = 8

.PortName = "COM6"

.Parity = Parity.None

.StopBits = StopBits.One

End With

' set the default serial port parameter

End Sub

Page 73: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XVIII

Public Function stringToByteArray _

(ByVal str As String) As Byte()

Dim s As Char()

s = str.ToCharArray

Dim b(s.Length - 1) As Byte

Dim i As Integer

For i = 0 To s.Length - 1

b(i) = Convert.ToByte(s(i))

Next

Return b

' change string to bytearray

End Function

Public Shared Sub WriteAllText( _

ByVal file As String, _

ByVal text As String, _

ByVal append As Boolean _

)

End Sub

Public Class SerialDataReceivedEventArgs

Inherits EventArgs

End Class

Function OpenPort() As Boolean

With Serialport

Try

.Open() 'calls the routine implemented in IO.ports

Return True

Catch ex As Exception

If .IsOpen = False Then

'if error when opening, message and close port

MsgBox("Port open failed", MsgBoxStyle.Exclamation)

.Close()

End If

End Try

End With

End Function

Function ClosePort() As Boolean

'called to close the port

With Serialport

Dim isOpen As Boolean = .IsOpen

Try

.Close()

Return True

Catch ex As Exception

'if error when closing,show message

If .IsOpen = True Then

MsgBox("Port close failed", MsgBoxStyle.Exclamation)

End If

End Try

End With

End Function

Page 74: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XIX

Public Delegate Sub StringSubPointer(ByVal Buffer As String)

Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As

_

System.IO.Ports.SerialDataReceivedEventArgs) Handles

Serialport.DataReceived

Dim RecString As String = Serialport.ReadExisting

'If Serialport.ReadBufferSize > 0 Then

' Me.Invoke(New EventHandler(AddressOf DisplayData))

'End If

TextRec.BeginInvoke(New StringSubPointer(AddressOf DisplayData),

RecString)

End Sub

Private Sub DisplayData(ByVal Buffer As String)

TextRec.Text += Buffer

End Sub

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

As System.EventArgs) Handles MenuItem_Open.Click

OpenPort()

MenuItem_Open.Enabled = False

MenuItem_Close.Enabled = True

End Sub

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

As System.EventArgs) Handles MenuItem_Close.Click

ClosePort()

MenuItem_Open.Enabled = True

MenuItem_Close.Enabled = False

End Sub

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

System.EventArgs) Handles MenuItem_Command_SN.Click

Dim DMAT As New System.IO.StreamReader("My documents\[email protected]")

Dim Context As String

Context = DMAT.ReadToEnd()

TextSend.Text = "Commands Sending:" + Context

Serialport.Write(Context)

' send command DM@

End Sub

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

System.EventArgs) Handles MenuItem_Command_DT.Click

Dim DMF As New System.IO.StreamReader("My documents\Meter-DMF.txt")

Dim Context As String

Context = DMF.ReadToEnd()

TextSend.Text = "Commands Sending:" + Context

Serialport.Write(Context)

' send command DMF

End Sub

Page 75: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XX

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

System.EventArgs) Handles MenuItem_Command_Records.Click

Dim DMP As New System.IO.StreamReader("My documents\Meter-DMP.txt")

Dim Context As String

Context = DMP.ReadToEnd()

TextSend.Text = "Commands Sending:" + Context

Serialport.Write(Context)

' send command DMP

End Sub

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

System.EventArgs) Handles MenuItem_Command_Units.Click

Dim DMSU As New System.IO.StreamReader("My

documents\Meter-DMSU.txt")

Dim Context As String

Context = DMSU.ReadToEnd()

TextSend.Text = "Commands Sending:" + Context

Serialport.Write(Context)

' send command DMSU

End Sub

Private Sub MenuItem_Ports_Click(ByVal sender As Object, ByVal e As

EventArgs) Handles MenuItem_COM1.Click, MenuItem_COM2.Click,

MenuItem_COM3.Click, MenuItem_COM4.Click, MenuItem_COM5.Click,

MenuItem_COM6.Click, MenuItem_COM7.Click, MenuItem_COM8.Click,

MenuItem_COM9.Click

With Serialport

Select Case MenuItem_Ports.MenuItems.IndexOf(sender)

Case 0

.PortName = "COM1"

Case 1

.PortName = "COM2"

Case 2

.PortName = "COM3"

Case 3

.PortName = "COM4"

Case 4

.PortName = "COM5"

Case 5

.PortName = "COM6"

Case 6

.PortName = "COM7"

Case 7

.PortName = "COM8"

Case 8

.PortName = "COM9"

End Select

End With

'Selecting the COM number

End Sub

Page 76: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXI

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

As System.EventArgs) Handles MenuItem_Exit.Click

ClosePort()

ExampleOrReal.Show()

End Sub

Private Sub MenuItem_Baudrate_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles MenuItem_115200.Click, MenuItem_1200.Click,

MenuItem_19200.Click, MenuItem_2400.Click, MenuItem_38400.Click,

MenuItem_4800.Click, MenuItem_57600.Click, MenuItem_9600.Click

With Serialport

Select Case MenuItem_Baudrate.MenuItems.IndexOf(sender)

Case 0

.BaudRate = 1200

Case 1

.BaudRate = 2400

Case 2

.BaudRate = 4800

Case 3

.BaudRate = 9600

Case 4

.BaudRate = 19200

Case 5

.BaudRate = 38400

Case 6

.BaudRate = 57600

Case 7

.BaudRate = 115200

End Select

End With

' selecting the Baudrate

End Sub

Private Sub MenuItem_databits_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles MenuItem_Databits_7.Click,

MenuItem_Databits_8.Click

With Serialport

Select Case MenuItem_Databits.MenuItems.IndexOf(sender)

Case 0

.DataBits = 7

Case 1

.DataBits = 8

End Select

' selceting the databits

End With

End Sub

Private Sub MenuItem_stopbits_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles MenuItem_Stopbits_1.Click,

MenuItem_Stopbits_15.Click, MenuItem_Stopbits_2.Click

With Serialport

Select Case MenuItem_Stopbits.MenuItems.IndexOf(sender)

Case 0

Page 77: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXII

.StopBits = StopBits.One

Case 1

.StopBits = StopBits.OnePointFive

Case 2

.StopBits = StopBits.Two

End Select

End With

'selecting the stopbits

End Sub

Private Sub MenuItem_Parity_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles MenuItem_Parity_Even.Click,

MenuItem_Parity_Mark.Click, MenuItem_Parity_None.Click,

MenuItem_Parity_Odd.Click, MenuItem_Parity_Space.Click

With Serialport

Select Case MenuItem_Parity.MenuItems.IndexOf(sender)

Case 0

.Parity = Parity.None

Case 1

.Parity = Parity.Odd

Case 2

.Parity = Parity.Even

Case 3

.Parity = Parity.Mark

Case 4

.Parity = Parity.Space

End Select

End With

' selecting the parity

End Sub

Private Sub MenuItem_CLRSend_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles MenuItem_CLRSend.Click

TextSend.Text = ""

'clear send

End Sub

Private Sub MenuItem_CLRREC_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles MenuItem_CLRREC.Click

TextRec.Text = ""

'clear receive

End Sub

Private Sub MenuItem_SaveREC_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles MenuItem_SaveRec_DT.Click,

MenuItem_SaveRec_Records.Click, MenuItem_SaveRec_SN.Click,

MenuItem_SaveRec_Units.Click

Select Case MenuItem_SaveREC.MenuItems.IndexOf(sender)

Case 0

Dim SN As FileStream

Dim bt1() As Byte

'Open the stream and write to it.

Page 78: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXIII

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

bt1 = stringToByteArray(TextRec.Text)

' Add some information

SN.Write(bt1, 0, bt1.Length)

SN.Close()

Case 1

Dim DT As FileStream

Dim bt2() As Byte

DT = File.OpenWrite("my documents\meterdata\DT.txt")

bt2 = stringToByteArray(TextRec.Text)

DT.Write(bt2, 0, bt2.Length)

DT.Close()

Case 2

Dim Records As FileStream

Dim bt3() As Byte

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)

Units.Close()

End Select

End Sub

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

System.EventArgs) Handles MenuItem2.Click

RecordsBar.Show()

End Sub

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

System.EventArgs) Handles MenuItem3.Click

Recordsline.Show()

End Sub

End Class

Page 79: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXIV

B.8.1 Graphic Data Show- Overall Bar Imports System.Drawing.Graphics

Imports System.IO

Public Class OverallBar

Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)

Dim formGraphics As Drawing.Graphics

Dim Max As New Single

Dim Min As New Single

Dim sum As New Single

Dim avg As New Single

Public number As Int64

Dim Records As New System.IO.StreamReader("my

documents\meterdata\BGTest.txt")

Dim i As Int64 = 0

Dim line As String

Dim data(500) As Single

Private Sub getdata(ByVal records As System.IO.StreamReader)

'Dim converter As String

line = records.ReadLine()

line = records.ReadLine()

Do While (line <> "")

data(i) = line.Substring(36, 3) / 18

i = i + 1

number = number + 1

line = records.ReadLine()

Loop

records.Close()

End Sub

Private Sub CalculateGraph(ByVal data() As Single)

'calculate the max, min, average values to represent in the graphic

Max = data(0)

Min = data(0)

sum = 0

For i = 1 To number - 1

If Max < data(i) Then

Max = data(i)

End If

Next

For i = 1 To number - 1

If Min > data(i) Then

Min = data(i)

End If

Next

For i = 0 To number - 1

sum += data(i)

Next

avg = sum / number

End Sub

Page 80: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXV

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As

System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

'called to paint in the picture box the blood suger leverls and the

boundaries

Dim g As Graphics = e.Graphics

Dim RedPen As Pen = New Pen(Color.Red)

Dim myBrush1 As Brush = New SolidBrush(Color.Lime)

Dim mybrush2 As Brush = New SolidBrush(Color.Blue)

Dim mybrush3 As Brush = New SolidBrush(Color.LightGray)

Dim mybrush4 As Brush = New SolidBrush(Color.Red)

Dim mybrush5 As Brush = New SolidBrush(Color.LightCoral)

Dim w As Integer = PictureBox1.Width

Dim h As Single = PictureBox1.Height

Call getdata(Records)

Call CalculateGraph(data)

Dim Width As Integer = (w - 20) / number

Dim Height As Integer = h / 15

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)

If data(m) > 10 Then

g.FillRectangle(mybrush4, ret(m))

ElseIf data(m) > avg Then

g.FillRectangle(mybrush2, ret(m))

ElseIf data(m) > 5 Then

g.FillRectangle(myBrush1, ret(m))

Else : g.FillRectangle(mybrush5, ret(m))

End If

Next

End Sub

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

System.EventArgs) Handles MenuItem1.Click

example.Show()

End Sub

End Class

Page 81: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXVI

B.8.2 Graphical Data Show- Datalist

Imports System.IO

Public Class DataList

Public bfbf As Int16

Public afbf As Int16

Public bfluc As Int16

Public afluc As Int16

Public bfdin As Int16

Public afdin As Int16

Public line(500) As String

Public TestDate(500) As String

Public Time(500) As String

Public Slot(500) As String

Public Slotdata(500) As Int16

Public Value(500) As Single

Public number As Int64 = 0

Public m As Integer = 0

Public Sub getdata()

Dim setup As New System.IO.StreamReader("my

documents\meterdata\setup.txt")

bfbf = Convert.ToInt16(setup.ReadLine().Substring(0, 2))

afbf = Convert.ToInt16(setup.ReadLine().Substring(0, 2))

bfluc = Convert.ToInt16(setup.ReadLine().Substring(0, 2))

afluc = Convert.ToInt16(setup.ReadLine().Substring(0, 2))

bfdin = Convert.ToInt16(setup.ReadLine().Substring(0, 2))

afdin = Convert.ToInt16(setup.ReadLine().Substring(0, 2))

setup.Close()

' read the time slot

End Sub

Public Sub getrecord5()

Dim i As Int64 = 0

Dim record As New System.IO.StreamReader("my

documents\meterdata\BGTest.txt")

'read the Serial Number Information

record.ReadLine()

line(i) = record.ReadLine()

Do While (line(i) <> "")

TestDate(i) = line(i).Substring(3, 3)

Time(i) = line(i).Substring(9, 8)

Slotdata(i) = Convert.ToInt16(line(i).Substring(20, 2))

Value(i) = line(i).Substring(36, 3) / 18

i = i + 1

number = number + 1

line(i) = record.ReadLine()

Loop

record.Close()

End Sub

Public Sub DealWithSchedule()

Dim s As Int64

getdata()

getrecord5()

Page 82: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXVII

For s = 0 To number - 1

'determine the time slot

If ((bfbf < Slotdata(s) And Slotdata(s) < afbf) Or Slotdata(s)

= bfbf) Then

Slot(s) = "Before Breakfast"

ElseIf ((afbf < Slotdata(s) And Slotdata(s) < bfluc) Or Slotdata(s)

= afbf) Then

Slot(s) = "After Breakfast"

ElseIf ((bfluc < Slotdata(s) And Slotdata(s) < afluc) Or

Slotdata(s) = bfluc) Then

Slot(s) = "Before Lunch"

ElseIf ((afluc < Slotdata(s) And Slotdata(s) < bfdin) Or

Slotdata(s) = afluc) Then

Slot(s) = "After Lunch"

ElseIf ((bfdin < Slotdata(s) And Slotdata(s) < afdin) Or

Slotdata(s) = bfdin) Then

Slot(s) = "Before Dinner"

ElseIf (Slotdata(s) = afdin Or Slotdata(s) > afdin Or Slotdata(s)

< bfbf) Then

Slot(s) = "After Dinner"

End If

Next

End Sub

Public Sub ShowRecords5(ByVal x As Integer)

DealWithSchedule()

Me.TextBox1.Text = TestDate(x * 5)

Me.TextBox5.Text = TestDate(x * 5 + 1)

Me.TextBox9.Text = TestDate(x * 5 + 2)

Me.TextBox13.Text = TestDate(x * 5 + 3)

Me.TextBox17.Text = TestDate(x * 5 + 4)

Me.TextBox2.Text = Time(x * 5)

Me.TextBox6.Text = Time(x * 5 + 1)

Me.TextBox10.Text = Time(x * 5 + 2)

Me.TextBox14.Text = Time(x * 5 + 3)

Me.TextBox18.Text = Time(x * 5 + 4)

Me.TextBox4.Text = Value(x * 5)

Me.TextBox8.Text = Value(x * 5 + 1)

Me.TextBox12.Text = Value(x * 5 + 2)

Me.TextBox16.Text = Value(x * 5 + 3)

Me.TextBox20.Text = Value(x * 5 + 4)

Me.TextBox3.Text = Slot(x * 5)

Me.TextBox7.Text = Slot(x * 5 + 1)

Me.TextBox11.Text = Slot(x * 5 + 2)

Me.TextBox15.Text = Slot(x * 5 + 3)

Me.TextBox19.Text = Slot(x * 5 + 4)

' show the data on that page

End Sub

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

System.EventArgs) Handles MyBase.Load

ShowRecords5(m)

End Sub

Page 83: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXVIII

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

System.EventArgs) Handles MenuItem2.Click

'only show the existed records in limited pages

If (TextBox4.Text = "0" Or TextBox8.Text = "0" Or TextBox12.Text =

"0" Or TextBox16.Text = "0" Or TextBox20.Text = "0") Then

MenuItem2.Enabled = False

Else

m = m + 1

ShowRecords5(m)

End If

End Sub

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

System.EventArgs) Handles MenuItem1.Click

example.Show()

End Sub

End Class

Set the Time Slot

Imports System.IO

Public Class patient_setup

Public bfbf As String

Public afbf As String

Public bfluc As String

Public afluc As String

Public bfdin As String

Public afdin As String

Public Sub getdata()

Dim setup As New System.IO.StreamReader("my

documents\meterdata\setup.txt")

bfbf = setup.ReadLine()

afbf = setup.ReadLine()

bfluc = setup.ReadLine()

afluc = setup.ReadLine()

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)

Page 84: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXIX

setup.WriteLine(Me.TextBox3.Text)

setup.WriteLine(Me.TextBox4.Text)

setup.WriteLine(Me.TextBox5.Text)

setup.WriteLine(Me.TextBox6.Text)

setup.Close()

' reset the data

End Sub

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

System.EventArgs) Handles MyBase.Load

getdata()

Me.TextBox1.Text = bfbf

Me.TextBox2.Text = afbf

Me.TextBox3.Text = bfluc

Me.TextBox4.Text = afluc

Me.TextBox5.Text = bfdin

Me.TextBox6.Text = afdin

Me.Label1.Text = afbf

Me.Label11.Text = bfluc

Me.Label12.Text = afluc

Me.Label13.Text = bfdin

Me.Label14.Text = afdin

Me.Label15.Text = bfbf

End Sub

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

System.EventArgs) Handles MenuItem1.Click

example.Show()

End Sub

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

System.EventArgs) Handles MenuItem2.Click

savedata()

getdata()

Me.TextBox1.Text = bfbf

Me.TextBox2.Text = afbf

Me.TextBox3.Text = bfluc

Me.TextBox4.Text = afluc

Me.TextBox5.Text = bfdin

Me.TextBox6.Text = afdin

Me.Label1.Text = afbf

Me.Label11.Text = bfluc

Me.Label12.Text = afluc

Me.Label13.Text = bfdin

Me.Label14.Text = afdin

Me.Label15.Text = bfbf

End Sub

End Class

Page 85: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXX

B.8.3 Graphical Data Show-Trend

Public Class Recordsline

Dim line As String

Dim Max As New Single

Dim Min As New Single

Dim sum As New Single

Dim avg As New Single

Public number As Int64

Dim Records As New System.IO.StreamReader("my

documents\meterdata\records.txt")

Dim i As Int64 = 0

Dim data(500) As Single

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 glucose data and change mg/dl to mmol/l

i = i + 1

number = number + 1

line = records.ReadLine()

Loop

records.Close()

End Sub

Public Sub DrawLinePoint(ByVal sender As Object, ByVal e As

System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

' Draw line to screen.

Dim g As Graphics = e.Graphics

'creat pen

Dim bluePen As Pen = New Pen(Color.Blue)

Dim RedPen As Pen = New Pen(Color.Red)

Dim brushgray As New SolidBrush(Color.LightGray)

Dim w As Integer = PictureBox1.Width

Dim h As Integer = PictureBox1.Height

Call getdata(Records)

Dim Width As Integer = (w - 10) / number

Dim Height As Single = h / 15

Dim m As Int64

Dim x(500) As Single

Dim y(500) As Single

For m = 0 To number - 1

x(m) = PictureBox1.Left + Width * m

y(m) = PictureBox1.Height - Height * data(m)

Next

Dim ret As New Rectangle(0, PictureBox1.Height - Height * 10,

PictureBox1.Width, 5 * Height)

g.FillRectangle(brushgray, ret)

For m = 0 To number - 2

e.Graphics.DrawLine(bluePen, x(m), y(m), x(m + 1), y(m + 1))

' draw the lines between each points

e.Graphics.DrawEllipse(RedPen, x(m), y(m), 5, 5)

Page 86: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXXI

' draw the data point

Next

e.Graphics.DrawEllipse(RedPen, x(number - 1), y(number - 1), 5, 5)

End Sub

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

System.EventArgs) Handles MenuItem1.Click

SerialPort.Show()

End Sub

End Class

B.8.4 Graphical Data Show- Standard Day

Public Class StandardDay

Dim line As String

Dim Max As New Single

Dim Min As New Single

Dim sum As New Single

Dim avg As New Single

Public number As Int64

Dim Records As New System.IO.StreamReader("my

documents\meterdata\BGTest.txt")

Dim i As Int64 = 0

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

Page 87: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXXII

number = number + 1

line = records.ReadLine()

Loop

records.Close()

End Sub

Public Sub DrawLinePoint(ByVal sender As Object, ByVal e As

System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

' Draw line to screen.

Dim g As Graphics = e.Graphics

'creat pen

Dim bluePen As Pen = New Pen(Color.Blue)

Dim RedPen As Pen = New Pen(Color.Red)

Dim graybrush As Brush = New SolidBrush(Color.LightGray)

Dim w As Integer = PictureBox1.Width

Dim h As Integer = PictureBox1.Height

Call getdata(Records)

Dim Width As Integer = (w - 10) / number

Dim Height As Integer = h / 15

Dim m As Int64

Dim x(500) As Single

Dim y(500) As Single

Dim ret As New Rectangle(0, PictureBox1.Bottom - Height * 10,

PictureBox1.Width, 5 * Height)

g.FillRectangle(graybrush, ret)

For m = 0 To number - 1

If hour(m) > 6 Or hour(m) = 6 Then

x(m) = ((hour(m) - 6) * PictureBox1.Width / 24) + (mint(m)

* PictureBox1.Width / (24 * 60))

' set the value of x-cordinator by the time

Else : x(m) = ((hour(m) - 6) * PictureBox1.Width / 24) + (mint(m)

* PictureBox1.Width / (24 * 60))

End If

y(m) = PictureBox1.Bottom - Height * data(m)

' set the value of y-cordinator by the test data

Next

For m = 0 To number - 1

e.Graphics.DrawEllipse(RedPen, x(m), y(m), 2, 2)

Next

End Sub

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

System.EventArgs) Handles MenuItem1.Click

example.Show()

End Sub

End Class

Page 88: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXXIII

B.9.1 Smart Data Analysis – Insuline Dose Suggestion Imports System.IO.file

Imports System.IO

Public Class Suggestion

Public food As String

Public Ex As String

Dim food1 As String = "Not Enough Food "

Dim food2 As String = "Adequate Food"

Dim food3 As String = "Too Much Food"

Dim data As System.DateTime = System.DateTime.Today

Dim Ex1 As String = "No Exercise"

Dim Ex2 As String = "Mild Exercise"

Dim Ex3 As String = "Hard Exercise"

Dim i1 As Single = 1

Dim i2 As Single = 1

Dim i3 As Single = 1

Dim i As Single

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

System.EventArgs) Handles MenuItem3.Click

If CheckBox1.CheckState Then

food = food1

End If

If CheckBox2.CheckState Then

food = food2

End If

If CheckBox3.CheckState Then

food = food3

End If

If CheckBox4.CheckState Then

Ex = Ex1

End If

If CheckBox5.CheckState Then

Ex = Ex2

End If

If CheckBox6.CheckState Then

Ex = Ex3

End If

Dim path As String = "my documents\logbook.txt"

Dim sw As system.IO.StreamWriter

'append the context

sw = File.AppendText(path)

sw.WriteLine(DateTime.Today.Date + " " + food + " " + Ex)

sw.Flush()

sw.Close()

End Sub

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

System.EventArgs) Handles MenuItem4.Click

Page 89: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXXIV

Dim record As New System.IO.StreamReader("my

documents\meterdata\BGTest.txt")

Dim BGdate As String

Dim value As Single

'read the Serial Number Information

record.ReadLine()

Dim line As String = record.ReadLine()

Dim data As String = (Convert.ToString(DateTime.Today.Date))

BGdate = line.Substring(9, 8)

If (data.Substring(0, 2) = BGdate.Substring(3, 2) And

data.Substring(3, 2) = BGdate.Substring(0, 2) And data.Substring(8, 2) =

BGdate.Substring(6, 2)) Then

value = line.Substring(36, 3) / 18

If value > 10 Then i3 = 2

If value < 5 Then i3 = 0.5

Else : MessageBox.Show("No Blood Glucose Record Today", "No BG Test

Today?", MessageBoxButtons.OK, MessageBoxIcon.Exclamation,

MessageBoxDefaultButton.Button1)

' if no blood glucose tested today, then messagebox shows

End If

record.Close()

If CheckBox1.CheckState Then

i1 = 0.5

End If

If CheckBox3.CheckState Then

i1 = 2

End If

If CheckBox4.CheckState Then

i2 = 2

End If

If CheckBox6.CheckState Then

i2 = 0.5

End If

i = i1 * i2 * i3

If i > 1 Then

TextBox1.Text = "Suggestion:You need a little more insulin today"

ElseIf i < 1 Then

TextBox1.Text = "Suggestion: You need a little less insulin today"

Else : TextBox1.Text = "You are perfect in control today!"

End If

' combine the information of daily food consumption, activity and

glucose level to adjust the insuline dose

End Sub

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

System.EventArgs) Handles MenuItem1.Click

lifeclinic.Show()

End Sub

End Class

Page 90: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXXV

B.9.2 Smart Data Analysis – Data Analyzer Imports System.Drawing.Graphics

Imports System.IO

Public Class Analyzer

Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)

Dim formGraphics As Drawing.Graphics

Dim Max As New Single

Dim Min As New Single

Dim sum As New Single

Dim avg As New Single

Public number As Int64

Dim Records As New System.IO.StreamReader("my

documents\meterdata\BGTest.txt")

Dim i As Int64 = 0

Dim line As String

Dim data(500) As Single

Dim controlNo As Int64

Dim Percentage As New Single

Private Sub getdata(ByVal records As System.IO.StreamReader)

'Dim converter As String

line = records.ReadLine()

line = records.ReadLine()

Do While (line <> "")

data(i) = line.Substring(36, 3) / 18

i = i + 1

number = number + 1

line = records.ReadLine()

Loop

records.Close()

End Sub

Private Sub Calculate(ByVal data() As Single)

'calculate the max, min, average values to represent in the graphic

Max = data(0)

Min = data(0)

sum = 0

For i = 1 To number - 1

If Max < data(i) Then

Max = data(i)

End If

Next

For i = 1 To number - 1

If Min > data(i) Then

Min = data(i)

End If

Next

Page 91: Final Report Xiaojia Jiang

Smartphone for Children with Diabetes University of Birmingham Xiaojia Jiang

XXXVI

For i = 0 To number - 1

sum += data(i)

Next

avg = sum / number

For i = 0 To number - 1

If (5 < data(i) Or 5 = data(i)) And (data(i) < 10 Or data(i) =

10) Then

controlNo = controlNo + 1

End If

Next

Percentage = (controlNo / number) * 100%

End Sub

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"

ElseIf (Percentage > 0.95 Or Percentage = 0.95) Then

TextBox7.Text = "Good in Control"

Else : TextBox7.Text = "More Attention"

End If

End Sub

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

System.EventArgs) Handles MenuItem1.Click

example.Show()

End Sub

End Class