瀏覽代碼

Merge remote-tracking branch 'origin/zyy' into zhangxueyang

# Conflicts:
#	XHWK.WKTool/App.cs
tags/录制修改前
zhangxueyang 4 年之前
父節點
當前提交
1fa1a53d63

二進制
Common/dlls/TStudy.DigitalPen.dll 查看文件


二進制
Common/dlls/TStudyDigitalPen.dll 查看文件


二進制
Common/dlls/TStudyDigitalPenInter.dll 查看文件


二進制
Common/dlls/TStudyDigitalPenLic.dll 查看文件


+ 15
- 0
XHWK.WKTool/App.cs 查看文件

@@ -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
@@ -86,6 +88,19 @@ namespace XHWK.WKTool
86 88
         /// 页码IP
87 89
         /// </summary>
88 90
         public static string[] OutPut = new string[] { }; 
91
+
92
+        /// <summary>
93
+        /// 点阵笔
94
+        /// </summary>
95
+        public static DigitalPenHID digitalPen;
96
+        /// <summary>
97
+        /// 笔序号
98
+        /// </summary>
99
+        public static string PenSerial;
100
+        /// <summary>
101
+        /// 笔状态,是否已连接
102
+        /// </summary>
103
+        public static bool PenStatus;
89 104
         #endregion
90 105
 
91 106
         [STAThread]

+ 15
- 0
XHWK.WKTool/MyLicense.cs
文件差異過大導致無法顯示
查看文件


+ 315
- 0
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs 查看文件

@@ -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
         /// 初始化
@@ -1339,5 +1342,317 @@ namespace XHWK.WKTool
1339 1342
             //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
1340 1343
         }
1341 1344
         #endregion
1345
+
1346
+        #region 点阵笔相关
1347
+
1348
+        #region 值初始化
1349
+        // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
1350
+
1351
+        /// <summary>
1352
+        /// A4点阵纸点阵宽度
1353
+        /// </summary>
1354
+        private const int A4_WIDTH = 5600;
1355
+
1356
+        /// <summary>
1357
+        /// A4点阵纸点阵高度
1358
+        /// </summary>
1359
+        private const int A4_HEIGHT = 7920;
1360
+
1361
+        /// <summary>
1362
+        /// 画板
1363
+        /// </summary>
1364
+        private Graphics graphics;
1365
+
1366
+        /// <summary>
1367
+        /// 笔画坐标数组
1368
+        /// </summary>
1369
+        private List<System.Drawing.Point> stroke;
1370
+
1371
+        /// <summary>
1372
+        /// 笔序列号
1373
+        /// </summary>
1374
+        private string penSerial;
1375
+
1376
+        /// <summary>
1377
+        /// 笔是否在点
1378
+        /// </summary>
1379
+        private bool isPenDown;
1380
+
1381
+        //当前点阵地址
1382
+        private string currentPageSerial = string.Empty;
1383
+
1384
+        //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
1385
+        //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
1386
+        private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
1387
+        #endregion
1388
+        public void InitPen()
1389
+        {
1390
+            stroke = new List<System.Drawing.Point>();
1391
+            //获取点阵笔实例,并绑定点阵笔事件
1392
+            //将授权文件内容传入,获取点阵笔对象实例
1393
+            APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
1394
+            //绑定笔连接事件
1395
+            APP.digitalPen.PenConnected += OnPenConnect;
1396
+            //绑定笔断开事件
1397
+            APP.digitalPen.PenDisconnect += OnPenDisconnect;
1398
+            //绑定笔书写输出坐标事件
1399
+            APP.digitalPen.PenCoordinate += OnPenCoordinate;
1400
+            //绑定抬笔事件
1401
+            APP.digitalPen.PenUp += OnPenUp;
1402
+            //绑定落笔事件
1403
+            APP.digitalPen.PenDown += OnPenDown;
1404
+            APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
1405
+            APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
1406
+            //完成初始化点阵笔,开始与点阵笔通信
1407
+            ERROR_CODE ER = APP.digitalPen.Start();
1408
+
1409
+            ////绑定笔在新的点阵地址页面书写事件
1410
+            //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
1411
+            ////绑定笔信息事件
1412
+            //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
1413
+            //启动接收笔数据,完成初始化工作
1414
+            ERROR_CODE rc = APP.digitalPen.Start();
1415
+            //判断是否成功
1416
+            if (ER != ERROR_CODE.ERROR_OK)
1417
+            {
1418
+                System.Windows.MessageBox.Show("初始化失败,授权过期,返回值:" + ER.ToString());
1419
+            }
1420
+        }
1421
+
1422
+
1423
+        /// <summary>
1424
+        /// 落笔
1425
+        /// </summary>
1426
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
1427
+        /// <param name="penSerial">点阵笔序列号</param>
1428
+        /// <param name="penType">点阵笔型号编号</param>
1429
+        private void OnPenDown(ulong time, string penSerial, int penType)
1430
+        {
1431
+            if (this.CheckAccess())
1432
+            {
1433
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
1434
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
1435
+            }
1436
+            else
1437
+            {
1438
+                //labPenSerial.Text = penSerial;
1439
+                //labPenStatus.Text = "PenDown";
1440
+                isPenDown = true;
1441
+            }
1442
+        }
1443
+
1444
+        /// <summary>
1445
+        /// 抬笔
1446
+        /// </summary>
1447
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
1448
+        /// <param name="penSerial">点阵笔序列号</param>
1449
+        /// <param name="penType">点阵笔型号编号</param>
1450
+        private void OnPenUp(ulong time, string penSerial, int penType)
1451
+        {
1452
+            if (this.CheckAccess())
1453
+            {
1454
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
1455
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
1456
+            }
1457
+            else
1458
+            {
1459
+                isPenDown = false;
1460
+                APP.PenSerial = penSerial;
1461
+                //int leftPoints = stroke.Count % 3;
1462
+                //if (0 != leftPoints)
1463
+                //{
1464
+                //    int from = stroke.Count - leftPoints - 1;
1465
+                //    if (from < 0)
1466
+                //        from = 0;
1467
+                //    int to = stroke.Count - 1;
1468
+                //    DrawCoordinates(from, to);
1469
+                //}
1470
+                stroke.Clear();
1471
+            }
1472
+        }
1473
+
1474
+        /// <summary>
1475
+        /// 笔断开
1476
+        /// </summary>
1477
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
1478
+        /// <param name="penSerial">点阵笔序列号</param>
1479
+        /// <param name="penType">点阵笔型号编号</param>
1480
+        private void OnPenDisconnect(ulong time, string penSerial, int penType)
1481
+        {
1482
+            if (this.CheckAccess())
1483
+            {
1484
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
1485
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
1486
+            }
1487
+            else
1488
+            {
1489
+                APP.PenSerial = penSerial;
1490
+                APP.PenStatus = false;
1491
+            }
1492
+        }
1493
+
1494
+        /// <summary>
1495
+        /// 笔连接
1496
+        /// </summary>
1497
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
1498
+        /// <param name="penSerial">点阵笔序列号</param>
1499
+        /// <param name="penType">点阵笔型号编号</param>
1500
+        private void OnPenConnect(ulong time, string penSerial, int penType)
1501
+        {
1502
+            if (this.CheckAccess())
1503
+            {
1504
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
1505
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
1506
+            }
1507
+            else
1508
+            {
1509
+                APP.PenSerial = penSerial;
1510
+                APP.PenStatus = true;
1511
+                this.penSerial = penSerial;
1512
+                //连接后,在获取笔数据前,可以清除笔内的历史数据
1513
+                //APP.digitalPen.ClearMemory(penSerial);
1514
+
1515
+                //开始接收笔数据
1516
+                APP.digitalPen.GetPenData(penSerial);
1517
+            }
1518
+        }
1519
+        /// <summary>
1520
+        /// 电池电量
1521
+        /// </summary>
1522
+        /// <param name="time"></param>
1523
+        /// <param name="penSerial"></param>
1524
+        /// <param name="penType"></param>
1525
+        /// <param name="capacity"></param>
1526
+        private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
1527
+        {
1528
+            if (this.CheckAccess())
1529
+            {
1530
+                Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
1531
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
1532
+            }
1533
+            else
1534
+            {
1535
+                //System.Windows.MessageBox.Show("电池电量:" + capacity.ToString());
1536
+            }
1537
+        }
1538
+
1539
+        /// <summary>
1540
+        /// 已用存储
1541
+        /// </summary>
1542
+        /// <param name="time"></param>
1543
+        /// <param name="penSerial"></param>
1544
+        /// <param name="penType"></param>
1545
+        /// <param name="fillLevel"></param>
1546
+        private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
1547
+        {
1548
+            if (this.CheckAccess())
1549
+            {
1550
+                Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
1551
+                this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
1552
+            }
1553
+            else
1554
+            {
1555
+                //System.Windows.MessageBox.Show("存储:" + fillLevel.ToString());
1556
+            }
1557
+        }
1558
+
1559
+        /// <summary>
1560
+        /// 笔书写,收到坐标
1561
+        /// </summary>
1562
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
1563
+        /// <param name="penSerial">点阵笔序列号</param>
1564
+        /// <param name="penType">点阵笔型号编号</param>
1565
+        /// <param name="pageSerial">点阵地址</param>
1566
+        /// <param name="cx">x坐标</param>
1567
+        /// <param name="cy">y坐标</param>
1568
+        /// <param name="force">压力值</param>
1569
+        private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
1570
+        {
1571
+            if (this.CheckAccess())
1572
+            {
1573
+                Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
1574
+                this.Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
1575
+            }
1576
+            else
1577
+            {
1578
+                //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
1579
+                if (!isPenDown)
1580
+                {
1581
+                    return;
1582
+                }
1583
+                stroke.Add(new System.Drawing.Point(cx, cy));
1584
+
1585
+                double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
1586
+                double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
1587
+                //点
1588
+                double testX=(double)cx * PropW;
1589
+                double testY=(double)cy * PropH;
1590
+                //pageSerial //点阵IP地址  与打印的页面关联
1591
+
1592
+
1593
+                ////每3个点画一条曲线
1594
+                //if (stroke.Count % 3 == 0)
1595
+                //{
1596
+                //    int from = stroke.Count - 3 - 1;
1597
+                //    if (from < 0)
1598
+                //        from = 0;
1599
+                //    int to = stroke.Count - 1;
1600
+                //    DrawCoordinates(from, to);
1601
+                //}
1602
+            }
1603
+        }
1604
+
1605
+        /// <summary>
1606
+        /// 停止笔
1607
+        /// </summary>
1608
+        public void StopDigitalPen()
1609
+        {
1610
+            //停止,释放资源
1611
+            APP.digitalPen.Stop();
1612
+        }
1613
+        /// <summary>
1614
+        /// 清空笔内存储
1615
+        /// </summary>
1616
+        public void ClearPenStorage()
1617
+        {
1618
+            if (!string.IsNullOrEmpty(penSerial))
1619
+                APP.digitalPen.ClearMemory(penSerial);
1620
+        }
1621
+        /// <summary>
1622
+        /// 获取剩余电量
1623
+        /// </summary>
1624
+        public void GetPenElectricityQuantity()
1625
+        {
1626
+            if (!string.IsNullOrEmpty(penSerial))
1627
+                APP.digitalPen.GetBatteryCapacity(penSerial);
1628
+        }
1629
+
1630
+        /// <summary>
1631
+        /// 获取存储空间
1632
+        /// </summary>
1633
+        public void GetUsedStorage()
1634
+        {
1635
+            if (!string.IsNullOrEmpty(penSerial))
1636
+                APP.digitalPen.GetMemoryFillLevel(penSerial);
1637
+        }
1638
+
1639
+        /// <summary>
1640
+        /// 开启悬浮
1641
+        /// </summary>
1642
+        public void 开启悬浮()
1643
+        {
1644
+            if (!string.IsNullOrEmpty(penSerial))
1645
+                APP.digitalPen.SetPenHoverMode(true, penSerial);
1646
+        }
1647
+
1648
+        /// <summary>
1649
+        /// 关闭悬浮
1650
+        /// </summary>
1651
+        public void 关闭悬浮()
1652
+        {
1653
+            if (!string.IsNullOrEmpty(penSerial))
1654
+                APP.digitalPen.SetPenHoverMode(false, penSerial);
1655
+        }
1656
+        #endregion
1342 1657
     }
1343 1658
 }

+ 5
- 0
XHWK.WKTool/XHWK.WKTool.csproj 查看文件

@@ -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…
取消
儲存