diff --git a/DevicesService/App.config b/DevicesService/App.config
index 05b125f..53cfc32 100644
--- a/DevicesService/App.config
+++ b/DevicesService/App.config
@@ -6,5 +6,8 @@
+
+
+
\ No newline at end of file
diff --git a/DevicesService/Commen/Log.cs b/DevicesService/Commen/Log.cs
index 83cf805..7b4e541 100644
--- a/DevicesService/Commen/Log.cs
+++ b/DevicesService/Commen/Log.cs
@@ -39,8 +39,10 @@ namespace DevicesService.Commen
if (streamWriter != null)
{
streamWriter.Flush();
- streamWriter.Dispose();
- streamWriter = null;
+ if (streamWriter != null) {
+ streamWriter.Dispose();
+ streamWriter = null;
+ }
}
}
}
@@ -73,8 +75,11 @@ namespace DevicesService.Commen
if (streamWriter != null)
{
streamWriter.Flush();
- streamWriter.Dispose();
- streamWriter = null;
+ if (streamWriter != null)
+ {
+ streamWriter.Dispose();
+ streamWriter = null;
+ }
}
}
}
diff --git a/DevicesService/Commen/ScriptCallbackObject.cs b/DevicesService/Commen/ScriptCallbackObject.cs
index 75b6b66..5aeafb8 100644
--- a/DevicesService/Commen/ScriptCallbackObject.cs
+++ b/DevicesService/Commen/ScriptCallbackObject.cs
@@ -27,6 +27,7 @@ using DevicesService.Commen;
using System.Numerics;
using System.Web;
using NAudio.Wave.SampleProviders;
+using System.Configuration;
namespace DevicesService.Common
{
@@ -489,15 +490,9 @@ namespace DevicesService.Common
//结束录音上传文件
if (!string.IsNullOrEmpty(url) && !isopen)
{
- //Task.Run(async () =>
- //{
- // UploadInfo(url);
- //});
- //@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 + "\"}";
+ string filename = Path.GetFileName(srpath);
+ string path = ConfigurationManager.AppSettings["rootPath"].ToString();
+ return path + "Record/" + filename;
}
else if (isopen)//开始录音
{
@@ -732,7 +727,7 @@ namespace DevicesService.Common
// 创建WaveFileWriter对象来保存录音数据 路径在bin文件下
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;
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]);
//16bit 将两个byte数据组合成一个short数据
short sample = (short)((e.Buffer[i * bitIndex + 1] << 8) | e.Buffer[i * bitIndex]);
- mStreamWriter.Write("{0},", sample);
+ //mStreamWriter.Write("{0},", sample);
}
};
try
@@ -769,7 +764,7 @@ namespace DevicesService.Common
waveIn.StopRecording();
waveIn.Dispose();
writer.Close();
- mStreamWriter.Close();
+ //mStreamWriter.Close();
waveIn = null;
}
catch (Exception ex)
diff --git a/DevicesService/Commen/TcpServer.cs b/DevicesService/Commen/TcpServer.cs
index 776d14e..eaa4b52 100644
--- a/DevicesService/Commen/TcpServer.cs
+++ b/DevicesService/Commen/TcpServer.cs
@@ -7,6 +7,15 @@ using System.Text;
using System.Threading;
using System.Linq;
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
{
///
@@ -14,8 +23,429 @@ namespace DevicesService.Commen
///
public class TcpServer
{
+ public static List clients = new List();
+ 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 { }
+ }
- }
+ ///
+ /// 发送数据
+ ///
+ ///
+ ///
+ 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 { }
+ }
+
+ ///
+ /// 发送一个Hello的方法
+ ///
+ ///
+ 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;
+ }
+ }
+ }
+
+ ///
+ /// 读取客户端信息
+ ///
+ ///
+ 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 { }
+ }
+ }
+
+ ///
+ /// 解析包头里面有多少字节
+ ///
+ ///
+ ///
+ 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 { }
+ }
+
+ ///
+ /// 等待流全部获取到,然后丢出去
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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 { }
+ }
+ }
}
diff --git a/DevicesService/Commen/Util.cs b/DevicesService/Commen/Util.cs
index 5b78f6f..0f9c731 100644
--- a/DevicesService/Commen/Util.cs
+++ b/DevicesService/Commen/Util.cs
@@ -397,5 +397,17 @@ namespace DevicesService.Common
return result;
}
}
+
+ ///
+ /// 文件转base64
+ ///
+ ///
+ ///
+ public static string FileToBase64(string filePath)
+ {
+ byte[] fileBytes = File.ReadAllBytes(filePath);
+ string base64String = Convert.ToBase64String(fileBytes);
+ return base64String;
+ }
}
}
diff --git a/DevicesService/Devices/SignDll.cs b/DevicesService/Devices/SignDll.cs
index 81b7d7a..04d012b 100644
--- a/DevicesService/Devices/SignDll.cs
+++ b/DevicesService/Devices/SignDll.cs
@@ -1,15 +1,11 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
+using Functions.FileExt;
+using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
+using System;
using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Runtime.InteropServices;
using System.Globalization;
-using Functions.FileExt;
using System.IO;
+using System.Runtime.InteropServices;
+using System.Text;
//0816加实时报点
[StructLayout(LayoutKind.Sequential)]
public struct TOUCH_INFO
@@ -25,18 +21,17 @@ namespace DevicesService.Devices
public class SignDll
{
public static PointF endPos;
- public static int status = -1;
public static PointF beginPos;
public static PointF frontPos;
- private static int xypointcount;
+ private static int xypointcount = 0;
private static int[] lastpointx = new int[3];
private static int[] lastpointy = new int[3];
Point mPoint = new Point(-1, -1);
- private System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
- private Bitmap bitmap = new Bitmap(594, 392);
- private static Graphics g;
- private static Pen pen = new Pen(Color.Red);
-
+ private static System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
+ //private Graphics mGraphicsBuffer;
+ private static Pen pen = new Pen(Color.Black); //
+ public static int status = -1;
+ private static Bitmap bitmap = new Bitmap(594, 392);
public SignDll()
{
endPos = new PointF(-1F, -1f);
@@ -49,143 +44,35 @@ namespace DevicesService.Devices
lastpointx[2] = -1;
lastpointy[2] = -1;
xypointcount = 0;
- g = Graphics.FromImage(bitmap);
-
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
}
public static void GetTouchNumber(int number)
{
- if (number == 1)
- {
- int ret = FiveInchDll.ComSignOK();
- }
- else
- {
- 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++)
+ try
{
- x = info1[k].X;
- y = info1[k].Y;
- if (info1[k].Pressure > 0)
+ //1 签字确定按钮 2签字取消按钮 3 签字重签按钮(清空界面)
+ if (number == 1)
{
- if (info1[k].Pressure > 0 && info1[k].Pressure < 500)
- {
- pressurevl = 1;
- pen.Width = 1;
- }
- else if (info1[k].Pressure >= 500 && info1[k].Pressure < 1000)
- {
- pressurevl = 2;
- pen.Width = 2;
- }
- 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;
- }
+ int ret = FiveInchDll.ComSignOK();
+ Console.WriteLine("ComSignOK:" + ret);
+ FiveInchDll.ComSetBackGroundAdv();
}
- else
+ else if (number == 3)
{
- pressurevl = 0;
- lastpointx[0] = -1;
- lastpointy[0] = -1;
- lastpointx[1] = -1;
- lastpointy[1] = -1;
- lastpointx[2] = -1;
- lastpointy[2] = -1;
- continue;
+ string UIFile = System.IO.Directory.GetCurrentDirectory() + "\\sign_ui.jpg";
+ int ret = FiveInchDll.ComSetSignBackgroundImage(UIFile);
+ Console.WriteLine("ComSetSignBackgroundImage:" + ret);
}
- if (info1[k].Pressure > 10) //有画线宽度
+ //2023-02-27 通知返回获取SN
+ else if (number == 17) //返回设备SN
{
- 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]);
- 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];
- lastpointy[1] = lastpointy[2];
- }
- }
+ StringBuilder sbDevSN = new StringBuilder();
+ FiveInchDll.ComGetDevSN_Async(sbDevSN);
+ Console.WriteLine("ComGetDevSN:" + sbDevSN);
}
else
{
- dx = dy = 0;
lastpointx[0] = -1;
lastpointy[0] = -1;
lastpointx[1] = -1;
@@ -193,19 +80,41 @@ namespace DevicesService.Devices
lastpointx[2] = -1;
lastpointy[2] = -1;
+ FiveInchDll.ComSetBackGroundAdv();
}
}
+ catch { }
+ finally { }
}
+ //0816加报点
+ public static void GetTouchPoint(TOUCH_INFO[] info1)
+ { }
+
//打开签字版
public static int OpenComDevice()
{
- if (status == -1)
+ int status = FiveInchDll.OpenComDevice(GetTouchNumber);
+ Console.WriteLine("OpenComDevice:" + status);
+ if (status == 0)
{
- status = FiveInchDll.OpenComDevice(GetTouchNumber);
- if (status != 0)
+ //2022-08-16 加实时报点
+ 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;
@@ -282,5 +191,26 @@ namespace DevicesService.Devices
[DllImport("XTJZFiveInch.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
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();
}
}
diff --git a/DevicesService/DevicesService.csproj b/DevicesService/DevicesService.csproj
index fee06d9..6360e4a 100644
--- a/DevicesService/DevicesService.csproj
+++ b/DevicesService/DevicesService.csproj
@@ -1,14 +1,13 @@
- WinExe
+ Exe
net6.0
favicon.ico
9.0
DevicesService
AnyCPU;x86
- x86
@@ -33,6 +32,10 @@
+
+
+
+
diff --git a/DevicesService/Program.cs b/DevicesService/Program.cs
index cbe2190..b1dd2c9 100644
--- a/DevicesService/Program.cs
+++ b/DevicesService/Program.cs
@@ -1,11 +1,14 @@
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.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Threading;
+using System.IO;
using System.Threading.Tasks;
-
namespace DevicesService
{
internal class Program
@@ -17,24 +20,38 @@ namespace DevicesService
static void Main(string[] args)
{
// 更改为你想检查的进程名称
- new COMUtils();
+ //new COMUtils();
+ //启动静态服务器
+ Task.Run(() =>
+ {
+ WebHost.CreateDefaultBuilder().UseUrls("http://0.0.0.0:5000").ConfigureServices(services => {
+ }).Configure(app =>
+ {
+ // 设置静态文件目录
+ var pathToFiles = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
+ app.UseStaticFiles(new StaticFileOptions
+ {
+ FileProvider = new PhysicalFileProvider(pathToFiles),
+ RequestPath = "/wwwroot"
+ });
+
+ // 处理文件未找到的情况
+ app.Use((context, next) =>
+ {
+ context.Response.StatusCode = 404;
+ return context.Response.WriteAsync("File not found");
+ });
+ }).Build().Run();
+ });
+ //启动Tcp服务
+ Task.Run(() =>
+ {
+ TcpServer.Start();
+ });
while (true)
{
Task.Delay(2000).Wait();
}
}
- static bool IsProgramRunning(string programName)
- {
- Process[] processes = Process.GetProcesses();
- foreach (Process process in processes)
- {
- if (process.ProcessName.Equals(programName))
- {
- return true;
- }
- }
- return false;
- }
-
}
}