C#Silicon Labs CP2102使用CP210xManufacturing dll使用

时间:2014-05-09 19:59:00

标签: c# dll

我正在尝试使用Silicon Labs CP210xManufacturing.dll来读取和设置2102芯片中的一些值。我可以读取产品ID和产品字符串,但我似乎无法读取序列号。该设备在SI实验室的代码中显示正常,因此我知道该设备正在运行。

这是我的代码(我使用的是Studio 2008,但它也在Studio 2012中显示了这一点);

这是我得到dll的地方;

http://www.silabs.com/products/mcu/Pages/USBXpress.aspx

如果取消注释以下行,Studio会显示以下错误;

第30行// result = CSepSIChipWrap.getDeviceSerialNumber(siRef,serialNumber,ref length,true);

错误2'CS_2102_Testing.CSepSIChipWrap.getDeviceSerialNumber(ref System.IntPtr,ref System.Text.StringBuilder,ref byte,bool)'的最佳重载方法匹配有一些无效的参数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;


namespace CS_2102_Testing
{
    class Program
    {
        static void Main(string[] args)
        {
            IntPtr siRef = IntPtr.Zero;
            uint numDevice = 0;
            var result = CSepSIChipWrap.getNumberOfDevices(ref numDevice);
            result = CSepSIChipWrap.open(0, ref siRef);

            ushort pid = 0;
            result = CSepSIChipWrap.getDevicePid(siRef, ref pid);

            StringBuilder productString = new StringBuilder();
            byte length = 0;
            result = CSepSIChipWrap.getDeviceProductString(siRef, productString, ref length, true);


            StringBuilder serialNumber = new StringBuilder();
            byte serialLength = 0;
            //result = CSepSIChipWrap.getDeviceSerialNumber(siRef, serialNumber, ref length, true);



            Console.WriteLine(pid.ToString());
            Console.WriteLine(productString.ToString());
            Console.ReadLine();
        }
    }

    class CSepSIChipWrap
    {
        private const string CP210xManu = "CP210xManufacturing.dll";

        [DllImport(CP210xManu, EntryPoint = "CP210x_GetNumDevices")]
        public static extern int getNumberOfDevices(
        [In, Out] ref UInt32 deviceNumb);

        [DllImport(CP210xManu, EntryPoint = "CP210x_Open")]
        public static extern int open(
        [In] UInt32 deviceNumb,
        [In, Out] ref IntPtr deviceHandle);

        [DllImport(CP210xManu, EntryPoint = "CP210x_Close")]
        public static extern int close(
        [In, Out] ref IntPtr deviceHandle);

        [DllImport(CP210xManu, EntryPoint = "CP210x_GetDeviceProductString",
        CharSet = CharSet.Ansi)]
        public static extern int getDeviceProductString(
        [In, Out] IntPtr deviceHandle,
        [In, Out] StringBuilder Product,
        [In, Out] ref byte Length,
        [In] bool ConvertToASCII);

        [DllImport(CP210xManu, EntryPoint = "CP210x_GetDeviceSerialNumber",
        CharSet = CharSet.Ansi)]
        public static extern int getDeviceSerialNumber(
        [In, Out] ref IntPtr deviceHandle,
        [In, Out] ref StringBuilder Product,
        [In, Out] ref byte Length,
        [In, Out] bool ConvertToASCII);

        [DllImport(CP210xManu, EntryPoint = "CP210x_GetDeviceVid")]
        public static extern int getDeviceVid(
        [In, Out] ref IntPtr deviceHandle,
        [In, Out] ref ushort Vid);

        [DllImport(CP210xManu, EntryPoint = "CP210x_GetDevicePid")]
        public static extern int getDevicePid(
        [In, Out] IntPtr deviceHandle,
        [In, Out] ref ushort Pid);
    }   

}

0 个答案:

没有答案