zoukankan      html  css  js  c++  java
  • .NET下使用ufun函数取CAM操作的进给速度

    UF_PARAM_ask_subobj_ptr_value,这个函数在封装的时候,给了很大一个坑啊。

    NXOpen.UF.UFParam.AskSubobjPtrValue(ByVal param_tag As NXOpen.Tag,
                                        ByVal param_index As Integer,
                                        ByRef value As System.IntPtr)

    如果你想使用如下的代码可以取到竟给速度,那你就错了

    错误是使用方法
    Dim cb As Integer = Marshal.SizeOf(GetType(NXOpen.UF.UFParam.Feedrate))
    Dim ptr As IntPtr = Marshal.AllocHGlobal(cb)
    theUfSession.Param.AskSubobjPtrValue(oper.tag, UFConstants.UF_PARAM_FEED_CUT, ptr)
    Dim feed_cut As NXOpen.UF.UFParam.Feedrate = CType(Marshal.PtrToStructure(ptr, GetType(NXOpen.UF.UFParam.Feedrate)), NXOpen.UF.UFParam.Feedrate)

    这个函数一直让我头疼了三年多,今天终于想到办法了

    其实这里不能使用指针,而是直接使用结构体NXOpen.UF.UFParam.Feedrate

    将UF_PARAM_ask_subobj_ptr_value函数重新封装定义一下:

    <DllImport("libufun.dll", EntryPoint:="UF_PARAM_ask_subobj_ptr_value", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi)> _
            Friend Shared Function _AskFeedRate(ByVal param_tag As Tag, ByVal param_index As Integer, <Out> ByRef value As NXOpen.UF.UFParam.Feedrate) As Integer
            End Function
    
            <DllImport("libufun.dll", EntryPoint:="UF_PARAM_set_subobj_ptr_value", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi)> _
            Friend Shared Function _SetFeedRate(ByVal param_tag As Tag, ByVal param_index As Integer, ByVal value As NXOpen.UF.UFParam.Feedrate) As Integer
            End Function

    整理了一下使用方法,代码如下:

    Public Function AskFeedRate(ByVal param_index As Integer) As NXOpen.UF.UFParam.Feedrate
        Dim value As NXOpen.UF.UFParam.Feedrate
        Dim errorCode As Integer = _AskFeedRate(_camobject, param_index, value)
        If errorCode <> 0 Then
            Throw NXOpen.NXException.Create(errorCode)
        End If
        Return value
    End Function
    
    
    Public Sub SetFeedRate(ByVal param_index As Integer, ByVal value As NXOpen.UF.UFParam.Feedrate)
        Dim errorCode As Integer = _SetFeedRate(_camobject, param_index, value)
        If errorCode <> 0 Then
            Throw NXOpen.NXException.Create(errorCode)
        End If
    End Sub
  • 相关阅读:
    通俗理解乐观锁和悲观锁
    面试系列-HashMap和Hashtable的区别
    单点登录原理与实现
    CodeReview常见代码问题
    漫画:什么是冒泡排序?
    Redis 和 Memcached 的区别
    动态图文了解 8 大排序算法
    分布式系统常见的事务处理机制
    面试系列-String,StringBuffer,StringBuilder三者区别
    面试系列-高并发之synchronized
  • 原文地址:https://www.cnblogs.com/bizca/p/4964302.html
Copyright © 2011-2022 走看看