This repository was archived by the owner on Apr 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvrdude.cs
More file actions
102 lines (86 loc) · 3.01 KB
/
Avrdude.cs
File metadata and controls
102 lines (86 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Diagnostics;
using System.IO;
namespace BlockFirmwareWriter
{
public class Avrdude
{
public Avrdude(string exePath, string confPath = null)
{
m_AvrdudePath = exePath;
m_ConfigPath = confPath;
}
public void OpenCmd(string _args = "", bool pause = true, bool openPromptOnly = false)
{
if (!File.Exists(m_AvrdudePath))
{
throw new InvalidOperationException("avrdudeのパスを設定してください。");
}
var p = new Process();
p.StartInfo.FileName = Environment.GetEnvironmentVariable("ComSpec");
var avrdudePath = Path.GetDirectoryName(m_AvrdudePath);
var args = (openPromptOnly || pause) ? "/K " : "/C ";
args += "cd \"" + avrdudePath + "\"";
if (!openPromptOnly)
{
args += " .\\avrdude.exe -c usbasp -p t85 ";
if (File.Exists(m_ConfigPath))
{
args += $" -C \"{m_ConfigPath}\" ";
}
args += _args;
}
p.StartInfo.Arguments = args;
p.Start();
}
public ExecInfo Execute(string args = "", bool checkOnlyExeWorks = false)
{
if (!File.Exists(m_AvrdudePath))
{
throw new InvalidOperationException("avrdudeのパスを設定してください。");
}
if (!checkOnlyExeWorks)
{
args += " -c usbasp -p t85";
}
if (File.Exists(m_ConfigPath))
{
args += $" -C \"{m_ConfigPath}\"";
}
var p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = m_AvrdudePath;
p.StartInfo.Arguments = args;
p.Start();
string stdout = p.StandardOutput.ReadToEnd();
string stderr = p.StandardError.ReadToEnd();
p.WaitForExit();
bool ret = (p.ExitCode == 0);
if (checkOnlyExeWorks)
{
string expectedErrorMsg = @"avrdude.exe: no programmer has been specified on the command line or the config file";
string actual = stderr.Trim().Split('\n')[0].Trim();
ret |= (actual == expectedErrorMsg);
}
return new ExecInfo(ret, stdout);
}
private string m_AvrdudePath { get; set; }
private string m_ConfigPath { get; set; }
}
/// <summary>
/// 実行時情報
/// </summary>
public class ExecInfo
{
public ExecInfo(bool success, string stdout = null)
{
Success = success;
StdOut = stdout;
}
public bool Success { get; }
public string StdOut { get; }
}
}