Browse Source

zhao:点阵笔连接

tags/录制修改前
耀 4 years ago
parent
commit
8983f89413

BIN
Common/dlls/TStudy.DigitalPen.dll View File


BIN
Common/dlls/TStudyDigitalPen.dll View File


BIN
Common/dlls/TStudyDigitalPenInter.dll View File


BIN
Common/dlls/TStudyDigitalPenLic.dll View File


+ 16
- 0
XHWK.WKTool/App.cs View File

@@ -9,6 +9,8 @@ using System.Threading;
9 9
 using System.Windows;
10 10
 using System.Windows.Threading;
11 11
 
12
+using TStudyDigitalPen.HID;
13
+
12 14
 using XHWK.Model;
13 15
 
14 16
 namespace XHWK.WKTool
@@ -82,6 +84,20 @@ namespace XHWK.WKTool
82 84
         /// </summary>
83 85
         public static string[] JPaths = new string[999];
84 86
         public static string ImgPath = string.Empty;
87
+
88
+        /// <summary>
89
+        /// 点阵笔
90
+        /// </summary>
91
+        public static DigitalPenHID digitalPen;
92
+        /// <summary>
93
+        /// 笔序号
94
+        /// </summary>
95
+        public static string PenSerial;
96
+        /// <summary>
97
+        /// 笔状态,是否已连接
98
+        /// </summary>
99
+        public static bool PenStatus;
100
+                //labPenStatus
85 101
         #endregion
86 102
 
87 103
         [STAThread]

+ 15
- 0
XHWK.WKTool/MyLicense.cs
File diff suppressed because it is too large
View File


+ 315
- 0
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs View File

@@ -17,6 +17,8 @@ using System.Windows.Controls;
17 17
 using ComeCapture;
18 18
 using Aspose.Slides;
19 19
 using static Common.system.PdfTrunImage;
20
+using TStudyDigitalPen.HID;
21
+using System.Drawing;
20 22
 
21 23
 namespace XHWK.WKTool
22 24
 {
@@ -73,6 +75,7 @@ namespace XHWK.WKTool
73 75
             }
74 76
             txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoSavePath");
75 77
             Initialize();
78
+            InitPen();
76 79
         }
77 80
         /// <summary>
78 81
         /// 初始化
@@ -1272,5 +1275,317 @@ namespace XHWK.WKTool
1272 1275
             //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
1273 1276
         }
1274 1277
         #endregion
1278
+
1279
+        #region 点阵笔相关
1280
+
1281
+        #region 值初始化
1282
+        // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
1283
+
1284
+        /// <summary>
1285
+        /// A4点阵纸点阵宽度
1286
+        /// </summary>
1287
+        private const int A4_WIDTH = 5600;
1288
+
1289
+        /// <summary>
1290
+        /// A4点阵纸点阵高度
1291
+        /// </summary>
1292
+        private const int A4_HEIGHT = 7920;
1293
+
1294
+        /// <summary>
1295
+        /// 画板
1296
+        /// </summary>
1297
+        private Graphics graphics;
1298
+
1299
+        /// <summary>
1300
+        /// 笔画坐标数组
1301
+        /// </summary>
1302
+        private List<System.Drawing.Point> stroke;
1303
+
1304
+        /// <summary>
1305
+        /// 笔序列号
1306
+        /// </summary>
1307
+        private string penSerial;
1308
+
1309
+        /// <summary>
1310
+        /// 笔是否在点
1311
+        /// </summary>
1312
+        private bool isPenDown;
1313
+
1314
+        //当前点阵地址
1315
+        private string currentPageSerial = string.Empty;
1316
+
1317
+        //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
1318
+        //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
1319
+        private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
1320
+        #endregion
1321
+        public void InitPen()
1322
+        {
1323
+            stroke = new List<System.Drawing.Point>();
1324
+            //获取点阵笔实例,并绑定点阵笔事件
1325
+            //将授权文件内容传入,获取点阵笔对象实例
1326
+            APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
1327
+            //绑定笔连接事件
1328
+            APP.digitalPen.PenConnected += OnPenConnect;
1329
+            //绑定笔断开事件
1330
+            APP.digitalPen.PenDisconnect += OnPenDisconnect;
1331
+            //绑定笔书写输出坐标事件
1332
+            APP.digitalPen.PenCoordinate += OnPenCoordinate;
1333
+            //绑定抬笔事件
1334
+            APP.digitalPen.PenUp += OnPenUp;
1335
+            //绑定落笔事件
1336
+            APP.digitalPen.PenDown += OnPenDown;
1337
+            APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
1338
+            APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
1339
+            //完成初始化点阵笔,开始与点阵笔通信
1340
+            ERROR_CODE ER = APP.digitalPen.Start();
1341
+
1342
+            ////绑定笔在新的点阵地址页面书写事件
1343
+            //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
1344
+            ////绑定笔信息事件
1345
+            //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
1346
+            //启动接收笔数据,完成初始化工作
1347
+            ERROR_CODE rc = APP.digitalPen.Start();
1348
+            //判断是否成功
1349
+            if (ER != ERROR_CODE.ERROR_OK)
1350
+            {
1351
+                System.Windows.MessageBox.Show("初始化失败,授权过期,返回值:" + ER.ToString());
1352
+            }
1353
+        }
1354
+
1355
+
1356
+        /// <summary>
1357
+        /// 落笔
1358
+        /// </summary>
1359
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
1360
+        /// <param name="penSerial">点阵笔序列号</param>
1361
+        /// <param name="penType">点阵笔型号编号</param>
1362
+        private void OnPenDown(ulong time, string penSerial, int penType)
1363
+        {
1364
+            if (this.CheckAccess())
1365
+            {
1366
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
1367
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
1368
+            }
1369
+            else
1370
+            {
1371
+                //labPenSerial.Text = penSerial;
1372
+                //labPenStatus.Text = "PenDown";
1373
+                isPenDown = true;
1374
+            }
1375
+        }
1376
+
1377
+        /// <summary>
1378
+        /// 抬笔
1379
+        /// </summary>
1380
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
1381
+        /// <param name="penSerial">点阵笔序列号</param>
1382
+        /// <param name="penType">点阵笔型号编号</param>
1383
+        private void OnPenUp(ulong time, string penSerial, int penType)
1384
+        {
1385
+            if (this.CheckAccess())
1386
+            {
1387
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
1388
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
1389
+            }
1390
+            else
1391
+            {
1392
+                isPenDown = false;
1393
+                APP.PenSerial = penSerial;
1394
+                //int leftPoints = stroke.Count % 3;
1395
+                //if (0 != leftPoints)
1396
+                //{
1397
+                //    int from = stroke.Count - leftPoints - 1;
1398
+                //    if (from < 0)
1399
+                //        from = 0;
1400
+                //    int to = stroke.Count - 1;
1401
+                //    DrawCoordinates(from, to);
1402
+                //}
1403
+                stroke.Clear();
1404
+            }
1405
+        }
1406
+
1407
+        /// <summary>
1408
+        /// 笔断开
1409
+        /// </summary>
1410
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
1411
+        /// <param name="penSerial">点阵笔序列号</param>
1412
+        /// <param name="penType">点阵笔型号编号</param>
1413
+        private void OnPenDisconnect(ulong time, string penSerial, int penType)
1414
+        {
1415
+            if (this.CheckAccess())
1416
+            {
1417
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
1418
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
1419
+            }
1420
+            else
1421
+            {
1422
+                APP.PenSerial = penSerial;
1423
+                APP.PenStatus = false;
1424
+            }
1425
+        }
1426
+
1427
+        /// <summary>
1428
+        /// 笔连接
1429
+        /// </summary>
1430
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
1431
+        /// <param name="penSerial">点阵笔序列号</param>
1432
+        /// <param name="penType">点阵笔型号编号</param>
1433
+        private void OnPenConnect(ulong time, string penSerial, int penType)
1434
+        {
1435
+            if (this.CheckAccess())
1436
+            {
1437
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
1438
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
1439
+            }
1440
+            else
1441
+            {
1442
+                APP.PenSerial = penSerial;
1443
+                APP.PenStatus = true;
1444
+                this.penSerial = penSerial;
1445
+                //连接后,在获取笔数据前,可以清除笔内的历史数据
1446
+                //APP.digitalPen.ClearMemory(penSerial);
1447
+
1448
+                //开始接收笔数据
1449
+                APP.digitalPen.GetPenData(penSerial);
1450
+            }
1451
+        }
1452
+        /// <summary>
1453
+        /// 电池电量
1454
+        /// </summary>
1455
+        /// <param name="time"></param>
1456
+        /// <param name="penSerial"></param>
1457
+        /// <param name="penType"></param>
1458
+        /// <param name="capacity"></param>
1459
+        private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
1460
+        {
1461
+            if (this.CheckAccess())
1462
+            {
1463
+                Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
1464
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
1465
+            }
1466
+            else
1467
+            {
1468
+                //System.Windows.MessageBox.Show("电池电量:" + capacity.ToString());
1469
+            }
1470
+        }
1471
+
1472
+        /// <summary>
1473
+        /// 已用存储
1474
+        /// </summary>
1475
+        /// <param name="time"></param>
1476
+        /// <param name="penSerial"></param>
1477
+        /// <param name="penType"></param>
1478
+        /// <param name="fillLevel"></param>
1479
+        private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
1480
+        {
1481
+            if (this.CheckAccess())
1482
+            {
1483
+                Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
1484
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
1485
+            }
1486
+            else
1487
+            {
1488
+                //System.Windows.MessageBox.Show("存储:" + fillLevel.ToString());
1489
+            }
1490
+        }
1491
+
1492
+        /// <summary>
1493
+        /// 笔书写,收到坐标
1494
+        /// </summary>
1495
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
1496
+        /// <param name="penSerial">点阵笔序列号</param>
1497
+        /// <param name="penType">点阵笔型号编号</param>
1498
+        /// <param name="pageSerial">点阵地址</param>
1499
+        /// <param name="cx">x坐标</param>
1500
+        /// <param name="cy">y坐标</param>
1501
+        /// <param name="force">压力值</param>
1502
+        private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
1503
+        {
1504
+            if (this.CheckAccess())
1505
+            {
1506
+                Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
1507
+                this.Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
1508
+            }
1509
+            else
1510
+            {
1511
+                //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
1512
+                if (!isPenDown)
1513
+                {
1514
+                    return;
1515
+                }
1516
+                stroke.Add(new System.Drawing.Point(cx, cy));
1517
+
1518
+                double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
1519
+                double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
1520
+                //点
1521
+                double testX=(double)cx * PropW;
1522
+                double testY=(double)cy * PropH;
1523
+                //pageSerial //点阵IP地址  与打印的页面关联
1524
+
1525
+
1526
+                ////每3个点画一条曲线
1527
+                //if (stroke.Count % 3 == 0)
1528
+                //{
1529
+                //    int from = stroke.Count - 3 - 1;
1530
+                //    if (from < 0)
1531
+                //        from = 0;
1532
+                //    int to = stroke.Count - 1;
1533
+                //    DrawCoordinates(from, to);
1534
+                //}
1535
+            }
1536
+        }
1537
+
1538
+        /// <summary>
1539
+        /// 停止笔
1540
+        /// </summary>
1541
+        public void StopDigitalPen()
1542
+        {
1543
+            //停止,释放资源
1544
+            APP.digitalPen.Stop();
1545
+        }
1546
+        /// <summary>
1547
+        /// 清空笔内存储
1548
+        /// </summary>
1549
+        public void ClearPenStorage()
1550
+        {
1551
+            if (!string.IsNullOrEmpty(penSerial))
1552
+                APP.digitalPen.ClearMemory(penSerial);
1553
+        }
1554
+        /// <summary>
1555
+        /// 获取剩余电量
1556
+        /// </summary>
1557
+        public void GetPenElectricityQuantity()
1558
+        {
1559
+            if (!string.IsNullOrEmpty(penSerial))
1560
+                APP.digitalPen.GetBatteryCapacity(penSerial);
1561
+        }
1562
+
1563
+        /// <summary>
1564
+        /// 获取存储空间
1565
+        /// </summary>
1566
+        public void GetUsedStorage()
1567
+        {
1568
+            if (!string.IsNullOrEmpty(penSerial))
1569
+                APP.digitalPen.GetMemoryFillLevel(penSerial);
1570
+        }
1571
+
1572
+        /// <summary>
1573
+        /// 开启悬浮
1574
+        /// </summary>
1575
+        public void 开启悬浮()
1576
+        {
1577
+            if (!string.IsNullOrEmpty(penSerial))
1578
+                APP.digitalPen.SetPenHoverMode(true, penSerial);
1579
+        }
1580
+
1581
+        /// <summary>
1582
+        /// 关闭悬浮
1583
+        /// </summary>
1584
+        public void 关闭悬浮()
1585
+        {
1586
+            if (!string.IsNullOrEmpty(penSerial))
1587
+                APP.digitalPen.SetPenHoverMode(false, penSerial);
1588
+        }
1589
+        #endregion
1275 1590
     }
1276 1591
 }

+ 5
- 0
XHWK.WKTool/XHWK.WKTool.csproj View File

@@ -82,6 +82,10 @@
82 82
     <Reference Include="System.Xaml">
83 83
       <RequiredTargetFramework>4.0</RequiredTargetFramework>
84 84
     </Reference>
85
+    <Reference Include="TStudy.DigitalPen, Version=3.0.0.0, Culture=neutral, processorArchitecture=x86">
86
+      <SpecificVersion>False</SpecificVersion>
87
+      <HintPath>..\Common\dlls\TStudy.DigitalPen.dll</HintPath>
88
+    </Reference>
85 89
     <Reference Include="WindowsBase" />
86 90
     <Reference Include="PresentationCore" />
87 91
     <Reference Include="PresentationFramework" />
@@ -127,6 +131,7 @@
127 131
     <Compile Include="Models\EntityBase.cs" />
128 132
     <Compile Include="Models\Limit.cs" />
129 133
     <Compile Include="Models\Tool.cs" />
134
+    <Compile Include="MyLicense.cs" />
130 135
     <Compile Include="PracticeWindow.xaml.cs">
131 136
       <DependentUpon>PracticeWindow.xaml</DependentUpon>
132 137
     </Compile>

Loading…
Cancel
Save