zoukankan      html  css  js  c++  java
  • 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);

        }

  • 相关阅读:
    vue typescript: Parameter ‘XXX’ implicitly has an ‘any’ type.解决方法
    ESLint学习(一)简介、安装、配置、命令行、规则
    使用vite搭建vue3项目(三) 配置国际化
    VUE3+Typescript 引用process提示错误
    centos7安装vsftpd,配置
    使用vite搭建vue3项目(一) 创建一个工程
    Symbols 是 JavaScript 最新推出的一种基本类型
    使用vite搭建vue3项目(二) 引入vuerouter
    在使用vite时使用import.meta.globEager 代替 require.context 自动导入文件
    VUE3.X版本error: Parsing error: Parsing error: Unexpected token 的解决办法
  • 原文地址:https://www.cnblogs.com/oyjj/p/2132978.html
Copyright © 2011-2022 走看看