C#调用PMAC运动控制卡的pcomm32动态链接库的数据类型转换

C#进行平台互调用总是很麻烦,不像C++调用的使用,人家厂商把.h文件都写好了,C#中的函数声明得自己来写,差一点都不行。不少人走了不少弯路,甚至对用.net来做工控程序界面失去了信心。为了节省广大开发人员的时间,将我写的一组好使好使的DllImport共享给大家。

下面给出C#调用PAMC运动控制卡中的pcomm32.dll时的用到的常用函数声明的数据类型转换后的形式

public class PMAC

    {

        /// <summary>

        /// This function opens a channel for the program to use the PMAC driver

        /// BOOL OpenPmacDevice(DWORD dwDevice);

        /// </summary>

        /// <param name="dwDevice">Device number to open</param>

        /// <returns>True if successful</returns>

        [DllImport("pcomm32.dll")]

        public static extern bool OpenPmacDevice(uint dwDevice);

 

        /// <summary>

        /// This function closes the channel from your program to the PMAC driver

        /// BOOL ClosePmacDevice(DWORD dwDevice);

        /// </summary>

        /// <param name="dwDevice">Device number to close</param>

        /// <returns>True if successful</returns>

        [DllImport("pcomm32.dll")]

        public static extern bool ClosePmacDevice(uint dwDevice);

 

        /// <summary>

        /// Provides a way to select and configure currently installed PMAC Devices

        /// long PmacSelect( HWND hwnd );

        /// </summary>

        /// <param name="hWnd">Handle to parent window for device configuration dialog</param>

        /// <returns>

        /// >= 0 and <= 7 : Device selected

        /// -1 or FFFFFFFF : User aborted with Cancel button.

        /// </returns>

        [DllImport("pcomm32.dll")]

        public static extern int PmacSelect(uint hWnd);

 

        /// <summary>

        /// Sends a string buffer to PMAC and flushes out any response from PMAC

        /// void PmacSendCommandA(DWORD dwDevice,PCHAR command)

        /// </summary>

        /// <param name="dwDevice">Device number</param>

        /// <param name="command">Pointer to NULL terminated string sent to PMAC</param>

        [DllImport("pcomm32.dll")]

        public static extern void PmacSendCommandA(uint dwDevice, string command);

 

        /// <summary>

        /// Most if not all of the communication with the PMAC can be handled

        /// long PmacGetResponseA(DWORD dwDevice,PCHAR response,UINT maxchar,PCHAR command);

        /// </summary>

        /// <param name="dwDevice">Device number</param>

        /// <param name="reponse">Pointer to string buffer to copy the PMACs response into</param>

        /// <param name="maxchar">Maximum characters to copy</param>

        /// <param name="command">Pointer to NULL terminated string to be sent to the PMAC as a question/command</param>

        /// <returns>

        /// The upper byte contains the status of the call, whereas all lower bytes contain the number of characters

        /// received from PMAC. If no characters were received from PMAC, check the upper bytes status code for

        /// a potential error code. See the Error Handling - ASCII Communication section for a detailed explanation.

        ///

        /// If successful, this function returns the number of characters received, including handshake characters.

        /// Otherwise FALSE (0) which implies of course that an error occurred, or no characters were received

        /// since PMAC was not required to respond.

        /// </returns>

        [DllImport("pcomm32.dll")]

        public static extern int PmacGetResponseA(uint dwDevice, byte[] reponse, uint maxchar, string command);

 

        [DllImport("pcomm32.dll")]

        public static extern int PmacGetBufferA(uint dwDevice, byte[] reponse, uint maxchar);

 

        [DllImport("pcomm32.dll")]

        public static extern int PmacSendLineA(uint dwDevice, string command);

    }

转载于:https://www.cnblogs.com/oyjj/archive/2009/09/15/2132978.html

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Pmac运动控制是一种用于运动控制的硬件设备,而上位机编程是一种为Pmac运动控制编写控制程序的编程方式。 上位机编程通过编写控制程序,将所需的运动控制逻辑和参数传输给Pmac运动控制,从而实现对运动控制系统的控制。 上位机编程可以通过各种编程语言来实现,比如C/C++、Visual Basic、LabVIEW等。编程者可以根据自己的需求和熟悉程度选择合适的编程语言来进行上位机编程。 在进行上位机编程时,首先需要了解和理解Pmac运动控制的功能和特性,包括如何配置、如何定义轴和运动参数等。然后,可以结合编程语言的特点和功能,编写相应的控制程序,实现对Pmac运动控制控制和调度。 上位机编程可以实现多种功能,比如位置控制、速度控制、力控制等。通过编写相应的控制程序,可以实现精确的运动控制和高效的运动系统控制。 总之,Pmac运动控制上位机编程是一种为Pmac运动控制编写控制程序的方式,通过上位机编程可以实现对运动控制系统的灵活控制。 ### 回答2: PMAC(Programmable Multi-Axis Controller)是一种运动控制,上位机编程是在PC上编写程序来控制PMAC进行运动控制。 上位机编程主要包括以下几个方面: 1. 硬件配置:通过上位机编程,可以配置PMAC的硬件参数,如轴数、编码器类型、输入输出信号等。可以根据实际需求配置不同的硬件组合,以便实现多轴控制。 2. 运动命令:上位机编程可以生成运动命令,包括指定轴的目标位置、速度、加减速度等。通过编程可以实现复杂的运动路径规划,如直线插补、圆弧插补等。 3. 输入输出控制PMAC通常具有多个数字输入输出端口,可以连外部器件如传感器、执行器等。通过上位机编程,可以编写逻辑控制程序,实现与外部设备的交互。例如,可以通过编程实现当某个输入信号触发时,执行某个特定的运动或输出控制信号。 4. 同步运动:在某些应用中,需要多个轴进行同步运动。通过上位机编程,可以实现多个轴的同步运动,确保各轴之间的位置和速度同步。 5. 故障诊断和调试:上位机编程可以将PMAC的状态和错误信息输出到PC上,便于故障诊断和调试。通过分析上位机输出的信息,可以快速找到问题的根源,并进行修复。 总之,上位机编程是控制PMAC运动控制的重要手段之一。通过编写上位机程序,可以实现复杂的运动控制和与外部设备的交互,提高运动控制系统的灵活性和功能性。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值