CH347 C# CH347GetDeviceInfor

Hi Sir,

Sorry my PC cannot type Chinese.

This code always has error of?System.AccessViolationException protected memroy access.

Could you please help the?CH347GetDeviceInfor C# coding?



? ? [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi,Pack =0, Size = 545)]// pack 0 for 4 bytes pack. All parameter offset must be aligned to 4x

? ? public struct _DEV_INFOR

? ? {

? ? ? ? [FieldOffset(0)]

? ? ? ? public byte iIndex;? ? ? ? ? ? ? ? ?// 當前打開序號

? ? ? ? [FieldOffset(1)]

? ? ? ? public byte DevicePath;? ?// 設備鏈接名,用于CreateFile

? ? ? ? [FieldOffset(261)]

? ? ? ? public byte UsbClass;? ? ? ? ? ? ? ?// 0:CH347_USB_CH341, 2:CH347_USB_HID,3:CH347_USB_VCP

? ? ? ? [FieldOffset(262)]

? ? ? ? public byte FuncType;? ? ? ? ? ? ? ?// 0:CH347_FUNC_UART,1:CH347_FUNC_SPI_I2C,2:CH347_FUNC_JTAG_I2C

? ? ? ? [FieldOffset(264)]

? ? ? ? public byte[] DeviceID;? ? ? ? ? ?// USB\VID_xxxx&PID_xxxx

? ? ? ? [FieldOffset(328)]

? ? ? ? public byte ChipMode;? ? ? ? ? ? ? ?// 芯片模式,0:Mode0(UART0/1); 1:Mode1(Uart1+SPI+I2C); 2:Mode2(HID Uart1+SPI+I2C) 3:Mode3(Uart1+Jtag+IIC)

? ? ? ? [FieldOffset(329)]

? ? ? ? public IntPtr DevHandle;? ? ? ? ? ? ? // 設備句柄

? ? ? ? [FieldOffset(333)]

? ? ? ? public UInt16 BulkOutEndpMaxSize;? ? ?// 上傳端點大小

? ? ? ? [FieldOffset(335)]

? ? ? ? public UInt16 BulkInEndpMaxSize;? ? ? // 下傳端點大小

? ? ? ? [FieldOffset(337)]

? ? ? ? public byte UsbSpeedType;? ? ? ? ? ?// USB速度類型,0:FS,1:HS,2:SS

? ? ? ? [FieldOffset(338)]

? ? ? ? public byte CH347IfNum;? ? ? ? ? ? ?// 設備接口號: 0:UART,1:SPI/IIC/JTAG/GPIO

? ? ? ? [FieldOffset(339)]

? ? ? ? public byte DataUpEndp;? ? ? ? ? ? ?// 端點地址

? ? ? ? [FieldOffset(340)]

? ? ? ? public byte DataDnEndp;? ? ? ? ? ? ?// 端點地址

? ? ? ? [FieldOffset(344)]

? ? ? ? public byte[] ProductString;? ? ? // USB產(chǎn)品字符串

? ? ? ? [FieldOffset(408)]

? ? ? ? public byte[] ManufacturerString; // USB廠商字符串

? ? ? ? [FieldOffset(472)]

? ? ? ? public UInt32 WriteTimeout;? ? ? ? ? ?// USB寫超時

? ? ? ? [FieldOffset(476)]

? ? ? ? public UInt32 ReadTimeout;? ? ? ? ? ? // USB讀超時

? ? ? ? [FieldOffset(480)]

? ? ? ? public byte[] FuncDescStr;? ? ? ? // 接口功能描述符

? ? ? ? [FieldOffset(544)]

? ? ? ? public byte FirmwareVer;? ? ? ? ? ? // 固件版本

? ? }



Hello, I have sent a private message to you. Could you please provide the complete project for me to review.


Sir,

You may download the code via Github.

https://github.com/ChrisLin76/CH347-USB-I2C-SPI-UART

Thanks.



Hi Sir,

可以幫忙看看問題嗎?

Github可以下載完整的Code.

https://github.com/ChrisLin76/CH347-USB-I2C-SPI-UART


CH347.DLL內(nèi)的CH347GetDeviceInfor的仍無法打通


您好,我查看了您的代碼,對于結構體的處理您可做如下操作,使用順序布局的基礎上,按1字節(jié)對其即可,此方式也較便捷。

[StructLayout(LayoutKind.Sequential,?Pack?=?1)]
????public?struct?_DEV_INFOR
????{
????????public?byte?iIndex;?????????????????//?當前打開序號
????????
????????[MarshalAs(UnmanagedType.ByValArray,?SizeConst?=?260)]
????????public?byte[]?DevicePath;???????????//?設備鏈接名,用于CreateFile
????????public?byte?UsbClass;???????????????//?0:CH347_USB_CH341,?2:CH347_USB_HID,3:CH347_USB_VCP
????????public?byte?FuncType;???????????????//?0:CH347_FUNC_UART,1:CH347_FUNC_SPI_I2C,2:CH347_FUNC_JTAG_I2C
????????
????????[MarshalAs(UnmanagedType.ByValArray,?SizeConst?=?64)]
????????public?byte[]?DeviceID;???????????????//?USB\VID_xxxx&PID_xxxx
????????public?byte?ChipMode;???????????????//?芯片模式,0:Mode0(UART0/1);?1:Mode1(Uart1+SPI+I2C);?2:Mode2(HID?Uart1+SPI+I2C)?3:Mode3(Uart1+Jtag+IIC)
????????public?IntPtr?DevHandle;??????????????//?設備句柄
????????public?UInt16?BulkOutEndpMaxSize;?????//?上傳端點大小
????????public?UInt16?BulkInEndpMaxSize;??????//?下傳端點大小
????????public?byte?UsbSpeedType;???????????//?USB速度類型,0:FS,1:HS,2:SS
????????public?byte?CH347IfNum;?????????????//?設備接口號:?0:UART,1:SPI/IIC/JTAG/GPIO
????????public?byte?DataUpEndp;?????????????//?端點地址
????????public?byte?DataDnEndp;?????????????//?端點地址
????????
????????[MarshalAs(UnmanagedType.ByValArray,?SizeConst?=?64)]
????????public?byte[]?ProductString;??????//?USB產(chǎn)品字符串
????????
????????[MarshalAs(UnmanagedType.ByValArray,?SizeConst?=?64)]
????????public?byte[]?ManufacturerString;?//?USB廠商字符串
????????public?UInt32?WriteTimeout;???????????//?USB寫超時
????????public?UInt32?ReadTimeout;????????????//?USB讀超時
????????
????????[MarshalAs(UnmanagedType.ByValArray,?SizeConst?=?64)]
????????public?byte[]?FuncDescStr;????????//?接口功能描述符
????????public?byte?FirmwareVer;????????????//?固件版本
????}



OK了,感謝支援!!


只有登錄才能回復,可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频