简单总结此次软件遇到的问题
1、打包是会碰到程序中调用了其他的程序集或者.exe,其目录可能在生成文件的目录下或者相对目录下,需要一起打包(需要的文件可以根据.bat路径查找)
2、.bat文件的编写
cd /d f:\file\newPage //进去一个绝对路径,当然这里非必须
Echo **开始升级** //显示提示内容
cd .\testfile1 //进入相对路径
.\test1.exe //执行某个.exe
cd ..\testfile2 //返回上一层,进入相对路径
.\test2.exe -fw ..\firmware\acc\release\dd.img //执行.exe 参数,后面跟着testfile2同级目录下firmware下面文件的.img
Echo **请接入新设备,按任意键继续下一设备** //显示内容
pause //不退出窗口
goto Start
在调用.exe时,出现一种情况,单独运行.exe,会出现cmd命令窗口,可以发送指令控制程序运行,同时调用camera工具。但是carmera工具无法单独关闭,必须在cmd窗口中发送命令关闭或者直接关闭cmd.
若在代码中直接调用carmer.exe工具,则不会出现cmd窗口,无法关闭掉程序。
解决方法:只能调用.bat文件,这样会出现cmd窗口,可以关闭掉应用。
3、开辟进程,调用exe文件或者.bat文件
a)调用无参数的.exe工具
Process p = new Process();
p.StartInfo.FileName = ".\\Tool\\Reader.exe";
p.StartInfo.UseShellExecute = false;//是否使用shell调用,填写true,显示error
p.StartInfo.RedirectStandardInput = true;//是否调用来自程序的输入信息
p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
p.StartInfo.CreateNoWindow = true;//不显示程序窗口
p.Start();//启动程序
b)调用有参数的.exe工具,并将运行结果保留(可以用于显示,打印在log窗口中)
Process p = new Process();
p.StartInfo.FileName = ".\\Tool\\CopperTool.exe";
p.StartInfo.Arguments = "/GetInfo"; //调用程序的参数
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
string result = p.StandardOutput.ReadToEnd();//运行程序结果,这里要等调用程序运行结束后才会显示结果。
richTextBox.Text += result;
p.WaitForExit();//等待结束,关闭
p.Close();
c)调用.文件bat
Process p = new Process();
p.StartInfo.WorkingDirectory = ".\\Tool\\";
p.StartInfo.FileName = "Download.bat";
p.Start();
修改目录
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(p.StartInfo.FileName);
关掉某个进程
Process[] p = Process.GetProcesses();
for (int i = 0; i < p.Length; i++)
{
if (p[i].ProcessName.StartsWith("oastest"))
{
p[i].Kill();
}
}
.
4、byte[]数据处理和显示
a)将string改为float
Convert.ToSingle(text_data_h.Text);
float fdata_h = float.Parse(text_data_h.Text);
float fdata_l = float.Parse(text_data_l.Text);
或者:
float f = 0;
float.TryParse("1.123", out f);若不能转换,返回false,成功,结果保存在f中。
b)string---int---byte[]
int num1 = Convert.ToInt32(opt_1.Text);
int num2 = Convert.ToInt32(opt_2.Text);
int num3 = Convert.ToInt32(opt_3.Text);
int num4 = Convert.ToInt32(opt_4.Text);
byte[] dd1 = System.BitConverter.GetBytes(num1);
byte[] dd2 = System.BitConverter.GetBytes(num2);
byte[] dd3 = System.BitConverter.GetBytes(num3);
byte[] dd4 = System.BitConverter.GetBytes(num4);
byte[] buff = { 0x00, 0x00, 0x00, dd1[0], dd2[0], dd3[0], dd4[0] };
c)string转为对应的16进制int型
Convert.ToInt32(txtBxSlaveID[i].Text, 16);
string转为对应的16进制byte型
(byte)Convert.ToInt32(txtBxSlaveID[i].Text, 16);
string转为对应10进制int型
Convert.ToInt32(txtBxSlaveID[i].Text);
string转为对应10进制byte型
(byte)Convert.ToInt32(txtBxSlaveID[i].Text);
5 将byte转为int
int data1=(int)RecvBuffer[0];
richtextbox.Text=data1.ToString();
..