Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for variable number of cylinders #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ $RECYCLE.BIN/
Network Trash Folder
Temporary Items
.apdisk
*.bak
storage.ide*
db.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A Windows XAML application that communicates to a TbsShield Arduino.

##Description
This application will communicate to a TbsShield equiped Arduino. It will expose actions and graph the realtime results.
See the Tbs4Rpm for a Arduino sketch that this project will communicate with.
See the [Tbs4Rpm](https://github.com/deHarro/Tbs4Rpm) for a Arduino sketch that this project will communicate with.

##Install
To install, clone this into your Vs projects folder, which will place it in a folder named Tbs4Rpm. VS is not picky where you actually clone this project to on your computer and you may clone this into any folder you want.
21 changes: 15 additions & 6 deletions Tbs4Rpm/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<Window x:Class="Tbs4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TBS 4" Height="410" Width="525">
Title="TBS 2" Height="410" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
<RowDefinition Height="23"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<Grid.ColumnDefinitions> <!-- Anzahl Spalten -->
<ColumnDefinition Width="*"/> <!-- Spalte 1 -->
<ColumnDefinition Width="*"/> <!-- Spalte 2 -->
<!-- if(numberOfCylinders > 2) --> <!-- this would make the display adapt to the number of cylinders committed by the Arduino app - ->
<ColumnDefinition Width="*"/> <!- - Spalte 3 - ->
<!- - if(numberOfCylinders > 3) - -> <!- - this would make the display adapt to the number of cylinders committed by the Arduino app - ->
<ColumnDefinition Width="*"/> <!- - Spalte 4 - ->
-->
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
Expand Down Expand Up @@ -105,6 +108,8 @@
</StackPanel>
<Label Name="tbs2RpmLabel" Content="1000 rpm" HorizontalAlignment="Right" VerticalAlignment="Center" FontFamily="Lucida Console" FontSize="10" Grid.Row="2" Margin="2,2" />
</Grid>
<!-- if(numberOfCylinders > 2) --> <!-- this would make the display adapt to the number of cylinders committed by the Arduino app -->
<!--
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
Expand Down Expand Up @@ -151,6 +156,9 @@
</StackPanel>
<Label Name="tbs3RpmLabel" Content="1000 rpm" HorizontalAlignment="Right" VerticalAlignment="Center" FontFamily="Lucida Console" FontSize="10" Grid.Row="2" Margin="2,2" />
</Grid>
-->
<!-- if(numberOfCylinders > 3) --> <!-- this would make the display adapt to the number of cylinders committed by the Arduino app -->
<!--
<Grid Grid.Column="3">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
Expand Down Expand Up @@ -196,6 +204,7 @@
</StackPanel>
<Label Name="tbs4RpmLabel" Content="1000 rpm" HorizontalAlignment="Right" VerticalAlignment="Center" FontFamily="Lucida Console" FontSize="10" Grid.Row="2" Margin="2,2" />
</Grid>
-->
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
Expand Down
54 changes: 27 additions & 27 deletions Tbs4Rpm/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,36 +229,35 @@ private string FindPortName(List<string> portsSkip)
{
string[] ports = SerialPort.GetPortNames();

// find the first port skipping any with single digit
// or in the portsSkip list
// find the first port skipping any in the portsSkip list
for (int indexPort = 0; indexPort < ports.GetLength(0); indexPort++)
{
string portName = ports[indexPort];
if (portName.Length > 4) // skip COM5
{
if (!portsSkip.Contains(portName))
{
return portName;
}
}
}

return null;
}

private bool ConnectPort(string portName)
{
bool found = false;
comms = new SerialPort(portName, 19200, Parity.None);
//comms = new SerialPort(portName, 19200, Parity.None);
comms = new SerialPort(portName, 19200, Parity.None, 8, (StopBits) 1);
comms.NewLine = "\r\n";
comms.RtsEnable = true;
comms.DtrEnable = true;
comms.RtsEnable = false; // true;
comms.DtrEnable = false; // true;
comms.ErrorReceived += comms_ErrorReceived;
comms.ReadTimeout = 2000; // large for initial setup
try
{
for(int x=0; ((x<5) && (found == false)); x++) // 5-mal versuchen, den Arduino zu kontaktieren, Harry
{
comms.Open();
Thread.Sleep(1000);
Thread.Sleep(200); // 200 ms sind genug (in Verbindung mit 5 Versuchen), Harry
comms.WriteLine("query version");
string message = comms.ReadLine();
if (message.StartsWith( "<version="))
Expand All @@ -273,6 +272,7 @@ private bool ConnectPort(string portName)
}
}
}
}
catch (Exception e)
{
comms.Close();
Expand Down Expand Up @@ -639,26 +639,26 @@ private void ProcessSample(SampleSet sample)
tbs2MinMax);
break;
case 2:
UpdateGraphBar(sample.Channels[indexChannel],
sample.Channels[indexChannel],
tbs3Label,
tbs3DeltaLabel,
tbs3RpmLabel,
tbs3,
tbs3Average,
tbs3Reading,
tbs3MinMax);
//UpdateGraphBar(sample.Channels[indexChannel],
//sample.Channels[indexChannel],
//tbs3Label,
//tbs3DeltaLabel,
//tbs3RpmLabel,
//tbs3,
//tbs3Average,
//tbs3Reading,
//tbs3MinMax);
break;
case 3:
UpdateGraphBar(sample.Channels[indexChannel],
sample.Channels[indexChannel],
tbs4Label,
tbs4DeltaLabel,
tbs4RpmLabel,
tbs4,
tbs4Average,
tbs4Reading,
tbs4MinMax);
//UpdateGraphBar(sample.Channels[indexChannel],
//sample.Channels[indexChannel],
//tbs4Label,
//tbs4DeltaLabel,
//tbs4RpmLabel,
//tbs4,
//tbs4Average,
//tbs4Reading,
//tbs4MinMax);
break;
}
}
Expand Down