Browse Source

提交对接下硬件适配

master
胡超1 1 year ago
parent
commit
74da2a0baa
  1. 3
      DevicesService/App.config
  2. 5
      DevicesService/Commen/Log.cs
  3. 19
      DevicesService/Commen/ScriptCallbackObject.cs
  4. 430
      DevicesService/Commen/TcpServer.cs
  5. 12
      DevicesService/Commen/Util.cs
  6. 212
      DevicesService/Devices/SignDll.cs
  7. 7
      DevicesService/DevicesService.csproj
  8. 53
      DevicesService/Program.cs

3
DevicesService/App.config

@ -6,5 +6,8 @@
<!--高拍仪图片旋转方向逆时针为例--> <!--高拍仪图片旋转方向逆时针为例-->
<add key="xzds" value="90"/> <add key="xzds" value="90"/>
<add key="ysb" value="10"/> <add key="ysb" value="10"/>
<add key="ipAddress" value="192.168.1.166"/>
<add key="port" value="1234"/>
<add key="rootPath" value="http://192.168.1.166:5000/wwwroot/"/>
</appSettings> </appSettings>
</configuration> </configuration>

5
DevicesService/Commen/Log.cs

@ -39,11 +39,13 @@ namespace DevicesService.Commen
if (streamWriter != null) if (streamWriter != null)
{ {
streamWriter.Flush(); streamWriter.Flush();
if (streamWriter != null) {
streamWriter.Dispose(); streamWriter.Dispose();
streamWriter = null; streamWriter = null;
} }
} }
} }
}
public static void Info(string message) public static void Info(string message)
{ {
@ -73,10 +75,13 @@ namespace DevicesService.Commen
if (streamWriter != null) if (streamWriter != null)
{ {
streamWriter.Flush(); streamWriter.Flush();
if (streamWriter != null)
{
streamWriter.Dispose(); streamWriter.Dispose();
streamWriter = null; streamWriter = null;
} }
} }
} }
} }
}
} }

19
DevicesService/Commen/ScriptCallbackObject.cs

@ -27,6 +27,7 @@ using DevicesService.Commen;
using System.Numerics; using System.Numerics;
using System.Web; using System.Web;
using NAudio.Wave.SampleProviders; using NAudio.Wave.SampleProviders;
using System.Configuration;
namespace DevicesService.Common namespace DevicesService.Common
{ {
@ -489,15 +490,9 @@ namespace DevicesService.Common
//结束录音上传文件 //结束录音上传文件
if (!string.IsNullOrEmpty(url) && !isopen) if (!string.IsNullOrEmpty(url) && !isopen)
{ {
//Task.Run(async () => string filename = Path.GetFileName(srpath);
//{ string path = ConfigurationManager.AppSettings["rootPath"].ToString();
// UploadInfo(url); return path + "Record/" + filename;
//});
//@event2.WaitOne();
//Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)");
//MatchCollection mc = re.Matches(url);//获取的是一个数组
//string reurl = mc[0].ToString() + "://" + mc[1].ToString() + urlpath;
return "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + srpath + "\"}";
} }
else if (isopen)//开始录音 else if (isopen)//开始录音
{ {
@ -732,7 +727,7 @@ namespace DevicesService.Common
// 创建WaveFileWriter对象来保存录音数据 路径在bin文件下 // 创建WaveFileWriter对象来保存录音数据 路径在bin文件下
writer = new WaveFileWriter(srpath, waveFormat); writer = new WaveFileWriter(srpath, waveFormat);
//编写器 //编写器
mStreamWriter = new StreamWriter(pathfile, false, new System.Text.UTF8Encoding(false)); //mStreamWriter = new StreamWriter(pathfile, false, new System.Text.UTF8Encoding(false));
// 设置录音回调函数 // 设置录音回调函数
int bitIndex = bitsPerSample / 8; int bitIndex = bitsPerSample / 8;
waveIn.DataAvailable += (sender, e) => waveIn.DataAvailable += (sender, e) =>
@ -745,7 +740,7 @@ namespace DevicesService.Common
//int sample = (int)((e.Buffer[i * bitIndex + 2] << 16) | (e.Buffer[i * bitIndex + 1] << 8) | e.Buffer[i * bitIndex]); //int sample = (int)((e.Buffer[i * bitIndex + 2] << 16) | (e.Buffer[i * bitIndex + 1] << 8) | e.Buffer[i * bitIndex]);
//16bit 将两个byte数据组合成一个short数据 //16bit 将两个byte数据组合成一个short数据
short sample = (short)((e.Buffer[i * bitIndex + 1] << 8) | e.Buffer[i * bitIndex]); short sample = (short)((e.Buffer[i * bitIndex + 1] << 8) | e.Buffer[i * bitIndex]);
mStreamWriter.Write("{0},", sample); //mStreamWriter.Write("{0},", sample);
} }
}; };
try try
@ -769,7 +764,7 @@ namespace DevicesService.Common
waveIn.StopRecording(); waveIn.StopRecording();
waveIn.Dispose(); waveIn.Dispose();
writer.Close(); writer.Close();
mStreamWriter.Close(); //mStreamWriter.Close();
waveIn = null; waveIn = null;
} }
catch (Exception ex) catch (Exception ex)

430
DevicesService/Commen/TcpServer.cs

@ -7,6 +7,15 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Linq; using System.Linq;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Configuration;
using System.Threading.Tasks;
using DevicesService.Common;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Drawing;
using System.IO.Ports;
using System.IO;
using System.Reflection;
namespace DevicesService.Commen namespace DevicesService.Commen
{ {
/// <summary> /// <summary>
@ -14,8 +23,429 @@ namespace DevicesService.Commen
/// </summary> /// </summary>
public class TcpServer public class TcpServer
{ {
public static List<TcpClient> clients = new List<TcpClient>();
private static ScriptCallbackObject scriptCallback = new ScriptCallbackObject();
public static void Start()
{
try
{
TcpListener listener = new TcpListener(IPAddress.Any, 1234);
listener.Start();
Console.WriteLine("服务器已启动,等待客户端连接...");
Timer timer = new Timer(SendHelloMessage, null, TimeSpan.Zero, TimeSpan.FromSeconds(20));
while (true)
{
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("客户端已连接:{0}", client.Client.RemoteEndPoint);
clients.Add(client);
// 启动线程,接收客户端消息
ThreadPool.QueueUserWorkItem(ReceiveMessage, client);
}
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
finally { }
}
/// <summary>
/// 发送数据
/// </summary>
/// <param name="client"></param>
/// <param name="message"></param>
public static void SendDataWithHeader(TcpClient client, string message)
{
try
{
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
byte[] header = BitConverter.GetBytes(messageBytes.Length);
byte[] data = new byte[header.Length + messageBytes.Length];
Array.Copy(header, 0, data, 0, header.Length);
Array.Copy(messageBytes, 0, data, header.Length, messageBytes.Length);
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
finally { }
}
/// <summary>
/// 发送一个Hello的方法
/// </summary>
/// <param name="state"></param>
public static void SendHelloMessage(object state)
{
foreach (TcpClient client in clients)
{
try
{
SendDataWithHeader(client, " heartbeatService");
}
catch (Exception ex)
{
Console.WriteLine("向客户端 {0} 发送消息失败:{1}", client.Client.RemoteEndPoint, ex.Message);
clients.Remove(client);
break;
}
}
}
/// <summary>
/// 读取客户端信息
/// </summary>
/// <param name="state"></param>
public static void ReceiveMessage(object state)
{
TcpClient client = (TcpClient)state;
NetworkStream stream = client.GetStream();
while (true)
{
try
{
// 读取包头,获取消息的大小
int messageSize = ReadHeader(stream);
// 读取消息内容
byte[] buffer = new byte[messageSize];
int bytesRead = ReadExactly(stream, buffer, 0, messageSize);
if (bytesRead < messageSize)
{
Console.WriteLine("无法读取消息,可能是连接断开:{0}", client.Client.RemoteEndPoint);
clients.Remove(client);
break;
}
string message = Encoding.UTF8.GetString(buffer, 0, bytesRead);
if (!message.Contains("heartbeatClient") || message != "keepAlive")
{
Console.WriteLine("收到客户端消息:{0}", message);
string indata = message;
if (!string.IsNullOrEmpty(indata))
{
string result = Util.Base64str2(indata);
Log.Info("接收到COM口传来数据:" + result);
if (!string.IsNullOrEmpty(result))
{
JObject jo = (JObject)JsonConvert.DeserializeObject(result);
int type = Convert.ToInt32(jo["type"].ToString());
string param = jo["param"].ToString();
string resultback = string.Empty;
string base64 = string.Empty;
string data = string.Empty;
string callback = jo["callback"].ToString();
JObject joparam;
switch (type)
{
//{"type":"1","param":{"data":""}}
case Func.IDCardRead:
#region 读取身份证
try
{
joparam = (JObject)JsonConvert.DeserializeObject(param);
data = joparam["data"].ToString();
resultback = scriptCallback.IDCardRead(data, callback);
//Console.WriteLine(resultback);
Log.Info("读取身份证 返回数据:" + resultback);
base64 = Util.str2Base64(resultback);
//向com对方发送数据
SendDataWithHeader(client, base64);
}
catch (Exception ex)
{
string rest = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
base64 = Util.str2Base64(rest);
SendDataWithHeader(client, base64);
}
#endregion
break;
//{"type":"2","param":{"ph":"A012","ddrs":"10","qrcode":"www.baidu.com/s?wd=国家赔偿","ywmc":"国家赔偿"}}
case Func.SendByPrint:
#region 打印排队票据
try
{
joparam = (JObject)JsonConvert.DeserializeObject(param);
string ph = joparam["ph"].ToString();
string ddrs = joparam["ddrs"].ToString();
string qrcode = joparam["qrcode"].ToString();
string ywmc = joparam["ywmc"].ToString();
resultback = scriptCallback.SendByPrint(ph, ddrs, qrcode, ywmc, callback);
Log.Info("打印排队票据 返回数据:" + resultback);
base64 = Util.str2Base64(resultback);
//向com对方发送数据
SendDataWithHeader(client, base64);
}
catch (Exception ex)
{
string rest = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
base64 = Util.str2Base64(rest);
SendDataWithHeader(client, base64);
}
#endregion
break;
//{"type":"3","param":{"text":"欢迎使用阿凯思控诉业务一体机","ispaye":false}}
case Func.payleText:
#region 文字语音播报
try
{
joparam = (JObject)JsonConvert.DeserializeObject(param);
data = joparam["text"].ToString();
bool ispaye = Convert.ToBoolean(joparam["ispaye"].ToString());
resultback = scriptCallback.payleText(data, ispaye, callback);
//Console.WriteLine(resultback);
Log.Info("文字语音播报 返回数据:" + resultback);
base64 = Util.str2Base64(resultback);
//向com对方发送数据
SendDataWithHeader(client, base64);
}
catch (Exception ex)
{
string rest = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
base64 = Util.str2Base64(rest);
SendDataWithHeader(client, base64);
}
#endregion
break;
//{"type":"4","param":{"content":"欢迎使用阿凯思控诉业务一体机","phone":"13333333333"}}
case Func.SendSSM:
#region 发送短信
try
{
joparam = (JObject)JsonConvert.DeserializeObject(param);
string content = joparam["content"].ToString();
string phone = joparam["phone"].ToString();
resultback = scriptCallback.SendSSM(content, phone, callback);
Log.Info("发送短信 返回数据:" + resultback);
base64 = Util.str2Base64(resultback);
//向com对方发送数据
SendDataWithHeader(client, base64);
}
catch (Exception ex)
{
string rest = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
base64 = Util.str2Base64(rest);
SendDataWithHeader(client, base64);
}
#endregion
break;
//{"type":"5","param":{"url":"http://192.168.0.34:92/api/UploadFP/UploadFP"}}
case Func.openCamera:
#region 打开高拍仪并且进行快速扫描文件
try
{
joparam = (JObject)JsonConvert.DeserializeObject(param);
data = joparam["url"].ToString();
resultback = scriptCallback.openCamera(data, callback);
Log.Info("打开高拍仪并且进行快速扫描文件 返回数据:" + resultback);
//base64 = Util.str2Base64(resultback);
//向com对方发送数据
SendDataWithHeader(client, resultback);
}
catch (Exception ex)
{
string rest = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
base64 = Util.str2Base64(rest);
SendDataWithHeader(client, base64);
}
#endregion
break;
//{"type":"6","param":{"data":""}}
case Func.OpenSign:
#region 打开签字版数据
try
{
joparam = (JObject)JsonConvert.DeserializeObject(param);
data = joparam["data"].ToString();
resultback = scriptCallback.OpenSign(data, callback);
Log.Info("打开签字版数据 返回数据:" + resultback);
base64 = Util.str2Base64(resultback);
//向com对方发送数据
SendDataWithHeader(client, base64);
}
catch (Exception ex)
{
string rest = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
base64 = Util.str2Base64(rest);
SendDataWithHeader(client, base64);
}
#endregion
break;
//{"type":"7","param":{"data":""}}
case Func.CloseSign:
#region 关闭签字版数据
try
{
joparam = (JObject)JsonConvert.DeserializeObject(param);
data = joparam["data"].ToString();
resultback = scriptCallback.CloseSign(data, callback);
Log.Info("关闭签字版数据 返回数据:" + resultback);
base64 = Util.str2Base64(resultback);
//向com对方发送数据
SendDataWithHeader(client, base64);
}
catch (Exception ex)
{
string rest = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
base64 = Util.str2Base64(rest);
SendDataWithHeader(client, base64);
}
#endregion
break;
//{"type":"8","param":{"url":"http://192.168.0.34:92/api/UploadFP/UploadFP"}}
case Func.GetSignData:
#region 获取签字版数据
try
{
string sourcepaht = Environment.CurrentDirectory + "\\fiveInch.png";
FileInfo fileInfo = new FileInfo(sourcepaht);
if (fileInfo.Exists)
{
double size = fileInfo.Length / 1024.0;
if (size > 10)
{
FileStream fs1 = fileInfo.OpenRead();
fs1.Close();
resultback = Util.ImgToBase64String(sourcepaht);
int width = 800;
int height = 394;
using (Bitmap blankImage = new Bitmap(width, height))
{
// 设置图片背景为完全透明
using (Graphics g = Graphics.FromImage(blankImage))
{
// 使用白色背景填充图片
g.Clear(Color.Transparent);
}
// 保存图片到文件系统
blankImage.Save(sourcepaht);
}
}
else
{
resultback = Util.str2Base64("400");
}
}
else
{
resultback = Util.str2Base64("400");
}
Log.Info("获取签字版数据 返回数据:" + resultback);
// base64 = Util.str2Base64(resultback);
//向com对方发送数据
SendDataWithHeader(client, resultback);
}
catch (Exception ex)
{
string rest = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
base64 = Util.str2Base64(rest);
SendDataWithHeader(client, base64);
}
#endregion
break;
//开始录音:{"type":"11","param":{"url":"","isopen":true}}
//结束录音:{"type":"11","param":{"url":"http://192.168.0.34:92/api/UploadFP/UploadFP","isopen":false}}
//取消录音:{"type":"11","param":{"url":"","isopen":false}}
case Func.SoundRecording:
#region 开始录音、取消录音、结束录音
try
{
joparam = (JObject)JsonConvert.DeserializeObject(param);
string url = joparam["url"].ToString();
bool isopen = Convert.ToBoolean(joparam["isopen"].ToString());
resultback = scriptCallback.SoundRecording(isopen, url, callback);
Log.Info("开始录音、取消录音、结束录音 返回数据:" + resultback);
base64 = Util.str2Base64(resultback);
//向com对方发送数据
SendDataWithHeader(client, base64);
}
catch (Exception ex)
{
string rest = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
base64 = Util.str2Base64(rest);
SendDataWithHeader(client, base64);
}
#endregion
break;
default:
string str = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "调用方法不存在" + "\"}";
base64 = Util.str2Base64(str);
SendDataWithHeader(client, base64);
break;
}
}
else
{
string str = "{\"callback\":\"" + "callback" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数不能为空" + "\"}";
string base64 = Util.str2Base64(str);
SendDataWithHeader(client, base64);
}
}
}
if (message == "keepAlive")
{
// 客户端发送心跳指令,关闭连接
Console.WriteLine("客户端发送了心跳指令,关闭连接:{0}", client.Client.RemoteEndPoint);
clients.Remove(client);
client.Close();
break;
}
}
catch { }
finally { }
}
}
/// <summary>
/// 解析包头里面有多少字节
/// </summary>
/// <param name="stream"></param>
/// <returns></returns>
public static int ReadHeader(NetworkStream stream)
{
try
{
byte[] header = new byte[4];
int headerBytesRead = stream.Read(header, 0, 4);
if (headerBytesRead < 4)
{
return -1;
}
return BitConverter.ToInt32(header, 0);
}
catch { return -1; }
finally { }
} }
/// <summary>
/// 等待流全部获取到,然后丢出去
/// </summary>
/// <param name="stream"></param>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="count"></param>
/// <returns></returns>
public static int ReadExactly(NetworkStream stream, byte[] buffer, int offset, int count)
{
try
{
int bytesRead = 0;
while (bytesRead < count)
{
int result = stream.Read(buffer, offset + bytesRead, count - bytesRead);
if (result == 0)
{
// 连接断开或遇到流的末尾
return bytesRead;
}
bytesRead += result;
}
return bytesRead;
}
catch { return -1; }
finally { }
}
}
} }

12
DevicesService/Commen/Util.cs

@ -397,5 +397,17 @@ namespace DevicesService.Common
return result; return result;
} }
} }
/// <summary>
/// 文件转base64
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static string FileToBase64(string filePath)
{
byte[] fileBytes = File.ReadAllBytes(filePath);
string base64String = Convert.ToBase64String(fileBytes);
return base64String;
}
} }
} }

212
DevicesService/Devices/SignDll.cs

@ -1,15 +1,11 @@
using System; using Functions.FileExt;
using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
using System.ComponentModel; using System;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Globalization; using System.Globalization;
using Functions.FileExt;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Text;
//0816加实时报点 //0816加实时报点
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct TOUCH_INFO public struct TOUCH_INFO
@ -25,18 +21,17 @@ namespace DevicesService.Devices
public class SignDll public class SignDll
{ {
public static PointF endPos; public static PointF endPos;
public static int status = -1;
public static PointF beginPos; public static PointF beginPos;
public static PointF frontPos; public static PointF frontPos;
private static int xypointcount; private static int xypointcount = 0;
private static int[] lastpointx = new int[3]; private static int[] lastpointx = new int[3];
private static int[] lastpointy = new int[3]; private static int[] lastpointy = new int[3];
Point mPoint = new Point(-1, -1); Point mPoint = new Point(-1, -1);
private System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); private static System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
private Bitmap bitmap = new Bitmap(594, 392); //private Graphics mGraphicsBuffer;
private static Graphics g; private static Pen pen = new Pen(Color.Black); //
private static Pen pen = new Pen(Color.Red); public static int status = -1;
private static Bitmap bitmap = new Bitmap(594, 392);
public SignDll() public SignDll()
{ {
endPos = new PointF(-1F, -1f); endPos = new PointF(-1F, -1f);
@ -49,163 +44,77 @@ namespace DevicesService.Devices
lastpointx[2] = -1; lastpointx[2] = -1;
lastpointy[2] = -1; lastpointy[2] = -1;
xypointcount = 0; xypointcount = 0;
g = Graphics.FromImage(bitmap);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
} }
public static void GetTouchNumber(int number) public static void GetTouchNumber(int number)
{ {
try
{
//1 签字确定按钮 2签字取消按钮 3 签字重签按钮(清空界面)
if (number == 1) if (number == 1)
{ {
int ret = FiveInchDll.ComSignOK(); int ret = FiveInchDll.ComSignOK();
Console.WriteLine("ComSignOK:" + ret);
FiveInchDll.ComSetBackGroundAdv();
} }
else else if (number == 3)
{
g.Clear(System.Drawing.Color.White);
lastpointx[0] = -1;
lastpointy[0] = -1;
lastpointx[1] = -1;
lastpointy[1] = -1;
lastpointx[2] = -1;
lastpointy[2] = -1;
}
}
//0816加报点
public static void GetTouchPoint(TOUCH_INFO[] info1)
{ {
int x = 0, y = 0;
int pressurevl;
int dx = 0, dy = 0;
for (int k = 0; k < 80; k++) string UIFile = System.IO.Directory.GetCurrentDirectory() + "\\sign_ui.jpg";
{ int ret = FiveInchDll.ComSetSignBackgroundImage(UIFile);
x = info1[k].X; Console.WriteLine("ComSetSignBackgroundImage:" + ret);
y = info1[k].Y;
if (info1[k].Pressure > 0)
{
if (info1[k].Pressure > 0 && info1[k].Pressure < 500)
{
pressurevl = 1;
pen.Width = 1;
} }
else if (info1[k].Pressure >= 500 && info1[k].Pressure < 1000) //2023-02-27 通知返回获取SN
else if (number == 17) //返回设备SN
{ {
pressurevl = 2; StringBuilder sbDevSN = new StringBuilder();
pen.Width = 2; FiveInchDll.ComGetDevSN_Async(sbDevSN);
} Console.WriteLine("ComGetDevSN:" + sbDevSN);
else if (info1[k].Pressure >= 1000 && info1[k].Pressure < 1500)
{
pressurevl = 3;
pen.Width = 3;
}
else if (info1[k].Pressure >= 1500 && info1[k].Pressure < 2048)
{
pressurevl = 4;
pen.Width = 4;
}
else
{
pressurevl = 0;
pen.Width = 1;
}
} }
else else
{ {
pressurevl = 0;
lastpointx[0] = -1; lastpointx[0] = -1;
lastpointy[0] = -1; lastpointy[0] = -1;
lastpointx[1] = -1; lastpointx[1] = -1;
lastpointy[1] = -1; lastpointy[1] = -1;
lastpointx[2] = -1; lastpointx[2] = -1;
lastpointy[2] = -1; lastpointy[2] = -1;
continue;
}
if (info1[k].Pressure > 10) //有画线宽度
{
lastpointx[2] = x;
lastpointy[2] = y;
if (lastpointx[2] != -1)
{
if (lastpointx[1] != -1 && lastpointx[0] != -1)
{
//float dx = Math.Abs(lastpointx[2] - beginPos.X);
//float dy = Math.Abs(endPos.Y - beginPos.Y);
dx = Math.Abs(lastpointx[2] - lastpointx[1]); FiveInchDll.ComSetBackGroundAdv();
dy = Math.Abs(lastpointy[2] - lastpointy[1]);
if ((dx != 0) && (dy != 0))
{
if (lastpointy[1] != -1 && lastpointy[2] != -1) //y轴相同的点不画,直接跳过
{
if (lastpointx[1] != -1 && lastpointx[2] != -1) //第3个点和第二个点比较是否x坐标在同一个位置,不是就执行画第一个点到第二个点的线
{
//painter->drawLine(frontPos, beginPos); //画线
g.DrawLine(pen, lastpointx[0], lastpointy[0], lastpointx[1], lastpointy[1]);
//painter->drawPoint(beginPos); //画点
//frontPos = beginPos;
//beginPos = endPos;
lastpointx[0] = lastpointx[1];
lastpointy[0] = lastpointy[1];
lastpointx[1] = lastpointx[2];
lastpointy[1] = lastpointy[2];
}
else
{
//是就执行画第一个点到第三个点的线
//painter->drawLine(frontPos, endPos);
g.DrawLine(pen, lastpointx[0], lastpointy[0], lastpointx[2], lastpointy[2]);
//frontPos = endPos; //第三个点赋值第一个点
//beginPos = QPointF(0, 0); //第二个点置空
//beginPos.X = -1;
//beginPos.Y = -1;
lastpointx[0] = lastpointx[2];
lastpointy[0] = lastpointy[2];
lastpointx[1] = -1;
lastpointy[1] = -1;
}
}
} }
}//
else
{
if (lastpointx[1] != -1) //不为空在赋值,防止丢弃点时赋空值
{
lastpointx[0] = lastpointx[1];
lastpointy[0] = lastpointy[1];
} }
lastpointx[1] = lastpointx[2]; catch { }
lastpointy[1] = lastpointy[2]; finally { }
} }
}
}
else
{
dx = dy = 0;
lastpointx[0] = -1;
lastpointy[0] = -1;
lastpointx[1] = -1;
lastpointy[1] = -1;
lastpointx[2] = -1;
lastpointy[2] = -1;
} //0816加报点
} public static void GetTouchPoint(TOUCH_INFO[] info1)
} { }
//打开签字版 //打开签字版
public static int OpenComDevice() public static int OpenComDevice()
{ {
if (status == -1) int status = FiveInchDll.OpenComDevice(GetTouchNumber);
Console.WriteLine("OpenComDevice:" + status);
if (status == 0)
{ {
status = FiveInchDll.OpenComDevice(GetTouchNumber); //2022-08-16 加实时报点
if (status != 0) status = FiveInchDll.ComSendPoint(1, GetTouchPoint);
Console.WriteLine("ComSendPoint:" + status);
if (true)
{ {
status = -1; string UIFile = System.IO.Directory.GetCurrentDirectory() + "\\adv_ui.jpg";
int ret1 = FiveInchDll.ComSendAdvantageImage(UIFile);
Console.WriteLine("ComSendAdvantageImage:" + ret1);
FiveInchDll.ComSetBackGroundAdv();
}
if (true)
{
string UIFile = System.IO.Directory.GetCurrentDirectory() + "\\sign_ui.jpg";
int ret1 = FiveInchDll.ComSetSignBackgroundImage(UIFile);
Console.WriteLine("ComSetSignBackgroundImage:" + ret1);
} }
} }
return status; return status;
@ -282,5 +191,26 @@ namespace DevicesService.Devices
[DllImport("XTJZFiveInch.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] [DllImport("XTJZFiveInch.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int ComSignOK(); public static extern int ComSignOK();
[DllImport("XTJZFiveInch.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int ComSetPenStyle(int PenStyle);
[DllImport("XTJZFiveInch.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int ComGetDevSN(StringBuilder pDevSN, int iSync);
[DllImport("XTJZFiveInch.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int ComGetDevSN_Async(StringBuilder pDevSN);
[DllImport("XTJZFiveInch.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int ComWhiteScreen();
[DllImport("XTJZFiveInch.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int ComSendAdvantageImage(string UIFile);
[DllImport("XTJZFiveInch.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int ComSetBackGroundAdv();
} }
} }

7
DevicesService/DevicesService.csproj

@ -1,14 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ApplicationIcon>favicon.ico</ApplicationIcon> <ApplicationIcon>favicon.ico</ApplicationIcon>
<StartupObject /> <StartupObject />
<LangVersion>9.0</LangVersion> <LangVersion>9.0</LangVersion>
<AssemblyName>DevicesService</AssemblyName> <AssemblyName>DevicesService</AssemblyName>
<Platforms>AnyCPU;x86</Platforms> <Platforms>AnyCPU;x86</Platforms>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@ -33,6 +32,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Aspose.Words" Version="19.11.0" /> <PackageReference Include="Aspose.Words" Version="19.11.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="NAudio" Version="2.2.1" /> <PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="NAudio.Asio" Version="2.2.1" /> <PackageReference Include="NAudio.Asio" Version="2.2.1" />
<PackageReference Include="NAudio.Core" Version="2.2.1" /> <PackageReference Include="NAudio.Core" Version="2.2.1" />

53
DevicesService/Program.cs

@ -1,11 +1,14 @@
using DevicesService.Commen; using DevicesService.Commen;
using DevicesService.Common; using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using System; using System;
using System.Diagnostics; using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DevicesService namespace DevicesService
{ {
internal class Program internal class Program
@ -17,24 +20,38 @@ namespace DevicesService
static void Main(string[] args) static void Main(string[] args)
{ {
// 更改为你想检查的进程名称 // 更改为你想检查的进程名称
new COMUtils(); //new COMUtils();
while (true) //启动静态服务器
Task.Run(() =>
{ {
Task.Delay(2000).Wait(); WebHost.CreateDefaultBuilder().UseUrls("http://0.0.0.0:5000").ConfigureServices(services => {
} }).Configure(app =>
} {
static bool IsProgramRunning(string programName) // 设置静态文件目录
var pathToFiles = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
app.UseStaticFiles(new StaticFileOptions
{ {
Process[] processes = Process.GetProcesses(); FileProvider = new PhysicalFileProvider(pathToFiles),
foreach (Process process in processes) RequestPath = "/wwwroot"
});
// 处理文件未找到的情况
app.Use((context, next) =>
{ {
if (process.ProcessName.Equals(programName)) context.Response.StatusCode = 404;
return context.Response.WriteAsync("File not found");
});
}).Build().Run();
});
//启动Tcp服务
Task.Run(() =>
{ {
return true; TcpServer.Start();
} });
while (true)
{
Task.Delay(2000).Wait();
} }
return false;
} }
} }
} }

Loading…
Cancel
Save