T1Machine.partial.cs 41.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static Asa.eyemLib;
using static DeviceLibrary.eyemlib;

namespace DeviceLibrary
{
    using crc = OnlineStore.CodeResourceControl;
    partial class T1Machine
    {
        public IO_VALUE End_Line_Tray_Check { get => IOValue(IO_T1_Type.End_Line_Tray_Check); }
        public bool TrayCanIN()
        {
            return IOValue(IO_T1_Type.End_Line_Tray_Check).Equals(IO_VALUE.LOW) && IOValue(IO_T1_Type.End_Lift_Cylinder_Down).Equals(IO_VALUE.HIGH)
                && (MoveInfo.MoveStep== MoveStep.T1_01_WaitReel || MoveInfo.MoveStep >= MoveStep.T1_07_PanToOut);
        }
        public void LineRun(int sec = 0)
        {
            IOMove(IO_T1_Type.Line4_Run, IO_VALUE.HIGH, false, sec);
        }
        void WorkProcess()
        {
            if (CheckWait(MoveInfo))
                return;

            switch (MoveInfo.MoveStep)
            {
                case MoveStep.T1_01_WaitReel:
                    if (IOValue(IO_T1_Type.End_Line_Tray_Check,IO_VALUE.HIGH) && preReelParam != null)
                    {
                        MoveInfo.ReelParam = preReelParam;
                        preReelParam = null;
                        MoveInfo.log("检测到料盘 ReelParam:" + MoveInfo.ReelParam.ToStr());
                        MoveInfo.NextMoveStep(MoveStep.T1_02_WaitReelInpos);
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
                        MoveInfo.StopwatchReset();
                    }
                    else
                    {
                        Msg.add(crc.GetString("wait_reel_entry", "{0}等待料盘进入", DeviceName), MsgLevel.info);
                    }
                    break;
                case MoveStep.T1_02_WaitReelInpos:
                    MoveInfo.NextMoveStep(MoveStep.T1_03_LocationUp);
                    LocationString();
                    //IOMove(IO_T1_Type.Line4_Run, IO_VALUE.LOW);
                    MoveInfo.log($"将料盘推到位 width:{MoveInfo.ReelParam.PlateW},POS:{Config.GetTrayPos(MoveInfo.ReelParam.PlateW)}位置");
                    T_TrayPos_Axis.AbsMove(MoveInfo, Config.GetTrayPos(MoveInfo.ReelParam.PlateW), Config.TrayPos_P1_speed);
                    T_Pan_Axis.AbsMove(MoveInfo, Config.Pan_P1, Config.Pan_P1_speed);
                    T_Y_Axis.AbsMove(MoveInfo, Config.Y_P1, Config.Y_P1_speed);
                    
                    //MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    break;
                case MoveStep.T1_03_LocationUp:
                    if (RobotManage.electricGripper.Release())
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_04_DownToReel);
                        MoveInfo.log($"料盘顶升");
                        IOMove(IO_T1_Type.Line4_Run, IO_VALUE.LOW);
                        CylinderMove(MoveInfo, IO_T1_Type.End_Lift_Cylinder_Down, IO_T1_Type.End_Lift_Cylinder_Up, IO_VALUE.HIGH);
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.End_Lift_Tray_Check, IO_VALUE.HIGH));
                    }
                    else
                    {
                        Msg.add("夹爪忙碌中...", MsgLevel.warning);
                        MoveInfo.log($"夹爪忙碌中...");
                    }
                    break;
                case MoveStep.T1_04_DownToReel:
                    MoveInfo.NextMoveStep(MoveStep.T1_05_ClampReel);
                    int pos = Config.UpdownAxis_P2 - (MoveInfo.ReelParam.PlateRawH - 8) * Config.UpdownAxis_ChangeValue;
                    MoveInfo.log($"升降轴下降到取料位置,配置位置:{Config.UpdownAxis_P2},计算位置:{pos}");
                    T_Updown_Axis.AbsMove(MoveInfo, pos, Config.UpdownAxis_P2_speed);
                    T_TrayPos_Axis.AbsMove(null, Config.TrayPos_P1, Config.TrayPos_P1_speed);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    break;
                case MoveStep.T1_05_ClampReel:
                    if (RobotManage.electricGripper.Clamp(null))
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_06_UpToTop);
                        //RobotManage.electricGripper.Clamp(null);
                        MoveInfo.log($"夹爪张开");
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1500));
                    }
                    else
                    {
                        Msg.add("夹爪忙碌中...", MsgLevel.warning);
                        MoveInfo.log($"夹爪忙碌中...");
                    }
                    break;
                case MoveStep.T1_06_UpToTop:
                    MoveInfo.NextMoveStep(MoveStep.T1_07_PanToOut);
                    MoveInfo.log($"升降轴上升, 料盘提升下降");
                    T_Updown_Axis.AbsMove(MoveInfo, Config.UpdownAxis_P1, Config.UpdownAxis_P1_speed);
                    //MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.End_Lift_Tray_Check, IO_VALUE.LOW));
                    //MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    break;
                case MoveStep.T1_07_PanToOut:
                    if (IOValue(IO_T1_Type.End_Lift_Tray_Check).Equals(IO_VALUE.LOW))
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_08_UpReelOk);
                        MoveInfo.log($"横移到料串");
                        
                        CylinderMove(MoveInfo, IO_T1_Type.End_Lift_Cylinder_Down, IO_T1_Type.End_Lift_Cylinder_Up, IO_VALUE.LOW);
                    }
                    else if (MoveInfo.IsTimeOut(2))
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_08_UpReelFail);
                    }
                     //MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    break;
                case MoveStep.T1_08_UpReelOk:
                    if (ShelfInMoveInfo.MoveStep == MoveStep.Shelf_20_EmptyIn_ShelfReady)
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_08_DownToShelf);
                        T_Pan_Axis.AbsMove(MoveInfo, Config.Pan_P2, Config.Pan_P2_speed);

                    }
                    else if (MoveInfo.IsTimeOut(30))
                    {
                        Msg.add(crc.GetString("wait_shelf_ready", "等待料串准备完成"), MsgLevel.warning);
                    }
                    break;
                case MoveStep.T1_08_UpReelFail:
                    Msg.add(crc.GetString("T1_grip_fail","出料机构抓料失败,请人工处理"), MsgLevel.warning);
                    if (IOValue(IO_T1_Type.Reset_BTN).Equals(IO_VALUE.HIGH))
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_10_PutReelFinish);
                        CylinderMove(MoveInfo, IO_T1_Type.End_Lift_Cylinder_Down, IO_T1_Type.End_Lift_Cylinder_Up, IO_VALUE.LOW);
                    }
                    break;
                case MoveStep.T1_08_DownToShelf:
                    if (ShelfInMoveInfo.MoveStep == MoveStep.Shelf_20_EmptyIn_ShelfReady)
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_09_ReleaseReel);

                        var offset_x = LastStringCenter.X - CenterPos.X;
                        var offset_y = LastStringCenter.Y - CenterPos.Y;
                        offset_x = offset_x * -1;
                        offset_y = offset_y * -1;
                        var Y = Config.Y_P2 + offset_y * Config.Cam_Pixel_Y_Ratio;
                        var Pan_X = Config.Pan_P2 + offset_x * Config.Cam_Pixel_X_Ratio;

                        T_Pan_Axis.AbsMove(MoveInfo, Pan_X, Config.Pan_P2_speed);
                        T_Y_Axis.AbsMove(MoveInfo, Y, Config.Y_P2_speed);

                        int p3pos = Config.UpdownAxis_P3 - (MoveInfo.ReelParam.PlateRawH - 8) * Config.UpdownAxis_ChangeValue;                        
                        T_Updown_Axis.AbsMove(MoveInfo, p3pos, Config.UpdownAxis_P3_speed);

                        MoveInfo.log($"下降到料串 CenterPos:{CenterPos},AxisBase:{Config.Pan_P2},{Config.Y_P2},, StringCenter:{LastStringCenter}, Offset:{new Point(offset_x, offset_y)}, AXIS:{new Point(Pan_X, Y)},p3pos:{p3pos}");
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    }
                    else if (MoveInfo.IsTimeOut(30))
                    {
                        Msg.add(crc.GetString("wait_shelf_ready", "等待料串准备完成"), MsgLevel.warning);
                    }
                    break;
                case MoveStep.T1_09_ReleaseReel:
                    if (RobotManage.electricGripper.Release())
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_09_ReleaseReel_Test);
                        MoveInfo.log($"夹爪放松");
                    }
                    else
                    {
                        Msg.add("夹爪忙碌中...", MsgLevel.warning);
                        MoveInfo.log($"夹爪忙碌中...");
                    }
                    break;
                case MoveStep.T1_09_ReleaseReel_Test:
                    if (IOValue(IO_T1_Type.T1_Tray_Check).Equals(IO_VALUE.HIGH))
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_10_PutReelFinish);
                    }
                    else if (MoveInfo.IsTimeOut(2))
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_09_ReleaseReel_Fail);
                    }
                    //MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    break;
                case MoveStep.T1_09_ReleaseReel_Fail:
                    Msg.add(crc.GetString("T1_put_fail", "出料机构放失败,请人工处理"), MsgLevel.warning);
                    if (IOValue(IO_T1_Type.Reset_BTN).Equals(IO_VALUE.HIGH))
                    {
                        MoveInfo.NextMoveStep(MoveStep.T1_10_PutReelFinish);
                    }
                    break;
                case MoveStep.T1_10_PutReelFinish:
                    ShelfInMoveInfo.ReelParam = MoveInfo.ReelParam;
                    MoveInfo.NewMove(MoveStep.T1_01_WaitReel);
                    MoveInfo.log($"放料完成");
                    T_Updown_Axis.AbsMove(MoveInfo, Config.UpdownAxis_P1, Config.UpdownAxis_P1_speed);
                    T_Pan_Axis.AbsMove(MoveInfo, Config.Pan_P1, Config.Pan_P1_speed);
                    T_TrayPos_Axis.AbsMove(MoveInfo, Config.TrayPos_P1, Config.TrayPos_P1_speed);
                    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_21_EmptyIn_TrayDown);
                    MoveInfo.StopwatchLog();
                    break;
            }
        }
        /// <summary>
        /// 最后的料串中心点距离
        /// </summary>
        int Lastdistance = 0;

        /// <summary>
        /// 最后的有效料串中心点位置
        /// </summary>
        Point LastStringCenter = Point.Empty;

        /// <summary>
        /// 料串高度修正次数
        /// </summary>
        int TrayStringFixTimes = 0;

        Task CheckLocationTask = null;
        void ShelfInProcess()
        {
            if (CheckWait(ShelfInMoveInfo))
                return;
            switch (ShelfInMoveInfo.MoveStep)
            {
                case MoveStep.Shelf_EmptyIn_WaitWorkLeave:
                    if (ShelfOutMoveInfo.MoveStep == MoveStep.Wait)
                    {
                        Msg.add(crc.GetString("T1_wait_empty", "等待空料串进入线体"), MsgLevel.info);
                    }
                    else {
                        Msg.add(crc.GetString("T1_wait_release", "等待料串释放中"), MsgLevel.info);
                        return;
                    }
                    if (IOValue(IO_T1_Type.T1_Lift_Tray_Check).Equals(IO_VALUE.HIGH))
                    {
                        ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_15_EmptyIn_LocationUp);
                        ShelfInMoveInfo.log("工位有料,提升准备");
                    }
                    else if (IOValue(IO_T1_Type.EmptyString_In_Check).Equals(IO_VALUE.HIGH))
                    {
                        ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_10_EmptyIn_Wait_StopDown);
                        ShelfInMoveInfo.log("工位无料,入口等待位有料,开始进入");
                    }
                    else if (IOValue(IO_T1_Type.Empty_LineIn_Check).Equals(IO_VALUE.HIGH))
                    {
                        ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_10_EmptyIn_StopDown);
                        ShelfInMoveInfo.log("工位无料,入口位有料,开始进入");
                    }
                    break;
                case MoveStep.Shelf_10_EmptyIn_StopDown:
                    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_10_EmptyIn_Wait_StopDown);
                    ShelfInMoveInfo.log("入料线体启动, 等待料串到等待位置");
                    IOMove(IO_T1_Type.EmptyString_In_Stop, IO_VALUE.HIGH, false, 2000);
                    ShelfInLine.LineRun("n", 999, "Shelf_10_EmptyIn_Wait_StopDown");
                    ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.EmptyString_In_Check, IO_VALUE.HIGH));
                    break;
                case MoveStep.Shelf_10_EmptyIn_Wait_StopDown:
                    if (IOValue(IO_T1_Type.T1_Lift_Tray_Check).Equals(IO_VALUE.LOW))
                    {
                        ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_11_EmptyIn_WaitTime);
                        ShelfInMoveInfo.log("入料线体启动, 等待料串到横移等待位置");
                        IOMove(IO_T1_Type.EmptyString_Wait_Stop, IO_VALUE.HIGH, false, 2000);
                        ShelfInLine.LineRun("n", 999, "Shelf_11_EmptyIn_WaitTime");
                        ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.EmptyString_End_Check, IO_VALUE.HIGH));
                    }
                    break;
                case MoveStep.Shelf_11_EmptyIn_WaitTime:
                    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_11_EmptyIn_LiftUp);
                    ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    break;
                case MoveStep.Shelf_11_EmptyIn_LiftUp:
                    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_13_EmptyIn_SidingRun);
                    ShelfInMoveInfo.log("入料线体停止, 横移顶升上升");
                    ShelfInLine.LineStop("n", "Shelf_13_EmptyIn_SidingRun");
                    CylinderMove(ShelfInMoveInfo, IO_T1_Type.EmptyString_Lift_Down, IO_T1_Type.EmptyString_Lift_Up, IO_VALUE.HIGH);
                    CylinderMove(ShelfInMoveInfo, IO_T1_Type.T1_Lift_Down, IO_T1_Type.T1_Lift_Up, IO_VALUE.HIGH);
                    break;
                case MoveStep.Shelf_13_EmptyIn_SidingRun:
                    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_14_EmptyIn_LiftDown);
                    ShelfInMoveInfo.log("横移到位, 停止横移");
                    IOMove(IO_T1_Type.T1_Sliding_Run, IO_VALUE.HIGH);
                    IOMove(IO_T1_Type.EmptyString_Sliding_Run, IO_VALUE.HIGH);
                    IOMove(IO_T1_Type.T1String_Sliding_Run, IO_VALUE.HIGH);
                    ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.T1_Lift_Tray_Check, IO_VALUE.HIGH));
                    break;
                case MoveStep.Shelf_14_EmptyIn_LiftDown:
                    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_15_EmptyIn_LocationUp);
                    ShelfInMoveInfo.log("入横移顶升下降");
                    CylinderMove(ShelfInMoveInfo, IO_T1_Type.EmptyString_Lift_Down, IO_T1_Type.EmptyString_Lift_Up, IO_VALUE.LOW);
                    //CylinderMove(ShelfInMoveInfo, IO_T1_Type.T1_Lift_Down, IO_T1_Type.T1_Lift_Up, IO_VALUE.LOW);
                    break;
                case MoveStep.Shelf_15_EmptyIn_LocationUp:
                    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_16_EmptyIn_ForkFwd);
                    ShelfInMoveInfo.log("定位气缸上升");
                    LocationUp(ShelfInMoveInfo);
                    ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
                    break;
                case MoveStep.Shelf_16_EmptyIn_ForkFwd:
                    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_19_EmptyIn_BatchUp);
                    ShelfInMoveInfo.log("料架叉前进,横移皮带停止");
                    CylinderMove(ShelfOutMoveInfo, IO_T1_Type.Fork_Cylinder_Bck, IO_T1_Type.Fork_Cylinder_Fwd, IO_VALUE.HIGH);

                    IOMove(IO_T1_Type.T1_Sliding_Run, IO_VALUE.LOW);
                    IOMove(IO_T1_Type.EmptyString_Sliding_Run, IO_VALUE.LOW);
                    IOMove(IO_T1_Type.T1String_Sliding_Run, IO_VALUE.LOW);
                    break;
                case MoveStep.Shelf_19_EmptyIn_BatchUp:
                    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_19_LocationString);
                    ShelfInMoveInfo.log("T1 批量轴上升到P2");
                    TrayStringFixTimes = 0;
                    BatchAxisToP2(ShelfInMoveInfo, false);
                    break;
                case MoveStep.Shelf_19_LocationString:
                    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_19_LocationString_wait);
                    LocationString();
                    break;
                case MoveStep.Shelf_19_LocationString_wait:
                    if (CheckLocationTask.IsCompleted)
                    {
                        ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_20_EmptyIn_ShelfReady);
                    }
                    else if (ShelfInMoveInfo.IsTimeOut(5))
                    {
                        LastStringCenter = CenterPos;
                        ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_20_EmptyIn_ShelfReady);

                    }
                    break;
                case MoveStep.Shelf_20_EmptyIn_ShelfReady:          //等待料盘放入  
                    Msg.add(crc.GetString("T1_ShelfReady", "料串准备完毕,等待放入料盘"), MsgLevel.info);
                    break;
                case MoveStep.Shelf_21_EmptyIn_TrayDown:            //料盘放入后调用
                    var Height = ShelfInMoveInfo.ReelParam.PlateRawH;
                    var currpos = T_Batch_Axis.GetAclPosition() - Config.BatchAxis_ChangeValue * Height;
                    if (currpos < Config.BatchAxis_P1 + Config.BatchAxis_ChangeValue * 20)
                    {
                        ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_Work_WaitShelfLeave);
                        ShelfOutMoveInfo.NewMove(MoveStep.Shelf_Out_Wait);
                        ShelfInMoveInfo.log($"批量轴已下降到底,料串已满,Left_Batch_P1={Config.BatchAxis_P1},needpos={currpos}");
                    }
                    //else if (TrayStringFixTimes < 3 && currpos < Config.BatchAxis_P1 + Config.BatchAxis_ChangeValue * 100)
                    //{
                    //    ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_20_EmptyIn_ShelfReady);
                    //    TrayStringFixTimes++;
                    //    ShelfInMoveInfo.log($"批量轴已下降过半,重新提升料串 TrayStringFixTimes:{TrayStringFixTimes}");                        
                    //    BatchAxisToP2(false);
                    //}
                    else
                    {
                        ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_20_EmptyIn_ShelfReady);
                        //T_Batch_Axis.AbsMove(ShelfInMoveInfo, currpos, Config.BatchAxis_P1_speed);
                        BatchAxisToP1();
                        ShelfInMoveInfo.log($"批量轴已下降一张料盘位置,等待料盘放入,needpos={currpos},{ShelfInMoveInfo.ReelParam.ToStr()}");
                    }
                    break;
                case MoveStep.Shelf_Work_WaitShelfLeave:
                    if ((IOValue(IO_T1_Type.T1_Lift_Tray_Check).Equals(IO_VALUE.LOW)))
                    {
                        ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_EmptyIn_WaitWorkLeave);
                    }
                    Msg.add(crc.GetString("T1_Shelffull_waitempty", "料串已满等待空料串"), MsgLevel.info);
                    break;
            }

        }
        /// <summary>
        /// 定位料串中心位置
        /// </summary>
        void LocationString() {
            if (CheckLocationTask != null && !CheckLocationTask.IsCompleted)
                return;
            var aclposA = T_Batch_Axis.GetAclPosition();
            ShelfInMoveInfo.log($"计算料串中心位置 P2:{Config.BatchAxis_P2}, AclPos:{aclposA}");
            bool isFirstA = true;
            if (Math.Abs(Config.BatchAxis_P2 - aclposA) > Config.BatchAxis_ChangeValue * 4)
                isFirstA = false;

            CheckLocationTask = Task.Run(() => {
                (Bitmap Bitmap, Point CurrentPoint, string debugstring) = GetStringCenter(isFirstA);
                var distance = (int)Common.distance(CenterPos, CurrentPoint);
                TrayStringLocation?.Invoke(this, Bitmap);
                if (isFirstA && (int)Common.distance(LastStringCenter, CurrentPoint) < Config.String_Offset_Range_Px)
                {
                    LastStringCenter = CurrentPoint;
                    ShelfInMoveInfo.log($"计算料串中心位置 First LastStringCenter:{LastStringCenter}");
                    ///Lastdistance = distance;
                }
                else if ((int)Common.distance(LastStringCenter, CurrentPoint) < Config.String_Offset_Range_Px)
                {
                    LastStringCenter = CurrentPoint;
                    ShelfInMoveInfo.log($"计算料串中心位置 LastStringCenter:{LastStringCenter}");
                }
                else
                {
                    ShelfInMoveInfo.log($"计算料串中心位置 失败");
                    //LastStringCenter = CenterPos;
                }
                Task.Delay(1000).Wait();
            });
        }
        public bool ReleaseShelf()
        {
            if (ShelfInMoveInfo.MoveStep != MoveStep.Shelf_20_EmptyIn_ShelfReady)
            {
                return false;
            }
            ShelfInMoveInfo.NextMoveStep(MoveStep.Shelf_Work_WaitShelfLeave);
            ShelfOutMoveInfo.NewMove(MoveStep.Shelf_Out_Wait);
            ShelfInMoveInfo.log($"用户强制释放料架");
            return true;
        }
        void ShelfOutProcess()
        {
            if (CheckWait(ShelfOutMoveInfo))
                return;

            switch (ShelfOutMoveInfo.MoveStep)
            {
                case MoveStep.Shelf_Out_Wait:
                    if (IOValue(IO_T1_Type.T1_Lift_Tray_Check).Equals(IO_VALUE.LOW))
                    {
                        ConfigIO io = Config.getWaitIO(IO_T1_Type.T1_Lift_Tray_Check);
                        WarnMsg = $"{crc.GetString("wait", "等待")}(" + io.DisplayStr + "=LOW" + $")";
                        Msg.add(WarnMsg, MsgLevel.warning);
                        return; 
                    }
                    if (IOValue(IO_T1_Type.T1_Out_Check).Equals(IO_VALUE.HIGH))
                    {
                        ConfigIO io = Config.getWaitIO(IO_T1_Type.T1_Out_Check);
                        WarnMsg = $"{crc.GetString("wait", "等待")}(" + io.DisplayStr + "=HIGH" + $")";
                        Msg.add(WarnMsg, MsgLevel.warning);
                        return;
                    }

                    ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_30_Out_BatchDown);
                    ShelfOutMoveInfo.log("出口工位有料,出口等待位无料,开始送出");
                    break;
                case MoveStep.Shelf_30_Out_BatchDown:
                    ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_31_Out_ForkBck);
                    ShelfOutMoveInfo.log("批量轴下降到P1");
                    T_Batch_Axis.AbsMove(ShelfOutMoveInfo, Config.BatchAxis_P1, Config.BatchAxis_P1_speed);
                    break;
                case MoveStep.Shelf_31_Out_ForkBck:
                    ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_32_Out_LocationDown);
                    ShelfOutMoveInfo.log("料架叉后退");
                    CylinderMove(ShelfOutMoveInfo, IO_T1_Type.Fork_Cylinder_Bck, IO_T1_Type.Fork_Cylinder_Fwd, IO_VALUE.LOW);
                    break;
                case MoveStep.Shelf_32_Out_LocationDown:
                    ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_33_Out_OutStopDown);
                    ShelfOutMoveInfo.log("顶升工位下降");
                    CylinderMove(ShelfInMoveInfo, IO_T1_Type.T1_Lift_Down, IO_T1_Type.T1_Lift_Up, IO_VALUE.LOW);
                    break;
                case MoveStep.Shelf_33_Out_OutStopDown:
                    ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_34_Out_OutStopDown);
                    ShelfOutMoveInfo.log("顶升气缸下降");
                    LocationDown(ShelfOutMoveInfo);
                    break;
                case MoveStep.Shelf_34_Out_OutStopDown:
                    ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_35_Out_OutLineRun);
                    ShelfOutMoveInfo.log("阻挡气缸下降,链条运转");

                    //IOMove(IO_T1_Type.Line_Out_Run, IO_VALUE.HIGH);
                    ShelfOutLine.LineRun("n", 999, "Shelf_34_Out_OutLineRun");
                    ShelfOutMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.T1_Wait_Check, IO_VALUE.HIGH));
                    break;
                case MoveStep.Shelf_35_Out_OutLineRun:
                    ShelfOutMoveInfo.NextMoveStep(MoveStep.Shelf_36_Out_OutLineRun);
                    IOMove(IO_T1_Type.T1_Wait_Stop, IO_VALUE.HIGH, false, 2000);
                    ShelfOutMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_T1_Type.T1_Out_Check, IO_VALUE.HIGH));
                    break;
                case MoveStep.Shelf_36_Out_OutLineRun:
                    ShelfOutMoveInfo.log("呼叫AGV取满料串");
                    RobotManage.wistonAgvClient.NeedLeave();
                    ShelfOutMoveInfo.EndMove();
                    ShelfOutLine.LineStop("n", "Shelf_35_Out_OutLineRun");
                    break;
            }
        }
        void EmptyStringIN()
        {
            this.loginfo($"T1空料串入口感应到料串,Empty_LineIn_Check:{IOValue(IO_T1_Type.Empty_LineIn_Check)}");
            if (IOValue(IO_T1_Type.EmptyString_In_Check).Equals(IO_VALUE.HIGH))
            {
                this.loginfo($"T1等待位有料不允许进入");
                return;
            }
            //if (IOValue(IO_T1_Type.Empty_LineIn_Check).Equals(IO_VALUE.HIGH))
            //    return;
            ShelfInLine.LineRun("EmptyStringIN", 30);
            WaitIo(IO_T1_Type.Empty_LineIn_Check, IO_VALUE.HIGH, 10);
            IOMove(IO_T1_Type.EmptyString_In_Stop, IO_VALUE.HIGH, false, 3000);
            WaitIo(IO_T1_Type.EmptyString_In_Check, IO_VALUE.HIGH, 10);
            Thread.Sleep(3000);
            ShelfInLine.LineStop("EmptyStringIN");
            this.loginfo($"T1等待位进入完成");
        }


        int StartMovePosition = 0;
        void BatchAxisToP2(MoveInfo moveInfo ,bool isFirstMove = true)
        {
            int targetP2 = Config.BatchAxis_P2;
            int targetSpeed = Config.BatchAxis_P2_speed;
            if (!isFirstMove)
            {
                int currPosition = T_Batch_Axis.GetAclPosition();
                if (currPosition != -1)
                {
                    //targetP2 = currPosition + Config.Right_Batch_ChangeValue * 80;
                    if (targetP2 > Config.BatchAxis_P2)
                    {
                        targetP2 = Config.BatchAxis_P2;
                    }
                    moveInfo.log("BatchAxisToP2 目标P2: " + targetP2 + "(" + currPosition + ")");
                }
                //targetSpeed = Config.BatchAxis_P3Speed / 2;
            }
            moveInfo.TimeOutSeconds = 200;
            moveInfo.CanWhileCount = 0;
            //  需要增加定时器,获取验证信号并停止伺服
            StartMovePosition = T_Batch_Axis.GetAclPosition();
            moveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.T_Batch_Axis, targetP2, targetSpeed));
            Config.T_Batch_Axis.TargetPosition = targetP2;
            T_Batch_Axis.AbsMove(null, targetP2, targetSpeed);
            //开始检测信号
            T_Batch_Axis.BatchAxisStartCheck(IO_T1_Type.T1_Tray_Check, Config, IO_VALUE.HIGH);
        }


        void BatchAxisToP1()
        {
            int targetP1 = Config.BatchAxis_P1;
            int targetSpeed = Config.BatchAxis_P2_speed/2;

            ShelfInMoveInfo.TimeOutSeconds = 200;
            ShelfInMoveInfo.CanWhileCount = 0;
            //  需要增加定时器,获取验证信号并停止伺服
            StartMovePosition = T_Batch_Axis.GetAclPosition();
            ShelfInMoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.T_Batch_Axis, targetP1, targetSpeed));
            Config.T_Batch_Axis.TargetPosition = targetP1;
            T_Batch_Axis.AbsMove(null, targetP1, targetSpeed);
            //开始检测信号
            T_Batch_Axis.BatchAxisStartCheck(IO_T1_Type.T1_Tray_Check, Config, IO_VALUE.LOW);
        }
        public (Bitmap, Point, string) GetStringCenter(bool isFirst = false)
        {
            //if (isFirst)
            //    return GetStringCenterA();
            //else
                return GetStringCenterC();
        }
        [HandleProcessCorruptedStateExceptions]
        public (Bitmap, Point, string) GetStringCenterA()
        {
            //return (null, 0, "调试屏蔽");
            Bitmap bmap = Common.DeepClone(Camera._cam.GrabOneImage(RobotManage.t1Machine.Config.String_Camera));

            //Bitmap bmap = new Bitmap(@"D:\logs\853\Image_20210921151717963.bmp");
            Bitmap bitmap = new Bitmap(bmap.Width, bmap.Height);

            var rectx = Config.String_Center_X - 500;
            var recty = Config.String_Center_Y - 500;

            string debugtxt = "";
            var currpos = Point.Empty;
            //Bitmap bmap = new Bitmap("D:\\853string\\Image_20210605142037637.bmp");
            //pictureBox1.Image = (Bitmap)bmap.Clone();
            try
            {
                Rectangle rect = new Rectangle(0, 0, bmap.Width, bmap.Height);
                var bitmapData = bmap.LockBits(rect, ImageLockMode.ReadOnly, bmap.PixelFormat);
                var eyemImage = new EyemImage();
                eyemImage.ucpImage = bitmapData.Scan0;
                eyemImage.iWidth = rect.Width;
                eyemImage.iHeight = rect.Height;
                eyemImage.iChannels = 1;
                eyemImage.iDepth = 0;


                //创建扫描区域
                EyemRect eyemRect = new EyemRect();
                eyemRect.iXs = Config.String_Center_X - 175;
                eyemRect.iYs = Config.String_Center_Y - 175;
                eyemRect.iWidth = 175 * 2;
                eyemRect.iHeight = 175 * 2;

                eyemlib.EyemOcsFXYR eyemOcsFXYR = new eyemlib.EyemOcsFXYR();

                int result = eyemlib.eyemMulFuncTool(eyemImage, eyemRect, "__func1", ConfigHelper.Config.Get("findcicyle_p1",95), ConfigHelper.Config.Get("findcicyle_p2", 75), ref eyemOcsFXYR, out _);
                LogUtil.info($"eyemMulFuncTool:result:{result},fX:{eyemOcsFXYR.fX},fY:{eyemOcsFXYR.fY},fR:{eyemOcsFXYR.fR}");
                debugtxt = $"eyemMulFuncTool:\nresult:{result}\nfX:{eyemOcsFXYR.fX}\nfY:{eyemOcsFXYR.fY}\nfR:{eyemOcsFXYR.fR}";
                bmap.UnlockBits(bitmapData);
            
            currpos = new Point((int)eyemOcsFXYR.fX, (int)eyemOcsFXYR.fY);
            var centerpos = new Point(Config.String_Center_X, Config.String_Center_Y);
            var distance = (int)Common.distance(centerpos, currpos);

            
            
            //try
            //{
                Graphics graphics = Graphics.FromImage(bitmap);
                graphics.DrawImage(bmap, new PointF(0, 0));
                graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                Pen greenpen = new Pen(Color.Green, 15);
                Pen redpen = new Pen(Color.FromArgb(255, Color.Red), 10);
                int r = 102;
                graphics.DrawEllipse(greenpen, Config.String_Center_X - r, Config.String_Center_Y - r, r * 2, r * 2);
                graphics.DrawEllipse(greenpen, Config.String_Center_X - 8, Config.String_Center_Y - 8, 8 * 2, 8 * 2);

                graphics.DrawEllipse(redpen, eyemOcsFXYR.fX - eyemOcsFXYR.fR, eyemOcsFXYR.fY - eyemOcsFXYR.fR, eyemOcsFXYR.fR * 2, eyemOcsFXYR.fR * 2);
                graphics.DrawEllipse(redpen, eyemOcsFXYR.fX - 5, eyemOcsFXYR.fY - 5, 5 * 2, 5 * 2);

                SolidBrush blue = new SolidBrush(Color.BlueViolet);
                Font font = new Font(FontFamily.GenericSansSerif, 30);
                graphics.DrawString($"center:X:{Config.String_Center_X},Y:{Config.String_Center_Y}", font, blue, rectx, recty);
                graphics.DrawString($"result:{result},fX:{eyemOcsFXYR.fX},fY:{eyemOcsFXYR.fY},fR:{eyemOcsFXYR.fR}", font, blue, rectx, font.Height + recty);
                graphics.DrawString($"distance:{distance}", font, blue, rectx, font.Height * 2 + recty);

                graphics.Save();
                bmap.Dispose();
                graphics.Dispose();
            }
            catch(Exception e) {
                LogUtil.info("GetStringCenterA" + e.ToString());
                debugtxt = "GetStringCenterA" + e.ToString();
            }
            Bitmap newbitmap = bitmap.Clone(new Rectangle(rectx, recty, 1000, 1000), PixelFormat.Format24bppRgb);
            bitmap.Dispose();
            Directory.CreateDirectory("\\image\\TrayString\\");
            newbitmap.Save("\\image\\TrayString\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg", ImageFormat.Jpeg);

            return (newbitmap, currpos, debugtxt);
        }


        [HandleProcessCorruptedStateExceptions]
        public (Bitmap, Point, string) GetStringCenterC()
        {
            Directory.CreateDirectory("\\image\\TrayString\\");
            //return (null, 0, "调试屏蔽");
            Bitmap bmap = Common.DeepClone(Camera._cam.GrabOneImage(RobotManage.t1Machine.Config.String_Camera));
            bmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
            
            Bitmap bitmap = new Bitmap(bmap.Width, bmap.Height);
            
            var rectx = Config.String_Center_X - 500;
            var recty = Config.String_Center_Y - 500;

            var file = "\\image\\TrayString\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".Png";
            bmap.Save(file, ImageFormat.Png);

            //bmap.Dispose();


            string debugtxt = "";
            var currpos = Point.Empty;
            //bmap = new Bitmap("D:\\料串\\2021-10-28-14-25-01.jpg");
            //pictureBox1.Image = (Bitmap)bmap.Clone();
            
            try
            {
                Rectangle rect = new Rectangle(0, 0, bmap.Width, bmap.Height);
                //var bitmapData = bmap.LockBits(rect, ImageLockMode.ReadOnly, bmap.PixelFormat);
                var eyemImage = new EyemImage();
                //eyemImage.ucpImage = bitmapData.Scan0;
                //eyemImage.iWidth = rect.Width;
                //eyemImage.iHeight = rect.Height;
                //eyemImage.iChannels = 1;
                //eyemImage.iDepth = 0;
                var a = eyemImageRead(file, -1, out eyemImage);
                //创建扫描区域
                EyemRect eyemRect = new EyemRect();
                eyemRect.iXs = Config.String_Center_X - 175;
                eyemRect.iYs = Config.String_Center_Y - 175;
                eyemRect.iWidth = 175 * 2;
                eyemRect.iHeight = 175 * 2;

                //创建中心识别区域
                EyemRect limRect = new EyemRect();
                limRect.iXs = Config.String_Center_X - 175;
                limRect.iYs = Config.String_Center_Y - 175;
                limRect.iWidth = 175 * 2;
                limRect.iHeight = 175 * 2;

                eyemlib.EyemOcsDXYR eyemOcsDXYR = new eyemlib.EyemOcsDXYR();
                double dp = ConfigHelper.Config.Get("DetectCircle_dp", 1);
                double dMinDist = ConfigHelper.Config.Get("DetectCircle_dMinDist", 80);
                double dParam1 = ConfigHelper.Config.Get("DetectCircle_dParam1", 100);
                double dParam2 = ConfigHelper.Config.Get("DetectCircle_dParam2", 50);
                double dMinRadius = ConfigHelper.Config.Get("DetectCircle_dMinRadius", 30);
                double dMaxRadius = ConfigHelper.Config.Get("DetectCircle_dMaxRadius", 42);
                int result = eyemlib.eyemDetectCircleUseHough(eyemImage, eyemRect, limRect,out eyemOcsDXYR, out _, dp, dMinDist, dParam1, dParam2, dMinRadius, dMaxRadius, 3,true);
                LogUtil.info($"eyemDetectCircleUseHough:result:{result},fX:{eyemOcsDXYR.fX},fY:{eyemOcsDXYR.fY},fR:{eyemOcsDXYR.fR}");
                debugtxt = $"eyemDetectCircleUseHough:\nresult:{result}\nfX:{eyemOcsDXYR.fX}\nfY:{eyemOcsDXYR.fY}\nfR:{eyemOcsDXYR.fR}";
                //bmap.UnlockBits(bitmapData);
                eyemImageFree(ref eyemImage);
                currpos = new Point((int)eyemOcsDXYR.fX, (int)eyemOcsDXYR.fY);
                var centerpos = new Point(Config.String_Center_X, Config.String_Center_Y);
                var distance = (int)Common.distance(centerpos, currpos);



                //try
                //{
                Graphics graphics = Graphics.FromImage(bitmap);
                graphics.DrawImage(bmap, new PointF(0, 0));
                graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                Pen greenpen = new Pen(Color.Green, 15);
                Pen redpen = new Pen(Color.FromArgb(255, Color.Red), 10);
                int r = 102;
                graphics.DrawEllipse(greenpen, Config.String_Center_X - r, Config.String_Center_Y - r, r * 2, r * 2);
                graphics.DrawEllipse(greenpen, Config.String_Center_X - 8, Config.String_Center_Y - 8, 8 * 2, 8 * 2);

                graphics.DrawEllipse(redpen, (float)(eyemOcsDXYR.fX - eyemOcsDXYR.fR), (float)(eyemOcsDXYR.fY - eyemOcsDXYR.fR), (float)(eyemOcsDXYR.fR * 2), (float)(eyemOcsDXYR.fR * 2));
                graphics.DrawEllipse(redpen, (float)(eyemOcsDXYR.fX - 5), (float)(eyemOcsDXYR.fY - 5), 5 * 2, 5 * 2);

                SolidBrush blue = new SolidBrush(Color.BlueViolet);
                Font font = new Font(FontFamily.GenericSansSerif, 30);
                graphics.DrawString($"center:X:{Config.String_Center_X},Y:{Config.String_Center_Y}", font, blue, rectx, recty);
                graphics.DrawString($"result:{result},dX:{eyemOcsDXYR.fX},dY:{eyemOcsDXYR.fY},dR:{eyemOcsDXYR.fR}", font, blue, rectx, font.Height + recty);
                graphics.DrawString($"distance:{distance}", font, blue, rectx, font.Height * 2 + recty);

                graphics.Save();
                bmap.Dispose();
                graphics.Dispose();
            }
            catch (Exception e)
            {
                LogUtil.info("GetStringCenterC" + e.ToString());
                debugtxt = "GetStringCenterC" + e.ToString();
            }
            Bitmap newbitmap = bitmap.Clone(new Rectangle(rectx, recty, 1000, 1000), PixelFormat.Format24bppRgb);
            newbitmap.Save("\\image\\TrayString\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg", ImageFormat.Jpeg);
            //newbitmap.Dispose();
            bitmap.Dispose();



            return (newbitmap, currpos, debugtxt);
        }
        private static Bitmap ConvertTo24(Bitmap bmpIn)
        {

            Bitmap converted = new Bitmap(bmpIn.Width, bmpIn.Height, PixelFormat.Format24bppRgb);
            using (Graphics g = Graphics.FromImage(converted))
            {
                // Prevent DPI conversion
                g.PageUnit = GraphicsUnit.Pixel;
                // Draw the image
                g.DrawImageUnscaled(bmpIn,0,0);
            }
            return converted;
        }

        [HandleProcessCorruptedStateExceptions]
        public (Bitmap, Point, string) GetStringCenterB()
        {
            //return (null, 0, "调试屏蔽");
            var centerpos = new Point(Config.String_Center_X, Config.String_Center_Y);
            Bitmap bmap = Common.DeepClone(Camera._cam.GrabOneImage(RobotManage.t1Machine.Config.String_Camera));
            Rectangle rectangle = new Rectangle(centerpos.X - 640 / 2, centerpos.Y - 640 / 2, 640, 640);

            Bitmap newbitmap = Common.ImageCrop(bmap, rectangle);
            bmap.Dispose();
            string filename = "\\image\\TrayString\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg";
            newbitmap.Save(filename, ImageFormat.Jpeg);
            
            float fx = 0, fy = 0;
            int r = centerDetector(filename, ref fx, ref fy);
            LogUtil.info($"centerDetector r:{r},x:{fx},y:{fy}");
            if (r != 0 || fx == 0)
            {
                return (newbitmap, Point.Empty, "未检测到盘心");
            }
            var debugtxt = $"centerDetector:\nresult:{r}\nfX:{fx}\nfY:{fy}";
            var currpos = new Point((int)fx+ rectangle.X, (int)fy+ rectangle.Y);
            var distance = (int)Common.distance(centerpos, currpos);
            Pen greenpen = new Pen(Color.Green, 15);
            Pen redpen = new Pen(Color.FromArgb(255, Color.Red), 10);
            Graphics graphics = Graphics.FromImage(newbitmap);
            graphics.DrawEllipse(greenpen, Config.String_Center_X - 8, Config.String_Center_Y - 8, 8 * 2, 8 * 2);
            graphics.DrawEllipse(redpen, (int)fx - 5, (int)fy - 5, 5 * 2, 5 * 2);
            graphics.Save();
            return (newbitmap, currpos, debugtxt);
        }
        [DllImport("yolov5.dll", CharSet = CharSet.Ansi)]
        public static extern int centerDetector([MarshalAs(UnmanagedType.LPStr)] string filename, ref float x, ref float y);


    }
}