使用WPF開(kāi)發(fā)CH347T上位機(jī),已對(duì)照官方的CH341的CSHARP例程對(duì)CH347DLL.H進(jìn)行了重寫(xiě),以下為CH347讀數(shù)據(jù)的方法重寫(xiě)前后對(duì)比:
//SPI4讀數(shù)據(jù)?無(wú)需先寫(xiě)數(shù)據(jù),效率較CH347SPI_WriteRead高很多(原CH347DLL.H內(nèi)接口) BOOL?WINAPI?CH347SPI_Read(ULONG?iIndex,?????//指定設(shè)備序號(hào) ??????????????ULONG?iChipSelect,???//片選控制,位7為0則忽略片選控制,位7為1進(jìn)行片選操作 ??????????????ULONG?oLength,?????//準(zhǔn)備發(fā)出的字節(jié)數(shù) ??????????????PULONG?iLength,????//準(zhǔn)備讀入的數(shù)據(jù)字節(jié)數(shù) ??PVOID?ioBuffer);????//指向一個(gè)緩沖區(qū),放置準(zhǔn)備從DOUT寫(xiě)出的數(shù)據(jù),返回后是從DIN讀入的數(shù)據(jù)
//SPI4讀數(shù)據(jù)?無(wú)需先寫(xiě)數(shù)據(jù),效率較CH347SPI_WriteRead高很多(重寫(xiě)后的C#接口) [DllImport("CH347DLL.DLL",?EntryPoint?=?"CH347SPI_Read")] public?static?extern?bool?CH347SPI_Read(uint?iIndex,????//指定設(shè)備序號(hào) ??????????????????????uint?iChipSelect,?//片選控制,位7為0則忽略片選控制,位7為1進(jìn)行片選操作 ??????????????????????uint?oLength,???//準(zhǔn)備發(fā)出的字節(jié)數(shù) ??????????????????????uint?iLength,???//準(zhǔn)備讀入的數(shù)據(jù)字節(jié)數(shù) ??????????????????????byte[]?ioBuffer);?//指向一個(gè)緩沖區(qū),放置準(zhǔn)備從DOUT寫(xiě)出的數(shù)據(jù),返回后是從DIN讀入的數(shù)據(jù)
我是C#新手,不太明白為什么PVOID ioBuffer 為什么是直接寫(xiě)成 byte[] ioBuffer,正常如果直接傳緩沖區(qū)數(shù)組進(jìn)去,接口里面的程序不會(huì)無(wú)法訪(fǎng)問(wèn)外面定義的緩沖區(qū)數(shù)組嗎,在實(shí)際在調(diào)用過(guò)程中也是報(bào)錯(cuò):
嘗試更改傳入的變量,改成IntPtr ioBuffer傳數(shù)組首地址指針、或改成ref byte[] ioBuffer傳數(shù)組引用、或是將數(shù)組首地址轉(zhuǎn)為byte[]數(shù)組再傳入,都是一樣報(bào)錯(cuò),不知道是不是CH347DLL.cs寫(xiě)的有問(wèn)題,附上我重寫(xiě)的CH347DLL.cs,跪求解決方法