Skip to content

Commit 7c32f7b

Browse files
committed
Updates to ECG console examples.
- Added feedback/comments. - Write default/recommended settings; gain register bits are not overwritten -> bug?
1 parent dc20248 commit 7c32f7b

File tree

1 file changed

+53
-7
lines changed
  • ShimmerECGConsoleAppExample/ShimmerConsoleAppExample

1 file changed

+53
-7
lines changed

ShimmerECGConsoleAppExample/ShimmerConsoleAppExample/Program.cs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void start()
3535
byte[] defaultECGReg1 = ShimmerBluetooth.SHIMMER3_DEFAULT_ECG_REG1; //also see ShimmerBluetooth.SHIMMER3_DEFAULT_TEST_REG1 && ShimmerBluetooth.SHIMMER3_DEFAULT_EMG_REG1
3636
byte[] defaultECGReg2 = ShimmerBluetooth.SHIMMER3_DEFAULT_ECG_REG2; //also see ShimmerBluetooth.SHIMMER3_DEFAULT_TEST_REG2 && ShimmerBluetooth.SHIMMER3_DEFAULT_EMG_REG2
3737
//The constructor below allows the user to specify the shimmer configurations which is set upon connection to the device
38-
shimmer = new ShimmerLogAndStreamSystemSerialPort("ShimmerID1", "COM29", samplingRate, 0, 4, enabledSensors, false, false, false, 0, 0, defaultECGReg1, defaultECGReg2, false);
38+
shimmer = new ShimmerLogAndStreamSystemSerialPort("ShimmerID1", "COM169", samplingRate, 0, 4, enabledSensors, false, false, false, 0, 0, defaultECGReg1, defaultECGReg2, false);
3939
shimmer.UICallback += this.HandleEvent;
4040
shimmer.Connect();
4141
if (shimmer.GetState() == ShimmerBluetooth.SHIMMER_STATE_CONNECTED)
@@ -51,10 +51,14 @@ public void start()
5151
{
5252
System.Console.Write(shimmer.GetEXG2RegisterContents()[i] + " ");
5353
}
54-
System.Console.WriteLine();
55-
//Note that it is better to set the exgrate via writesamplingrate, a value of 2 is 500 SPS, it should actually be 3 1000 SPS for a sampling rate of 512Hz
56-
shimmer.WriteEXGRate(2);
57-
shimmer.WriteEXGGain(1);
54+
System.Console.WriteLine("\n");
55+
56+
//Note the data rate of the EXG chips (exgrate) is automatically set via writesamplingrate(). For a sampling rate of 512Hz, the exgrate is set to 0x03, which corresponds to 1000 SPS.
57+
//The exgrate can be set to a different settting afterwards, e.g. to 2000 SPS:
58+
shimmer.WriteEXGRate(4);
59+
60+
//The gain of the EXG chips is also configurable. The default gain = 4 (0x04). Now the gain is set to 0x05, which corresponds to a gain of 8:
61+
shimmer.WriteEXGGain(5);
5862

5963
shimmer.ReadEXGConfigurations(1);
6064
shimmer.ReadEXGConfigurations(2);
@@ -68,12 +72,54 @@ public void start()
6872
{
6973
System.Console.Write(shimmer.GetEXG2RegisterContents()[i] + " ");
7074
}
71-
System.Console.WriteLine();
75+
System.Console.WriteLine("\n");
7276

73-
//EXAMPLE TO CHANGE ECG RESOLUTION
77+
//Example code for changing the ecg resolution from 24bit to 16bit - to limit the amount of data transmitted over the Bluetooth link
7478
enabledSensors = ((int)ShimmerBluetooth.SensorBitmapShimmer3.SENSOR_EXG1_16BIT | (int)ShimmerBluetooth.SensorBitmapShimmer3.SENSOR_EXG2_16BIT); // this is to enable the two EXG Chips on the Shimmer3 at 16 bit resolution
7579
shimmer.WriteSensors(enabledSensors);
7680

81+
//Example code for changing the ecg resolution back to 24bit - recommended
82+
enabledSensors = ((int)ShimmerBluetooth.SensorBitmapShimmer3.SENSOR_EXG1_24BIT | (int)ShimmerBluetooth.SensorBitmapShimmer3.SENSOR_EXG2_24BIT); // this is to enable the two EXG Chips on the Shimmer3 at 24 bit resolution
83+
shimmer.WriteSensors(enabledSensors);
84+
85+
//Example code for setting the default ecg settings again (exggain = 4, exgrate >= sampling rate)
86+
//First write the default register settings for both EXG chips
87+
shimmer.WriteEXGConfigurations(defaultECGReg1, defaultECGReg2);
88+
shimmer.ReadEXGConfigurations(1);
89+
shimmer.ReadEXGConfigurations(2);
90+
System.Console.WriteLine("SET DEFAULT ECG CONFIGURATIONS AGAIN");
91+
System.Console.WriteLine("EXG CHIP 1 CONFIGURATION");
92+
for (int i = 0; i < 10; i++)
93+
{
94+
System.Console.Write(shimmer.GetEXG1RegisterContents()[i] + " ");
95+
}
96+
System.Console.WriteLine("\nEXG CHIP 2 CONFIGURATION");
97+
for (int i = 0; i < 10; i++)
98+
{
99+
System.Console.Write(shimmer.GetEXG2RegisterContents()[i] + " ");
100+
}
101+
System.Console.WriteLine("\n");
102+
//Second write the exgrate via writesamplingrate() this time
103+
shimmer.WriteSamplingRate(512);
104+
shimmer.ReadEXGConfigurations(1);
105+
shimmer.ReadEXGConfigurations(2);
106+
System.Console.WriteLine("SET ECG DATA RATE AUTOMATICALLY BY CHANGING THE SAMPLING RATE OF THE SHIMMER");
107+
System.Console.WriteLine("EXG CHIP 1 CONFIGURATION");
108+
for (int i = 0; i < 10; i++)
109+
{
110+
System.Console.Write(shimmer.GetEXG1RegisterContents()[i] + " ");
111+
}
112+
System.Console.WriteLine("\nEXG CHIP 2 CONFIGURATION");
113+
for (int i = 0; i < 10; i++)
114+
{
115+
System.Console.Write(shimmer.GetEXG2RegisterContents()[i] + " ");
116+
}
117+
System.Console.WriteLine("\n");
118+
119+
System.Console.WriteLine("IN ABOUT 5 SECONDS STREAMING WILL START AFTER THE BEEP");
120+
Thread.Sleep(5000);
121+
System.Console.Beep();
122+
77123
shimmer.StartStreaming();
78124
}
79125
}

0 commit comments

Comments
 (0)