Skip to content

Commit 10c4c7e

Browse files
committed
feat: Uninit 기능 구현 및 리스트 Clear 구현
- 메시지 송신 시 메시지 길이 오류 수정 - 리스트 화면 깜박임을 위한 리스트 클래스 추가
1 parent 913d4ea commit 10c4c7e

File tree

5 files changed

+70
-12
lines changed

5 files changed

+70
-12
lines changed

Form1.Designer.cs

Lines changed: 17 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Form1.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public partial class Form1 : Form
1414
public Form1()
1515
{
1616
InitializeComponent();
17+
selectChennel.SelectedIndex = 0;
18+
selectBaudRate.SelectedIndex = 0;
1719
}
1820

1921
private void ProcessMessage(PcanMessage msg, ulong msgTimeStamp = 0)
@@ -50,7 +52,7 @@ private void SendMessage(string id, string len, string data, bool isExtended)
5052

5153
byte[] dataByteArr = data.Split(' ').Select(s => Convert.ToByte(s, 16)).ToArray();
5254

53-
for (int i = 0; i < msg.Data.MaxLength; i++)
55+
for (int i = 0; i < dataByteArr.Length; i++)
5456
{
5557
msg.Data[i] = dataByteArr[i];
5658
}
@@ -100,10 +102,14 @@ private void ViewTimer_Tick(object sender, EventArgs e)
100102

101103
foreach (CanMessage lstMsg in canMessages)
102104
{
105+
string[] dataArr = BitConverter.ToString(lstMsg.Msg.Data).Split("-");
106+
103107
lstItem = msgViewList.Items[lstMsg.MsgIdx];
104108

105109
lstItem.SubItems[2].Text = lstMsg.Msg.Length.ToString();
106-
lstItem.SubItems[3].Text = BitConverter.ToString(lstMsg.Msg.Data).Replace("-", " ");
110+
lstItem.SubItems[3].Text = "";
111+
for (int i = 0; i < lstMsg.Msg.Length; i++) lstItem.SubItems[3].Text += dataArr[i] + " ";
112+
lstItem.SubItems[3].Text.Trim();
107113
lstItem.SubItems[4].Text = ((lstMsg.MsgTime - lstMsg.MsgPrevTime) * 0.001).ToString("F1");
108114
lstItem.SubItems[5].Text = lstMsg.MsgCount.ToString();
109115
}
@@ -213,7 +219,6 @@ private void initBtn_Click(object sender, EventArgs e)
213219
{
214220
Api.GetErrorText(result, out var errorText);
215221
MessageBox.Show("초기화가 실패했습니다. \n에러메시지: " + errorText, "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
216-
Close();
217222
}
218223
else
219224
{
@@ -229,5 +234,26 @@ private void initBtn_Click(object sender, EventArgs e)
229234
viewTimer.Start();
230235
}
231236
}
237+
238+
private void unInitBtn_Click(object sender, EventArgs e)
239+
{
240+
readTimer.Stop();
241+
viewTimer.Stop();
242+
Api.Uninitialize(channel);
243+
244+
canMessages.Clear();
245+
msgViewList.Items.Clear();
246+
247+
selectBaudRate.Enabled = true;
248+
selectChennel.Enabled = true;
249+
initBtn.Enabled = true;
250+
unInitBtn.Enabled = false;
251+
}
252+
253+
private void listClearBtn_Click(object sender, EventArgs e)
254+
{
255+
canMessages.Clear();
256+
msgViewList.Items.Clear();
257+
}
232258
}
233259
}

ListViewNF.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace PCanMiniView
2+
{
3+
4+
/*
5+
* ListView 깜박임 방지
6+
*/
7+
internal class ListViewNF : System.Windows.Forms.ListView
8+
{
9+
public ListViewNF()
10+
{
11+
this.SetStyle(System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer | System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);
12+
this.SetStyle(System.Windows.Forms.ControlStyles.EnableNotifyMessage, true);
13+
}
14+
15+
protected override void OnNotifyMessage(System.Windows.Forms.Message m)
16+
{
17+
if (m.Msg != 0x14)
18+
{
19+
base.OnNotifyMessage(m);
20+
}
21+
}
22+
}
23+
}

Program.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ namespace PCanMiniView
22
{
33
internal static class Program
44
{
5-
/// <summary>
6-
/// The main entry point for the application.
7-
/// </summary>
85
[STAThread]
96
static void Main()
107
{
11-
// To customize application configuration such as set high DPI settings or default font,
12-
// see https://aka.ms/applicationconfiguration.
138
ApplicationConfiguration.Initialize();
149
Application.Run(new Form1());
1510
}

UtilityHelpers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Peak.Can.Basic;
2+
using System.Reflection;
23

34
namespace PCanMiniView
45
{

0 commit comments

Comments
 (0)