Skip to content

設定画面表示とある程度のBIDS互換 #3

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

Merged
merged 97 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
a921e26
add serial.cs
stop-pattern Dec 23, 2024
c7deeac
update serial
stop-pattern Dec 24, 2024
5b6872c
update serial
stop-pattern Dec 24, 2024
865f333
update serial
stop-pattern Dec 24, 2024
d67a7dc
add setting window
stop-pattern Dec 25, 2024
e23bd09
add chatgptに書かせたやつ
stop-pattern Dec 26, 2024
453696e
update window
stop-pattern Dec 27, 2024
2c7f30d
update port control
stop-pattern Dec 27, 2024
0bebb85
fix forget return
stop-pattern Dec 28, 2024
72ba8d7
update ISerialControl
stop-pattern Jan 1, 2025
b504762
update port conotrol
stop-pattern Jan 1, 2025
2367324
split interface
stop-pattern Jan 1, 2025
159a7d0
update 謎の変更
stop-pattern Jan 1, 2025
793d0cd
move serial.cs
stop-pattern Jan 1, 2025
10540ba
change namespace
stop-pattern Jan 1, 2025
8f1fbd3
update project
stop-pattern Jan 1, 2025
d1e6cef
update using
stop-pattern Jan 1, 2025
8174432
update main
stop-pattern Jan 1, 2025
bd8dcff
update window behavior
stop-pattern Jan 1, 2025
bb7d516
add comment
stop-pattern Jan 1, 2025
92f6e50
update main
stop-pattern Jan 1, 2025
13de502
clean main
stop-pattern Jan 1, 2025
db9d891
update component name
stop-pattern Jan 1, 2025
ce72ff2
update xaml xaml.cs
stop-pattern Jan 1, 2025
caf7a31
update var name
stop-pattern Jan 1, 2025
e480d41
update serial control
stop-pattern Jan 1, 2025
8536d40
move code
stop-pattern Jan 3, 2025
9575afc
add native
stop-pattern Jan 3, 2025
bcf073e
update native
stop-pattern Jan 3, 2025
87e1d34
add view model
stop-pattern Jan 4, 2025
5894890
add DTR checkbox
stop-pattern Jan 4, 2025
a383aae
move control
stop-pattern Jan 4, 2025
559578d
add binding
stop-pattern Jan 7, 2025
92fa225
update viewmodel
stop-pattern Jan 7, 2025
ad55e05
update serial control
stop-pattern Jan 8, 2025
6a0f878
fix fogotten change
stop-pattern Jan 11, 2025
750e516
add prop change notify
stop-pattern Jan 11, 2025
045cd87
change dir
stop-pattern Jan 11, 2025
63f17a5
change namespace
stop-pattern Jan 12, 2025
eaef85c
move main
stop-pattern Jan 12, 2025
64a9832
add autoconnect
stop-pattern Jan 12, 2025
992037f
delete resource dict
stop-pattern Jan 12, 2025
dcc8eaf
add save settings
stop-pattern Jan 12, 2025
07a11e3
update save settings
stop-pattern Jan 12, 2025
3e51479
update save settings
stop-pattern Jan 12, 2025
d8c6f83
add sample settings
stop-pattern Jan 12, 2025
51cd93e
update main
stop-pattern Jan 12, 2025
9674b16
add debug
stop-pattern Jan 12, 2025
84097dd
add lib
stop-pattern Jan 12, 2025
d61f7ae
clean bids serial
stop-pattern Jan 12, 2025
1a46a64
add status check
stop-pattern Jan 12, 2025
3b71b49
update bids
stop-pattern Jan 12, 2025
f74f8fd
update start check
stop-pattern Jan 12, 2025
cb5764a
update get instance
stop-pattern Jan 12, 2025
1e194ec
clean main code
stop-pattern Jan 12, 2025
09ce0f5
change class name
stop-pattern Jan 12, 2025
a3eb8c0
change serial control
stop-pattern Jan 12, 2025
3477b5c
add init method
stop-pattern Jan 12, 2025
6d5bd69
add error catch
stop-pattern Jan 12, 2025
4cb56f8
update status management
stop-pattern Jan 12, 2025
cb29348
add auto connect
stop-pattern Jan 12, 2025
8d5ec9c
clean code
stop-pattern Jan 12, 2025
ec149a4
fix autoconnect
stop-pattern Jan 13, 2025
3d702a5
update prop load
stop-pattern Jan 14, 2025
efb070a
update newline
stop-pattern Jan 14, 2025
51daa29
fix namespace
stop-pattern Jan 14, 2025
09c7f8c
update sindow size
stop-pattern Jan 14, 2025
a0cfbf0
update window format
stop-pattern Jan 14, 2025
c4e55e8
add on-design DataContext setting
stop-pattern Jan 20, 2025
54abe0d
add list view
stop-pattern Jan 20, 2025
ff0af26
update setting window
stop-pattern Jan 20, 2025
9a0e6c6
change main window
stop-pattern Jan 20, 2025
ed02a34
update button status
stop-pattern Jan 21, 2025
f5fe6b2
clean code
stop-pattern Jan 21, 2025
ece5031
fix code
stop-pattern Jan 21, 2025
e504074
fix command binding
stop-pattern Jan 21, 2025
d17ebcd
add message display
stop-pattern Jan 21, 2025
8d91016
clean files
stop-pattern Jan 21, 2025
b17533a
add static / clean
stop-pattern Jan 21, 2025
6112f2d
update view
stop-pattern Jan 24, 2025
9037749
update save settings
stop-pattern Jan 25, 2025
a5e71a2
update save config
stop-pattern Jan 25, 2025
bd05947
fix auto connect
stop-pattern Jan 25, 2025
d4dac71
fix error message
stop-pattern Jan 25, 2025
831818e
fix default constructor
stop-pattern Jan 25, 2025
13f618c
delete asm ref
stop-pattern Jan 25, 2025
04da371
update project
stop-pattern Jan 25, 2025
888df6f
add controller enum
stop-pattern Jan 25, 2025
3236c25
fix converter
stop-pattern Jan 25, 2025
1cdc9dd
update serial controller
stop-pattern Jan 26, 2025
2cb1b79
update enum converter
stop-pattern Jan 26, 2025
6d3ed7f
fix error code
stop-pattern Jan 26, 2025
90110d6
update comment
stop-pattern Jan 26, 2025
21656da
update sample setting
stop-pattern Jan 26, 2025
1d7524a
add controller
stop-pattern Jan 26, 2025
d3e5a49
add setting element
stop-pattern Jan 26, 2025
2e9873d
update default value
stop-pattern Jan 26, 2025
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
8 changes: 8 additions & 0 deletions CommEx/CommEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Deterministic>false</Deterministic>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,4 +19,11 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
</Project>
439 changes: 439 additions & 0 deletions CommEx/Serial/Bids/Serial.cs

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions CommEx/Serial/Common/BoolToColorConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace CommEx.Serial.Common
{
/// <summary>
/// bool 型を Color に変換するコンバータ
/// </summary>
public class BoolToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool isOpen)
{
return isOpen ? Brushes.Green : Brushes.Red;
}

return Brushes.Gray; // デフォルト色
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Brush brush)
{
if (brush == Brushes.Green)
{
return true;
}
else if (brush == Brushes.Red)
{
return false;
}
else if (brush == Brushes.Gray)
{
return false;
}
}

throw new InvalidOperationException("Unsupported conversion");
}
}
}
124 changes: 124 additions & 0 deletions CommEx/Serial/Common/EnumConverters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CommEx.Serial.Common
{
#region StringConverter

/// <inheritdoc/>
/// <summary>
/// Enum の Value と String を変換するコンバータ
/// String はそのまま Enum の Value として扱われる
/// </summary>
public class EnumToStringConverter : EnumConverter
{
public EnumToStringConverter(Type type) : base(type)
{
if (!type.IsEnum)
{
throw new ArgumentException("Type must be an Enum.");
}
}
/// <summary>
/// Enum の Value から String を取得
/// Enum.Value -> string
/// </summary>
/// <param name="value">Enum.value</param>
/// <param name="destinationType">string</param>
/// <returns>string</returns>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string) && value != null)
{
return value.ToString();
}
return base.ConvertTo(context, culture, value, destinationType);
}

/// <summary>
/// String から Enum の Value を取得
/// string -> Enum.Value
/// </summary>
/// <param name="value">string</param>
/// <returns>Enum.value</returns>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string stringValue)
{
return Enum.Parse(EnumType, stringValue);
}
return base.ConvertFrom(context, culture, value);
}
}

#endregion

#region DescriptionConverter

/// <inheritdoc/>
/// <summary>
/// Enum の Value とその Description を変換するコンバータ
/// </summary>
public class EnumToDescriptionConverter : EnumConverter
{
public EnumToDescriptionConverter(Type type) : base(type)
{
if (!type.IsEnum)
{
throw new ArgumentException("Type must be an Enum.");
}
}

/// <summary>
/// Enum の Value から DescriptionAttribute を取得
/// Enum.Value -> string
/// </summary>
/// <param name="value">Enum.value</param>
/// <param name="destinationType">string</param>
/// <returns>string</returns>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string) && value != null)
{
var fieldInfo = value.GetType().GetField(value.ToString());
var descriptionAttribute = fieldInfo?.GetCustomAttribute<DescriptionAttribute>();
if (descriptionAttribute != null)
{
return descriptionAttribute.Description;
}
}
return base.ConvertTo(context, culture, value, destinationType);
}

/// <summary>
/// Enum の DescriptionAttribute から Value を取得
/// string -> Enum.Value
/// </summary>
/// <param name="value">string</param>
/// <returns>Enum.value</returns>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string stringValue)
{
foreach (var field in EnumType.GetFields(BindingFlags.Public | BindingFlags.Static))
{
var descriptionAttribute = field.GetCustomAttribute<DescriptionAttribute>();
if (descriptionAttribute != null && descriptionAttribute.Description == stringValue)
{
return Enum.Parse(EnumType, field.Name);
}
}
}
return base.ConvertFrom(context, culture, value);
}
}

#endregion
}
86 changes: 86 additions & 0 deletions CommEx/Serial/Common/ISerialControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using BveEx.PluginHost;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommEx.Serial.Common
{
public interface ISerialControl
{
/// <summary>
/// ポートを開ける前に呼ばれる
/// </summary>
/// <param name="serialPort"><see cref="SerialPort"/></param>
void PortOpen(SerialPort serialPort);

/// <summary>
/// ポートを閉じた後に呼ばれる
/// </summary>
/// <param name="serialPort"><see cref="SerialPort"/></param>
void PortClose(SerialPort serialPort);

/// <summary>
/// シリアルポートの受信時に呼ばれる
/// </summary>
/// <param name="sender"><see cref="SerialPort"/></param>
/// <param name="e"></param>
//void DataReceived(object sender, SerialDataReceivedEventArgs e);
}

interface IBveEx
{
/// <summary>
/// 全ての BveEx 拡張機能が読み込まれ、BveEx.PluginHost.Plugins.Extensions プロパティが取得可能になると発生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void AllExtensionsLoaded(object sender, EventArgs e);

/// <summary>
/// シナリオ読み込み
/// </summary>
/// <param name="e"></param>
void OnScenarioCreated(ScenarioCreatedEventArgs e);

/// <summary>
/// シナリオ読み込み中に毎フレーム呼び出される
/// </summary>
/// <param name="elapsed"></param>
void Tick(TimeSpan elapsed);

/// <summary>
/// シナリオ終了
/// </summary>
/// <param name="e"></param>
void ScenarioClosed(EventArgs e);
}

/// <summary>
/// 入力されたキーを送信する
/// </summary>
/// <param name="nInputs"></param>
/// <param name="pInputs"></param>
/// <param name="cbsize"></param>
//[DllImport("user32.dll", SetLastError = true)]
//public extern static void SendInput(int nInputs, Input[] pInputs, int cbsize);

/// <summary>
/// BveHacker と Native の初期化
/// </summary>
/// <param name="bveHacker"></param>
/// <param name="native"></param>
/// <exception cref="ArgumentNullException">引数がnullの時に投げる例外</exception>
//public static void Load(IBveHacker bveHacker, INative native)
//{
// native = native ?? throw new ArgumentNullException(nameof(native));
// bveHacker = bveHacker ?? throw new ArgumentNullException(nameof(bveHacker));
//}
//public static void Load(IBveHacker bveHacker)
//{
// bveHacker = bveHacker ?? throw new ArgumentNullException(nameof(bveHacker));
//}

}
50 changes: 50 additions & 0 deletions CommEx/Serial/Common/Loopback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using BveEx.Diagnostics;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommEx.Serial.Common
{
/// <summary>
/// シリアルループバック
/// </summary>
internal class Loopback : ISerialControl
{
/// <inheritdoc/>
public void PortOpen(SerialPort serialPort)
{
serialPort.DataReceived += DataReceived;
}

/// <summary>
/// シリアル受信時のイベントハンドラ
/// 送られてきた情報をそっくりそのまま返す
/// </summary>
/// <param name="sender">受信したポートの <see cref="SerialPort"/></param>
/// <param name="e">イベントデータ</param>
private void DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
SerialPort serialPort = (SerialPort)sender;
string str = serialPort.ReadLine();
serialPort.WriteLine(str);
}
catch (Exception ex)

Check warning on line 36 in CommEx/Serial/Common/Loopback.cs

View workflow job for this annotation

GitHub Actions / MSBuild

The variable 'ex' is declared but never used

Check warning on line 36 in CommEx/Serial/Common/Loopback.cs

View workflow job for this annotation

GitHub Actions / MSBuild

The variable 'ex' is declared but never used
{
#if DEBUG
ErrorDialog.Show(new ErrorDialogInfo("通信エラー", ex.Source, ex.Message));
#endif
}
}

/// <inheritdoc/>
public void PortClose(SerialPort serialPort)
{
serialPort.DataReceived -= DataReceived;
}
}
}
26 changes: 26 additions & 0 deletions CommEx/Serial/Common/NewLines.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Drawing;

namespace CommEx.Serial.Common
{
/// <summary>
/// 改行文字
/// </summary>
[TypeConverter(typeof(EnumToStringConverter))]
public enum NewLines
{
[Description("\n")]
LF,
[Description("\r\n")]
CRLF,
[Description("\r")]
CR
}
}
16 changes: 16 additions & 0 deletions CommEx/Serial/Common/Sample.Setting.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<PortSettings>
<Port PortName="COM0">
<BaudRate>115200</BaudRate>
<DataBits>8</DataBits>
<DtrEnable>false</DtrEnable>
<Handshake>None</Handshake>
<NewLine>CRLF</NewLine>
<Parity>None</Parity>
<StopBits>One</StopBits>
<IsAutoConnent>true</IsAutoConnent>
<Controller>Loopback</Controller>
</Port>
</PortSettings>
</Settings>
Loading