C# 工程 SDK的实现

在我们的一个项目中,需要用C#实现一个SDK,以便于以后调用这个SDK来对机器人进行操控。
首先这个SDK是继承了base. base是abstract抽象类,大致如下所示:

     public abstract class Base
    {
        public abstract void Start(Dictionary<string, Object> cfg);
        public abstract bool IsOnline();
        public abstract bool LoadPara();
        public abstract bool SetPara(int id, Dictionary<string, Object> para);
        public abstract bool GetPara(int id, ref Dictionary<string, Object> para);
        public abstract bool FireOn(bool flag, int fireOnTime, int fireOffTime, float weldVoltage, float weldCurrent);

可以看到抽象类定义焊接机器人的很多动作。
下面是SDK的部分代码:

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Hanli.Driver;
using Hanli.ParaStorage;
using Hanli.Platform;

namespace Hanli.MotionMidware
{
    public class STEP_ROBOT : Base
    {
        private static STEP_ROBOT _robot;
        public const float LenUnitScale = GlobalParam.LEN_UNIT_SCALE;
        private const int MonitorInterval = 100;    // 线程间隔(ms)
        private bool myMovActually = false;
        bool myCMModeOn = false;

        public static STEP_ROBOT GetRobot()
        {
            if (_robot == null)
            {
                _robot = new STEP_ROBOT();
            }
            return _robot;
        }

        STEPSDK _sdk;
        private bool[] _DIs;
        private Coord _currentPosition;
        private Coord _resetPosition;
        private Coord myCurPos;

        private STEP_ROBOT()
        {
            _sdk = STEPSDK.GetSDK();
            _currentPosition = new Coord();
            myCurPos = new Coord();
            //_resetPosition = new Coord()
            //{
            //    x = -1224,
            //    y = -1943,
            //    z = 2276,
            //    rx = -1766,
            //    ry = 66,
            //    rz = -491
            //};
            Task.Run(UpdataDIs);
        }

        public void WriteSDK()
        {
            _sdk.Write();
        }

在窗体中,可以这么调用SDK:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Hanli.MotionMidware;
private void button16_Click(object sender, EventArgs e)
{
            STEPSDK _sdk = STEPSDK.GetSDK();
            _sdk.SetWeldingProcess(int WeldVoltage, int WeldCurrent, int WeldSpeed, int StartArcDelay, int StopArcDelay); 
}

这个SDK是和机器人进行通讯,其通讯方式如下图所示:
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值