Commit c03cb254 顾剑亮

upload

1 个父辈 61e8ca5e
正在显示 35 个修改的文件 包含 512 行增加1 行删除
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
......@@ -34,6 +35,7 @@ namespace Asa
/// </summary>
public CarerayImage()
{
}
/// <summary>
......@@ -141,4 +143,55 @@ namespace Asa
}
internal static class API
{
//CARERAY_API_PORT int CR_GetDetectorIndexAndIPAddress(CR_DetrIdxAndIPAddr* pDetrIdxAndIPAddr, int* pDetrNum);
[DllImport("CRInterface.dll")]
public static extern int CR_Connect(int nDetrIndex);
[DllImport("CRInterface.dll")]
public static extern int CR_Disconnect(int nDetrIndex);
//CARERAY_API_PORT int CR_ResetDetector(int nDetrIndex, bool needReboot);
//CARERAY_API_PORT int CR_DoSelfTest(int nDetrIndex);
//CARERAY_API_PORT int CR_GetSystemInformation(int nDetrIndex, CR_SystemInfo* pSystemInformation);
//CARERAY_API_PORT int CR_GetApplicationMode(int nDetrIndex, CR_ModeInfo* pModeInfo, int* pModeNum);
//CARERAY_API_PORT int CR_SetApplicationMode(int nDetrIndex, int nModeIndex);
//CARERAY_API_PORT int CR_SetApplicationModeWithParam(int nDetrIndex, int nModeIndex, float* pFrameRate, int* pExposureTime, int nTriggType, int nGainIndex);
//CARERAY_API_PORT int CR_StartAcquisition(int nDetrIndex, int nFrameNum, void* pBuffer, int nNumFrmReqFromDetr = -1); // nNumFrmReqFromDetr == -1 means that detector sends out frames continuously until StopAcquisition() is received.
//CARERAY_API_PORT int CR_StopAcquisition(int nDetrIndex);
//CARERAY_API_PORT int CR_GetDetrStatus(int nDetrIndex, CR_DetrStatus* pDetrStatus);
//CARERAY_API_PORT int CR_StartDarkCalibration(int nDetrIndex);
//CARERAY_API_PORT int CR_StartGainCalibration(int nDetrIndex);
//CARERAY_API_PORT int CR_StopCalibration(int nDetrIndex);
//CARERAY_API_PORT int CR_QueryCalibrationStatus(int nDetrIndex, CR_CalibrationInfo* pCalProgInfo);
//CARERAY_API_PORT int CR_RegisterEventCallback(int nDetrIndex, ICallback* pCallback);
struct CR_SystemInfo
{
uint nRawImageWidth;
uint nRawImageHeight;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
byte[] szHardwareVersion;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
byte[] szSerialNumber;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
byte[] szSoftwareVersion;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
byte[] szFirmwareVersion;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
byte[] szDetrMachineID;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
byte[] szDetrDesc;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
byte[] szReserved;
}
}
}
......@@ -5,3 +5,9 @@ C:\Users\neotel\Desktop\CarerayImage\CarerayImage\obj\Debug\Asa.CarerayImage.dll
C:\Users\neotel\Desktop\CarerayImage\CarerayImage\obj\Debug\Asa.CarerayImage.pdb
C:\Users\neotel\Desktop\CarerayImage\CarerayImage\obj\Debug\CarerayImage.csprojAssemblyReference.cache
C:\Users\neotel\Desktop\CarerayImage\CarerayImage\bin\Debug\Asa.CarerayImage.xml
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage\bin\Debug\Asa.CarerayImage.xml
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage\bin\Debug\Asa.CarerayImage.dll
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage\bin\Debug\Asa.CarerayImage.pdb
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage\obj\Debug\CarerayImage.csproj.CoreCompileInputs.cache
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage\obj\Debug\Asa.CarerayImage.dll
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage\obj\Debug\Asa.CarerayImage.pdb
......@@ -28,6 +28,9 @@ namespace CarerayImage_Test
pictureBox1.Image = careray.Get48bImage();
//bmp.Save(@"C:\Users\neotel\Desktop\20200520X-ray\11.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
......
8135443e5dc0b09562daf22ec658c724a6c1e648
0bdc60cf636ca9d6e9d721d157aa36b80a9e2a56
......@@ -12,3 +12,17 @@ C:\Users\neotel\Desktop\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Te
C:\Users\neotel\Desktop\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Test.exe
C:\Users\neotel\Desktop\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Test.pdb
C:\Users\neotel\Desktop\CarerayImage\CarerayImage_Test\bin\Debug\Asa.CarerayImage.xml
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\bin\Debug\CarerayImage_Test.exe.config
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\bin\Debug\CarerayImage_Test.exe
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\bin\Debug\CarerayImage_Test.pdb
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\bin\Debug\Asa.CarerayImage.dll
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\bin\Debug\Asa.CarerayImage.pdb
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\bin\Debug\Asa.CarerayImage.xml
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Test.csprojAssemblyReference.cache
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Test.Form1.resources
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Test.Properties.Resources.resources
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Test.csproj.GenerateResource.cache
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Test.csproj.CoreCompileInputs.cache
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Test.csproj.CopyComplete
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Test.exe
D:\OneDrive - 上海挚锦科技有限公司\SMD\AutoCountMachine\CarerayImage\CarerayImage_Test\obj\Debug\CarerayImage_Test.pdb

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29920.165
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X-Ray Controller", "X-Ray Controller\X-Ray Controller.csproj", "{FABBED13-18E1-4525-9ACC-E20F8A4032C6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FABBED13-18E1-4525-9ACC-E20F8A4032C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FABBED13-18E1-4525-9ACC-E20F8A4032C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FABBED13-18E1-4525-9ACC-E20F8A4032C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FABBED13-18E1-4525-9ACC-E20F8A4032C6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {621D060F-FE37-4AD4-AF9E-580C33BFEE27}
EndGlobalSection
EndGlobal
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("X-Ray Controller")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("X-Ray Controller")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("fabbed13-18e1-4525-9acc-e20f8a4032c6")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FABBED13-18E1-4525-9ACC-E20F8A4032C6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Asa</RootNamespace>
<AssemblyName>X-Ray</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\X-Ray.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="X_Ray.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Asa
{
/// <summary>
/// X-ray Source (AVJ Technologies Company)
/// </summary>
public class X_Ray
{
private System.IO.Ports.SerialPort port;
private System.Threading.Thread tWarmUp;
private bool finish;
private string result;
private readonly string LAST_DATE = AppDomain.CurrentDomain.BaseDirectory + "LastUsedDate.txt";
/// <summary>
/// 日志事件委托
/// </summary>
/// <param name="log"></param>
public delegate void LogEvent(string log);
/// <summary>
/// 日志事件
/// </summary>
public LogEvent LogOut;
/// <summary>
/// 预热事件委托
/// </summary>
public delegate void WarmUpCompleteEvent();
/// <summary>
/// 预热事件
/// </summary>
public WarmUpCompleteEvent WarmUpComplete;
/// <summary>
/// X-ray Source
/// </summary>
public X_Ray()
{
port = new System.IO.Ports.SerialPort //9600,N,8,1
{
BaudRate = 9600,
Parity = System.IO.Ports.Parity.None,
DataBits = 8,
StopBits = System.IO.Ports.StopBits.One
};
port.DataReceived += Port_DataReceived;
finish = false;
}
/// <summary>
/// 打开或关闭状态
/// </summary>
public bool IsOpen { get { return port.IsOpen; } }
/// <summary>
/// 打开设备
/// </summary>
/// <param name="portName">串口名称</param>
/// <returns></returns>
public bool Open(string portName)
{
port.PortName = portName;
try
{
port.Open();
LogOut?.Invoke("Open " + portName + " OK");
return true;
}
catch (Exception ex)
{
LogOut?.Invoke("Open " + portName + " Error: " + ex.Message);
return false;
}
}
/// <summary>
/// 关闭设备
/// </summary>
public void Close()
{
port.Close();
System.IO.File.WriteAllText(LAST_DATE, DateTime.Now.ToString());
}
/// <summary>
/// 预热
/// </summary>
public void WarmUp()
{
int days;
DateTime lastUsed;
//距离最后一次使用的天数
if (System.IO.File.Exists(LAST_DATE))
{
string s = System.IO.File.ReadAllText(LAST_DATE);
lastUsed = Convert.ToDateTime(s);
TimeSpan ts = DateTime.Now.Subtract(lastUsed);
days = ts.Days;
}
else
{
lastUsed = DateTime.Now.AddDays(-3);
System.IO.File.WriteAllText(LAST_DATE, lastUsed.ToString());
days = 3;
}
LogOut?.Invoke("距离最后使用的天数:" + days);
tWarmUp = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(WarmUpProcess));
tWarmUp.Start(days);
}
public void Start()
{
Send("VP" + "10");
Send("CP" + "1");
}
public void Stop()
{
}
/// <summary>
/// 预热处理线程
/// </summary>
/// <param name="obj">天数</param>
private void WarmUpProcess(object obj)
{
int days = (int)obj;
int seconds = 0;
bool loop = true;
if (days < 3)
{
LogOut?.Invoke("最后使用天数小于3,不需要预热。");
WarmUpComplete?.Invoke();
return;
}
else if (days >= 3 && days < 30) //3-30天
{
seconds = 30;
}
else if (days >= 30 && days < 90) //1-3月
{
seconds = 60;
}
else if (days >= 90) //3个月以上
{
seconds = 300;
}
int step = 0; //步骤
int sleep = 1; //秒
int timer = 0; //计时器
double[] voltage = new double[10] { 30.00, 35.55, 41.10, 46.65, 52.20, 57.75, 63.30, 68.85, 74.40, 80.00 }; //电压,固定值
double[] current = new double[10] { 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50, 0.55, 0.60, 0.70 }; //电流,固定值
while (loop)
{
if (timer == 0)
{
Send("VP" + voltage[step]);
Send("CP" + current[step]);
string log = string.Format("预热{0}/10,{1}kV,{2}uA,{3}s", step + 1, voltage[step], current[step], seconds);
LogOut?.Invoke(log);
}
timer += sleep;
if (timer >= seconds)
{
timer = 0;
step++;
if (step == 10)
loop = false;
}
System.Threading.Thread.Sleep(sleep * 1000);
}
//预热完成,最终日期写入
System.IO.File.WriteAllText(LAST_DATE, DateTime.Now.ToString());
LogOut?.Invoke("预热完成。");
WarmUpComplete?.Invoke();
}
private void Port_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
System.Threading.Thread.Sleep(50);
byte[] buffer = new byte[100];
int count = port.Read(buffer, 0, buffer.Length);
if (buffer[0] == 0x02 && buffer[count - 1] == 0x0D)
result = Encoding.ASCII.GetString(buffer, 1, count - 2);
else
result = "";
finish = true;
}
private bool Send(string s)
{
byte[] cmd = Encoding.ASCII.GetBytes(s);
byte[] buff = new byte[cmd.Length + 2];
Array.Copy(cmd, 0, buff, 1, cmd.Length);
buff[0] = 0x02; //包头
buff[buff.Length - 1] = 0x0D; //包尾
try
{
finish = false;
string log = "Send " + s + " Hex: " + HexBuff(buff);
LogOut?.Invoke(log);
port.Write(buff, 0, buff.Length);
bool rtn = Wait();
if (rtn)
LogOut?.Invoke("Received " + result);
else
LogOut?.Invoke("Received Timeout");
return rtn;
}
catch (Exception ex)
{
LogOut?.Invoke("Send " + s + " Error: " + ex.Message);
return false;
}
}
private bool Wait()
{
int time = 0;
while (time < 5000)
{
if (finish) return true;
System.Threading.Thread.Sleep(50);
time += 50;
}
return false;
}
private string HexBuff(byte[] buff)
{
string s = "";
if (buff == null) return s;
for (int i = 0; i < buff.Length; i++)
s += buff[i].ToString("X2") + " ";
return s;
}
}
}
2020-05-06 12:00:00
\ No newline at end of file
<?xml version="1.0"?>
<doc>
<assembly>
<name>X-Ray</name>
</assembly>
<members>
<member name="T:Asa.X_Ray">
<summary>
X-ray Source (AVJ Technologies Company)
</summary>
</member>
<member name="T:Asa.X_Ray.LogEvent">
<summary>
日志事件委托
</summary>
<param name="log"></param>
</member>
<member name="F:Asa.X_Ray.LogOut">
<summary>
日志事件
</summary>
</member>
<member name="M:Asa.X_Ray.#ctor">
<summary>
X-ray Source
</summary>
</member>
<member name="P:Asa.X_Ray.IsOpen">
<summary>
打开或关闭状态
</summary>
</member>
<member name="M:Asa.X_Ray.Open(System.String)">
<summary>
打开设备
</summary>
<param name="portName">串口名称</param>
<returns></returns>
</member>
<member name="M:Asa.X_Ray.Close">
<summary>
关闭设备
</summary>
</member>
<member name="M:Asa.X_Ray.WarmUp">
<summary>
预热
</summary>
</member>
</members>
</doc>
D:\OneDrive - 上海挚锦科技有限公司\SMD\X-Ray Controller\X-Ray Controller\bin\Debug\X-Ray.dll
D:\OneDrive - 上海挚锦科技有限公司\SMD\X-Ray Controller\X-Ray Controller\bin\Debug\X-Ray.pdb
D:\OneDrive - 上海挚锦科技有限公司\SMD\X-Ray Controller\X-Ray Controller\obj\Debug\X-Ray Controller.csproj.CoreCompileInputs.cache
D:\OneDrive - 上海挚锦科技有限公司\SMD\X-Ray Controller\X-Ray Controller\obj\Debug\X-Ray.dll
D:\OneDrive - 上海挚锦科技有限公司\SMD\X-Ray Controller\X-Ray Controller\obj\Debug\X-Ray.pdb
D:\OneDrive - 上海挚锦科技有限公司\SMD\X-Ray Controller\X-Ray Controller\bin\Debug\X-Ray.xml
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!