哪位能帮把USBEE逻辑仪自定义解码的VB工程转成VC工程
USBEE逻辑仪带自定义解码扩展,最近有用到,是个VB的DLL工程,没用过VB,翻着网页磕磕碰碰的在源码上勉强实现了自定义解码。以后再用到难道又要去磕磕碰碰用VB,于是想改成VC的。先测试自己重建VB工程,用VS2010选VB->类库,选.NET3.5,复制源码编译,出来的DLL可用。 开始默认选的.NET4.0出来的DLL不可用,启用调试发现提示改成3.5就好了。
接下来建VC工程,选择VC->类库,选.NET3.5 空工程编译提示出错: NET3.5需要安装VS2008
usbee手册说的 You can build this Class Library using the free Microsoft Visual Studio 2008 Express or newer.Our example is in Visual Basic, but can easily be ported to C or other language supported in Visual Studio.
厚着脸皮求助哪位上位机玩的熟的能否帮忙看一下将工程和代码转成能用的VC DLL,电工都会C,有VC工程就都能自己改了重编译。 工程已经从安装目录打包上来,谢谢。
原始VB工程打包 bbs2009 发表于 2016-8-5 11:55
感觉这么折腾 还不如用 VB.net方便。也不是多大的程序 , VB.net也没那么难。 装 VS2008 也不难。
...
vc2008 以后版本啊 你这主要就是把这个“CustomUSBeeSuiteDecoder.vb”转换一下就可以了嘛。这个是原代码吧?
Option Explicit On
Option Strict On
Imports System.IO
Public Class CustomUSBeeSuiteDecoder
Declare Function SampleData Lib "usbeeste.dll" Alias "?LoggedData@@YGJK@Z" (ByVal Index As Integer) As UInteger
' The SampleData routine returns a 4 byte value that contains a single sample of all the signals
' The format of the 32 bits is as follows:
'
' MSB LSB
' XXXXXXXXYYYYYYYYFEDCBA9876543210
'
' where XXXXXXXX is Channel 2 Analog value (0=-10V, 255 = +10V)
' YYYYYYYY is Channel 1 Analog value (0=-10V, 255 = +10V)
' F is logic level (0 or 1) for channel F
' E is logic level (0 or 1) for channel E
' D is logic level (0 or 1) for channel D
' ...
' 0 is logic level (0 or 1) for channel 0
Dim GTriggerSample As UInteger
Dim GX1Sample As UInteger
Dim GX2Sample As UInteger
Public Sub SetCaptureParameters(ByVal TriggerSample As UInteger, ByVal X1Sample As UInteger, ByVal X2Sample As UInteger)
' This routine is called right at the end of a capture to pass the positions of the Trigger and X1 and X2 Cursors to the
' custom decoding process.
GTriggerSample = TriggerSample
GX1Sample = X1Sample
GX2Sample = X2Sample
End Sub
Public Sub DecodeCustom(ByVal OutFilename As String, ByVal NumberOfSamples As Integer, ByVal RateIndex As Byte, ByVal Parameters As String)
Dim OldSample As UInteger
Try
' This is a custom bus decoder Processing Routine
'
' The passed in variables are as follows:
' OutFilename - the file that all of the decoded Entries get written to.This is the file that the USBee Suite
' will read to display the data on the waveline.
' NumberOfSamples - How many samples are in the sample buffer
' RateIndex - An index of the sample rate that the samples were taken.
' 17=1Msps,27=2Msps,37=3Msps,47=4Msps,67=6Msps,87=8Msps,127=12Msps,167=16Msps,247=24Msps
' Parameters - User defined string passed from the USBee Suite user interface Channel Setting for the custom decoder.
' Use this string to pass in any parameters that your decoder needs to know, such as what channels to use
' in decoding, which protocol if you have multiple protocols supported here, and how you want the data formatted.
' Below is an example set of Custom Protocol decoders that show how to access the sample buffer and how to generate output that get sent to the screen.
' Setup the File Stream that stores the Output Entry Information
Dim FS As New FileStream(OutFilename, FileMode.Append, FileAccess.Write)
Dim BW As New BinaryWriter(FS)
Dim SamplingRate As Double
' Determining the actual sample rate so it can be written in the OutputFile
' 17=1Msps,27=2Msps,37=3Msps,47=4Msps,67=6Msps,87=8Msps,127=12Msps,167=16Msps,247=24Msps
If RateIndex = 17 Then
SamplingRate = 1000000
ElseIf RateIndex = 27 Then
SamplingRate = 2000000
ElseIf RateIndex = 37 Then
SamplingRate = 3000000
ElseIf RateIndex = 47 Then
SamplingRate = 4000000
ElseIf RateIndex = 67 Then
SamplingRate = 6000000
ElseIf RateIndex = 87 Then
SamplingRate = 8000000
ElseIf RateIndex = 127 Then
SamplingRate = 12000000
ElseIf RateIndex = 167 Then
SamplingRate = 16000000
ElseIf RateIndex = 247 Then
SamplingRate = 24000000
End If
' Since this file supports 3 different custom decoders, we need to see which one to run for this pass based on the Parameters string
If CBool(InStr(Parameters.ToUpper, "CHANGE")) Then
' Sample Decoder that just detects when a signal changes state
' The signal to use for the detection is specified in the Parameters as the second parameter
Dim Params() = Parameters.Split(CChar(" ,-"))
Dim SignalToUse As Double = Val(Params(1))
Dim SignalMask As Integer = 1 << CInt(SignalToUse) ' Make the mask that will mask off the channel we want in the sample
' Now go from the start of the samples to the end and process the decoder
For Sample = 0 To NumberOfSamples - 1
' This example decoder places a label at every transition of a digital signal
Dim DigitalChannel As UInteger = CUInt(SampleData(Sample) And SignalMask)
If DigitalChannel <> OldSample Then
WriteEntry(BW, CUInt(Sample), CUInt(Sample + 100), "Changed!")
End If
OldSample = DigitalChannel
Next
ElseIf CBool(InStr(Parameters.ToUpper, "RISE")) Then
' Sample Decoder that just detects when a signal changes state
' The signal to use for the detection is specified in the Parameters as the second parameter
Dim Params() = Parameters.Split(CChar(" ,-"))
Dim SignalToUse As Double = Val(Params(1))
Dim SignalMask As Integer = 1 << CInt(SignalToUse) ' Make the mask that will mask off the channel we want in the sample
' Now go from the start of the samples to the end and process the decoder
For Sample = 0 To NumberOfSamples - 1
' This example decoder places a label at every transition of digital signal 0
Dim DigitalChannel As UInteger = CUInt(SampleData(Sample) And SignalMask)
If (DigitalChannel <> OldSample) And (OldSample = 0) Then
WriteEntry(BW, CUInt(Sample), CUInt(Sample + 100), "Rise!")
End If
OldSample = DigitalChannel
Next
ElseIf CBool(InStr(Parameters.ToUpper, "HELLOWORLD")) Then
' Simplest Decoder Possible
' Print Hello World at the start of the buffer
WriteEntry(BW, 0, 100, "Hello World!")
WriteEntry(BW, GTriggerSample, CUInt(GTriggerSample + 100), "Trigger Is Here!")
WriteEntry(BW, GX1Sample, CUInt(GX1Sample + 100), "X1 Is Here!")
WriteEntry(BW, GX2Sample, CUInt(GX2Sample + 100), "X2 Is Here!")
ElseIf CBool(InStr(Parameters.ToUpper, "NECIR")) Then
' Sample Decoder that just detects when a signal changes state
' The signal to use for the detection is specified in the Parameters as the second parameter
WriteEntry(BW, CUInt(0), CUInt(100), "NEC IR Decoder 3.0")
Dim Params() = Parameters.Split(CChar(" ,-"))
Dim SignalToUse As Double = Val(Params(1))
Dim SignalMask As Integer = 1 << CInt(SignalToUse) 'Make the mask that will mask off the channel we want in the sample
Const LOOKING_FOR_HEADER As Integer = 1
Const LOOKING_FOR_BITS As Integer = 2
Dim DecodeState As Integer = LOOKING_FOR_HEADER ' Holds what state of the decoder we are in
Dim ByteAccumlator As Integer = 0 ' Holds the accumulated bits for each byte
Dim BitCounter As Integer = 0 ' Holds how many bits we have accumulated in this byte so far
Dim ByteStartSample As Integer ' Holds the sample at the start of the byte
Dim Data As UInteger ' Holds the state of the signal at the current sample
Dim tEdge1 As Integer ' Where the first edge is
Dim tEdge2 As Integer ' Where the second edge is
Dim tPulseWidth As Double ' The pulsewidth in seconds
' Now go from the start of the samples to the end and process the signal
For Sample As Integer = 0 To NumberOfSamples - 1
Data = CUInt(SampleData(Sample) And SignalMask)
If DecodeState = LOOKING_FOR_HEADER Then
If Data <> 0 Then
' We found a High which starts the Header
' Now look for the next edge
tEdge1 = WhereIsTheNextEdge(Sample, SignalMask, NumberOfSamples)
If tEdge1 >= 0 Then
' Check to see if this falling edge is in the right timeframe
tPulseWidth = (tEdge1 - Sample) / SamplingRate
If (tPulseWidth >= 0.008) And (tPulseWidth <= 0.01) Then
' Now look for the rising edge
tEdge2 = WhereIsTheNextEdge(tEdge1, SignalMask, NumberOfSamples)
If tEdge2 >= 0 Then
' Check to see if this rising edge is in the right timeframe
tPulseWidth = (tEdge2 - tEdge1) / SamplingRate
If (tPulseWidth >= 0.004) And (tPulseWidth <= 0.005) Then
' Great!Valid Header Format!Look for bits from this point on
' Write out a Header Marker (remove this if you don't need the header)
WriteEntry(BW, CUInt(Sample), CUInt(tEdge2), "Lead Code")
DecodeState = LOOKING_FOR_BITS
Sample = tEdge2
' Initialize the Byte Accumulation variables
ByteStartSample = Sample
ByteAccumlator = 0
BitCounter = 0
Continue For
ElseIf (tPulseWidth >= 0.002) And (tPulseWidth <= 0.003) Then
' Great!Valid Repeat Format!
' Find the next falling edge to complete the Repeat
tEdge2 = WhereIsTheNextEdge(tEdge2, SignalMask, NumberOfSamples)
' Write out a Repeat Marker (remove this if you don't need the Repeat)
WriteEntry(BW, CUInt(Sample), CUInt(tEdge2), "Repeat")
Sample = tEdge2
Continue For
Else
' Pulse is not the right size so bail and keep looking
Sample = tEdge2
Continue For
End If
Else
' No edges at all!So we are done
Exit For
End If
Else
' Pulse is not the right size so bail and keep looking
Sample = tEdge1
Continue For
End If
Else
' No edges at all!So we are done
Exit For
End If
End If
ElseIf DecodeState = LOOKING_FOR_BITS Then
If BitCounter = 8 Then
' We have an entire byte worth of data so output the information
WriteEntry(BW, CUInt(ByteStartSample), CUInt(tEdge2), Hex(ByteAccumlator))
BitCounter = 0
ByteAccumlator = 0
End If
If Data <> 0 Then
' We found a High which starts the bit
' Now look for the next edge
tEdge1 = WhereIsTheNextEdge(Sample, SignalMask, NumberOfSamples)
If tEdge1 >= 0 Then
' Check to see if this falling edge is in the right timeframe
tPulseWidth = (tEdge1 - Sample) / SamplingRate
If (tPulseWidth >= 0.0005) And (tPulseWidth <= 0.0007) Then
' Good start of a bit
' Now look for the rising edge
tEdge2 = WhereIsTheNextEdge(tEdge1, SignalMask, NumberOfSamples)
If tEdge2 >= 0 Then
' Check to see if this rising edge is in the right timeframe for a logic "0"
tPulseWidth = (tEdge2 - tEdge1) / SamplingRate
If (tPulseWidth >= 0.0004) And (tPulseWidth <= 0.0006) Then
' Great!Valid 0 Bit Format!
' Write out a Bit Marker (remove this if you don't need the bit)
'WriteEntry(BW, CUInt(Sample), CUInt(tEdge2), "0")
' Add this bit to the accumulators (LSB first)
ByteAccumlator = ByteAccumlator >> 1 ' Shift the Accumulator
ByteAccumlator = ByteAccumlator And &H7F ' Clear out the MSBit
' Mark the start of the byte if so
If BitCounter = 0 Then ByteStartSample = Sample
' Next Bit next time
BitCounter = BitCounter + 1
Sample = tEdge2
Continue For
ElseIf (tPulseWidth >= 0.001) And (tPulseWidth <= 0.002) Then
' Great!Valid 1 Bit Format!
' Write out a Bit Marker (remove this if you don't need the bit)
'WriteEntry(BW, CUInt(Sample), CUInt(tEdge2), "1")
' Add this bit to the accumulators (LSB first)
ByteAccumlator = ByteAccumlator >> 1 ' Shift the Accumulator
ByteAccumlator = ByteAccumlator Or &H80 ' Set the MSBit
' Mark the start of the byte if so
If BitCounter = 0 Then ByteStartSample = Sample
' Next Bit next time
BitCounter = BitCounter + 1
Sample = tEdge2
Continue For
Else
' Pulse is not the right size so bail and keep looking
DecodeState = LOOKING_FOR_HEADER
Sample = tEdge2
Continue For
End If
Else
' No edges at all!So we are done
Exit For
End If
Else
' Pulse is not the right size so bail and keep looking
Sample = tEdge1
DecodeState = LOOKING_FOR_HEADER
Continue For
End If
Else
' No edges at all!So we are done
Exit For
End If
End If
End If
Next
End If
' Close the Output File
FS.Close()
Catch ex As Exception
End Try
End Sub
Public Function WhereIsTheNextEdge(ByVal tSample As Integer, ByVal tSignalMask As Integer, ByVal NumberOfSamples As Integer) As Integer
' This function finds where the next edge is starting at Sample tSample
Dim OldData As UInteger = CUInt(SampleData(tSample) And tSignalMask)
For Sample As Integer = tSample To NumberOfSamples - 1
Dim Data As UInteger = CUInt(SampleData(Sample) And tSignalMask)
If Data <> OldData Then
Return Sample
End If
Next
Return -1
End Function
Public Sub WriteEntry(ByRef BW As BinaryWriter, ByVal StartSample As UInt32, ByVal EndSample As UInt32, ByRef TextString As String)
' DO NOT CHANGE THIS ROUTINE!!!
' This routine writes the Entry in the file format that is used by the Custom Decoder
' This entry specifies the Start Sample, End Sample and the text string to display
Try
BW.Write(StartSample)
BW.Write(EndSample)
' Write the length of the string in bytes (include the 0 at the end in the count)
Dim tStrLen As UInt32
tStrLen = CUInt(TextString.Length + 1)
BW.Write(tStrLen)
' Now write out the characters one byte at a time and put a 0 at the end
For x As Integer = 0 To CInt(tStrLen - 2)
BW.Write(CByte(Asc(TextString.Chars(x))))
Next
BW.Write(CByte(0))
Catch ex As Exception
End Try
End Sub
End Class
本帖最后由 huangqi412 于 2016-8-5 17:45 编辑
xf331785508 发表于 2016-8-5 17:24
你这主要就是把这个“CustomUSBeeSuiteDecoder.vb”转换一下就可以了嘛。这个是原代码吧?
...
不是VB代码问题,代码问题不会很大,是建立DEMO工程的问题。
先把VB代码精简了测试 最终精简成这样了编译出的DLL可以使用就一个CLASS带2个空函数
先后在VS2010下建立各种VC工程,C#工程 仿照VB建立CLASS和空函数弄出来的DLL都没法用, USBEE手册已经明确说了支持VS2008及以后版本的各种语言重写 对上位机只限于用VC拖按钮做个小程序,实在没招。
不知道要怎么建立个能让USBEE正常识别的DEMO。
Option Explicit On
Option Strict On
Imports System.IO
‘将代码最简化测试只剩下一个CLASS带2个空函数将这个转成别的语言
Public Class CustomUSBeeSuiteDecoder '类名必须叫这个
'获取光标这个函数必须要有
Public Sub SetCaptureParameters(ByVal TriggerSample As UInteger, ByVal X1Sample As UInteger, ByVal X2Sample As UInteger)
End Sub
'解码数据这个函数必须要有
Public Sub DecodeCustom(ByVal OutFilename As String, ByVal NumberOfSamples As Integer, ByVal RateIndex As Byte, ByVal Parameters As String)
End Sub
End Class
用Saleae的,有demo 1.CustomUSBeeSuiteDecoder.dll必须要与usbeeste.dll放在同一目录下.
主要原因就是这句:
Declare Function SampleData Lib "usbeeste.dll" Alias "?LoggedData@@YGJK@Z" (ByVal Index As Integer) As UInteger
2.可以通过托管vc直接调用CustomUSBeeSuiteDecoder.dll中的函数.
vc调用vb.net的dll网上有方法,不过看了几篇也是很麻烦的事.祝楼主好运.
高级语言调用低级的简单,低级调用高级的麻烦.
可以再包一层皮啊~
如果是VB的话,也可以编译成支持CLI的版本,用比较新的VS,实际上你现在的版本就应该已经支持了。
然后就回到M$的统一框架下了,VC和C#都可以通过Dllimport调用你这个和“目标程序接口”是好的DLL,至于这个DLL里面要干嘛,你大可以另写一个程序,让这个VB工程去调用,相当于callback的形式。
只需要一个确定好用的框架和接口,你现在框架是有的,所以你可能还需要研究一下VB引入外部工程的方式,我只搞过C#的。
但是一旦知道那个DLL里面都有什么(所谓的资源,类,函数什么的),声明引入后就可以直接用,很爽的~ e1ki0lp 发表于 2016-8-5 22:36
1.CustomUSBeeSuiteDecoder.dll必须要与usbeeste.dll放在同一目录下.
主要原因就是这句:
Declare Function...
额,先不看代码, 不管这个加载DLL 现在已经把VB代码简化成一个CLASS带2个空函数了,照着各种建VC C#工程,生成的DLL都没法用。 error_dan 发表于 2016-8-5 22:43
可以再包一层皮啊~
如果是VB的话,也可以编译成支持CLI的版本,用比较新的VS,实际上你现在的版本就应该已 ...
能否给个DEMO,谢谢。VB代码已经简化成一个CLASS带2个空函数。 本帖最后由 gylg3344love 于 2016-8-6 09:44 编辑
才这么点莫元啊,不过我想来挑战一下 .没看到需要调用.Net的地方啊? {:sweat:}实在折腾不来的话,下次要用还得接着用VB了。
额,上面各位回复没看太懂,不确定我描述清楚了没。 USBEE.exe是逻辑仪软件,调用一个CustomUSBeeSuiteDecoder.DLL解码,这个DLL有VB源码工程可以自己修改,手册也说可以将这个VB的DLL工程改成VS2008以后的其他语言写,这不电工都习惯用C么,想将这个VB的DLL工程改成C工程。 VB代码已经简化成一个CLASS带2个空函数编译成DLL后拷给EXE用没问题,但是各种建VC ,C#的DLL工程写个CLASS带两空函数给EXE用都报错列表不符合还是什么的 所以首要问题不是代码,是建的工程都不行。 本帖最后由 huangqi412 于 2016-8-6 09:57 编辑
gylg3344love 发表于 2016-8-6 09:36
才这么点莫元啊,不过我想来挑战一下 .没看到需要调用.Net的地方啊?
{:lol:} 发悬赏贴随手的数,我看看貌似我有上千莫元?莫元花出去了不会掉等级进不了非技术版吧,如何在帖子悬赏再加莫元。
USBEE是个好东西啊,把自定义解码工程改成C工程,就跟写IO模拟IIC时序,SPI时序的单片机程序差不多了,造福广大电工自己解码。 huangqi412 发表于 2016-8-6 09:55
发悬赏贴随手的数,我看看貌似我有上千莫元?莫元花出去了不会掉等级进不了非技术版吧,如何在 ...
这个怎么测试我写的对不对,是不是还要一台逻辑分析仪才能试这个解码对不对? gylg3344love 发表于 2016-8-6 10:01
这个怎么测试我写的对不对,是不是还要一台逻辑分析仪才能试这个解码对不对? ...
不用硬件测试,只要安装USBEE suite软件(论坛似乎就有), 打开目录下的DEMO波形文件,
双击波形左侧弹出解码对话框,选择自定义,输入参数后会解码显示。 手册有具体说明。 huangqi412 发表于 2016-8-6 10:09
不用硬件测试,只要安装USBEE suite软件(论坛似乎就有), 打开目录下的DEMO波形文件,
双击波形左侧弹 ...
要输入参数.怎么输入.输入了好像没反应 本帖最后由 huangqi412 于 2016-8-6 11:07 编辑
gylg3344love 发表于 2016-8-6 10:30
要输入参数.怎么输入.输入了好像没反应
0安装USBEE软件
1打开USBEE SUITE安装目录下的demo波形文件,菜单setup->quite setup 8dig ch,波形通道0左侧双击弹出channel Settings对话框,custom标签页 输入大写 HELLOWORLD点SAVE 波形0最左侧会显示helloworld标签,验证了软件运行OK. 点击file->save as cap保存,下次打开会自动使用以前选择的解码设置。
2安装目录下CustomUSBeeSuiteDecoder 下的VB工程BUILD,拷贝生成的DLL到安装目录下 再打开刚才SAVE的波形文件,验证原始VB工程没问题
3简化VB工程中代码,只留着简化代码生成DLL拷贝到安装目录下,打开波形文件运行没问题话先撇开代码问题。
4新建其他语言的DLL工程,生成DLL拷贝到安装目录下
输入没反应没事,只要USBEE SUITE软件没弹出错误对话框就行,说明DLL没问题。 我用VC和C#生成的DLL拷过去EXE出错误窗口然后自动关闭。
操 ..Net的工程.不懂.普通的VB还是没问题的 bbs2009 发表于 2016-8-6 11:25
这个其实也有难度。
虽然说 DLL 可以在不同的编译器编译的程序间调用 , 但实际做起来 想处处通用 还是 ...
有没可能保留vb. 新写个vc.然后vb的dll调用vc的dllvb的相当vc的一层皮
原工程里vb就是导入了另一个dll中一个函数啊 bbs2009 发表于 2016-8-6 11:57
早年间 用 VB6 写程序 , 不喜欢VB的语法, 做算法不如 C 痛快, 就写一个 DLL , 让 VB 调用。
你保留 V ...
对上位机只限于对话框工程这个不懂手册but can easily be ported to C or other language supported in Visual Studio.说的跟和蛋汤一样 我以为新建个工程就完事 看来不是很容易? bbs2009 发表于 2016-8-6 11:57
早年间 用 VB6 写程序 , 不喜欢VB的语法, 做算法不如 C 痛快, 就写一个 DLL , 让 VB 调用。
你保留 V ...
这样理论上只剩下vb的dll调用vc的dll了 bbs2009 发表于 2016-8-6 11:52
实在折腾不来的话,下次要用还得接着用VB了。
额,上面各位回复没看太懂,不确定我描述清楚了 ... ...
实际上安装目录下还有个addin的vc的dll工程 也是给同一个exe调用的里面没有class. 就一个函数 bbs2009 发表于 2016-8-6 12:24
SampleData用 VB.net 读出 交给 VC 写的DLL 处理再 返回结果 给 VB.net,注意 VB.net VC.net 之间的数 ...
安装目录下实际上还有个ADDIN的DLL是VC工程,生成的DLL也是被USBEE SUITE.EXE调用,所以VC生成DLL给USBEE SUITE.EXE调用是没问题的
新建VC对话框工程调用usbeeste.dll 的?LoggedData@@YGJK@Z也测试过可以。 所以VC调用这个DLL也没问题,而且这个问题先忽略后面再看,先解决工程问题才是关键。
但是在ADDIN的工程里修改代码添加一个CLASS带2个空函数生成DLL不能识别,弹错误框关闭
System.BadImageFormatException”类型的未经处理的异常出现在 mscorlib.dll 中。
其他信息: 未能加载文件或程序集“CustomUSBeeSuiteDecoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。该模块应包含一个程序集清单。
按道理手册也说很容易换别的语言,又自带了一个VC工程的DLL,应该没什么问题吧。
“未能加载文件或程序集,应该包含清单。” 从错误看应该是DLL搞的不对 识别不到DLL中的函数吧。 大神能否帮看看。 bbs2009 发表于 2016-8-6 12:24
SampleData用 VB.net 读出 交给 VC 写的DLL 处理再 返回结果 给 VB.net,注意 VB.net VC.net 之间的数 ...
addin生成的DLL , 下了个DLL查看工具感觉跟usbeeste.dll 是一个调调, 推测usbeeste.dll 是VC生成的,虽然不懂DLL. 另建一个VC的DLL工程给现有的VB的DLL工程调用经过测试可行
VC_DLL:
CWAV_EXPORT unsigned int CWAV_APIaa( unsigned long a )
{
return a+5;
}
CWAV_EXPORT unsigned int CWAV_APIbb( unsigned long b )
{
return b-5;
}
VB_DLL:
Declare Function add_5 Lib "ab.dll" Alias "?aa@@YGIK@Z" (ByVal Index As UInteger) As UInteger
Declare Function dec_5 Lib "ab.dll" Alias "?bb@@YGIK@Z" (ByVal Index As UInteger) As UInteger
Dim a_v As ULong '测试函数A
Dim b_v As ULong '测试函数B
a_v = add_5(10) ‘VB的DLL调用VC的DLL中的函数
b_v = dec_5(10)
WriteEntry(BW, 3000, 3100, CStr(a_v))'计算结果显示=15
WriteEntry(BW, 5000, 5100, CStr(b_v))’计算结果显示=5
这做法感觉蛋蛋疼的难受。。。还是希望能直接用VC代替VB. 要新建一个解决方案,包含两个工程,编译后把两个DLL都拷贝到安装目录。 VB的那个DLL在DLL查看工具下是空的 看不到里面函数是因为里面是CLASS还是因为VB的缘故?
看不到函数,VC的DLL没法反向调用了。只能写函数把VB的函数指针传给VC? VC调用usbeeste.dll自然没问题,VB也不调用usbeeste.dll了 现在VB真是层皮了, VB仅仅是一个CLASS带2个空函数,空函数里就一句话:调用VC中一模一样函数。 本帖最后由 huangqi412 于 2016-8-6 15:15 编辑
接下来真是语法问题了
1VB的STRING怎么传递给VC
2VB里这段怎么变成VC
Dim FS As New FileStream(OutFilename, FileMode.Append, FileAccess.Write)
Dim BW As New BinaryWriter(FS)
3怎么把一个VB函数的地址传递给VC
本帖最后由 huangqi412 于 2016-8-6 17:43 编辑
想了下,VB里别的可以不变,把具体解码过程放到VC里。VB把采样长度和速率告诉VC, VC自己调用usbeeste.dll 一个个采样数据去处理测试没一点问题。现在问题在于如何显示解码结果。比如可能平均处理10个采样点就要输出一个显示标签,VC怎么显示。
1 显示函数留在VB中,VC如何获得句柄调用VB中这个显示函数,特别是接口参数类型。最直观,VC只管“写单片机IO模拟IIC时序函数并输出调试信息”
2 显示函数也放到VC中去,也是要解决接口参数STRING,粗略试了下用lpstr应该是能有办法对接上,具体代码不熟, 打开流文件FileStream这里代码不知道怎么写,感觉应该比上面更简单,也更彻底。
3 VC脱离这里显示, 自己create一个文件一股脑的写,写的结果不能显示在图形界面上,只能自己事后用TXT看。这个倒是应该不难,跟VB没毛钱关系了,{:sweat:}但这个更蛋疼一层了,还是用1或2好些。
so,上位机高手们指点一下吧,现在只剩纯语法问题了,工程问题没了。 问题变成了将如下两个函数转换成功能一模一样的C代码了 高手们帮帮忙
'打印函数 二进制打印到流文件
Public Sub WriteEntry1(ByRef BW As BinaryWriter, ByVal StartSample As UInt32, ByVal EndSample As UInt32, ByRef TextString As String)
BW.Write(StartSample)
BW.Write(EndSample)
Dim tStrLen As UInt32 '长度包括字符串末尾的0
tStrLen = CUInt(TextString.Length + 1)
BW.Write(tStrLen)
For x As Integer = 0 To CInt(tStrLen - 2)
BW.Write(CByte(Asc(TextString.Chars(x))))
Next
BW.Write(CByte(0))
End Sub
'创建流文件和打印
Public Sub DecodeCustom1(ByVal OutFilename As String, ByVal NumberOfSamples As Integer, ByVal RateIndex As Byte, ByVal Parameters As String)
'流文件
Dim FS As New FileStream(OutFilename, FileMode.Append, FileAccess.Write)
Dim BW As New BinaryWriter(FS)
Dim va As ULong’测试
Dim str As String
va = 100
str = "hello"
WriteEntry(BW, 3000, 3500, CStr(va))
WriteEntry(BW, 7000, 7500, str)
End Sub bbs2009 发表于 2016-8-6 23:29
FileStream Class
参考
https://msdn.microsoft.com/en-us/library/system.io.filestream(v=vs.110).aspx
.net.完全搞不懂啊 还有第四种方法 vc将解析结果存在buf解析完后vb获取buf长度并且全部提取显示 huangqi412 发表于 2016-8-7 06:58
还有第四种方法 vc将解析结果存在buf解析完后vb获取buf长度并且全部提取显示 ...
第四种方法测试成功,已经可以用纯C解码并且在界面上显示,功能实现了但是这玩意看起来绕的蛋蛋疼啊。。。
VC搞定了与VB接口的参数类型STRING问题双向传递参数接口没问题了
方法0已经是死胡同,完全不知道怎么建个VC工程替代这个VB的DLL
遇到.NET完全不懂,所以VC不知道怎么搞流文件实现显示函数。 也不知道如何传递VB的函数指针给VC,让VC反向调用VB的显示函数,更没招VC反向调用VB.NET的DLL。 这样方法1和2短时间都搞不定 其实上位机熟的人应该很容易搞定方法2
方法3简直太粗暴了,完全是另起炉灶,自己粗暴新写文件的下一步就得是折腾自己做显示了,那还搞个屁,完全是另起一套。
方法4虽然蛋疼,介于12和3之间,平衡粗暴和复杂,最容易实现最容易接受。
具体如下:
VC一个解码函数做解码,解码完的输出暂存到一个大数组里包含一共有多少个显示标签,每个显示标签起点终点字符串内容和字符串颜色。 提供接口给VB按索引返回指定索引号的标签数据(起点终点内容颜色)
VB保留主函数壳子和显示函数,VB主程序传递参数(采样点数,采样频率,解码通道,解码协议名,协议参数)调用VC解码函数,解码完获取解码生成了多少个标签,创建流文件,FOR循环GET所有的标签内容调用显示函数做显示。
现在比较乱,整理好以后就可以不动VB工程,只需要修改VC代码,万恶的VB拜拜,给个DEMO工程电工都可以用写单片机IIC/SPI模拟时序方法任意解码了(个别只用汇编的电工除外)。 兄弟.把里面的函数移植完了麻烦回传一份.函数入口我已经给你改好了 VB .NET 和vb只是长的像.里面的东西全都换过来了DNA 不一样
gylg3344love 发表于 2016-8-7 18:21
兄弟.把里面的函数移植完了麻烦回传一份.函数入口我已经给你改好了
没问题这几天先暂停了 过几天整理好发出来 中间停了几天,今天上午拿出来重新开干。
方法4很快变成了实例,写了个DEMO例子输入不同参数解码不同协议:pluexxx解码宽度>xxx的高脉冲,changeN,XX解码通道N上滤波xx的跳变, equalNNN解码任意指定三条线相等的地方。 虽然功能实现,但看实现方法和代码简直不能更蛋疼了,强迫症电工肯定会不忍直视。
中午果断琢磨折回方法2,方法2接近于方法0的程度=接近完美。PC真是好,不比单片机,可以各种调试各种抓各种看,几分钟就找到办法了,相比起来单片机就是苦逼啊。 上周研究了两天怎么用C替代VB语句,还语法语法的折腾全TMD瞎JB折腾,用工具抓到VB写文件的动作后,直接把2个VB函数架空成壳子,根本不用考虑那么多,直接用C创建文件再写文件,写完CLOSE就行, USBEE.exe其实就是调用DECODER函数去创建一个TXT填充内容,调用完了就读TXT显示内容而已,EXE读和DLL写时间是错开的,根本不用考虑任何冲突或者神马的问题,纯C代码真是满满的幸福感,用C喜欢怎么创建就怎么创建,喜欢怎么写就怎么写,写完别忘记CLOSE退出就行。连文件路径都是固定的。
结论就是上周都是瞎JB折腾了这么多,吐血了,最后解决办法竟然是如此简单,效果接近完美。会纯C的电工照我说的都很容易搞定,所以就不上代码工程了。 方法0估计是永远搞不定了,这个不知道USBEE.EXE是怎么写的,更搞不懂.NET和DLL,建的各种VC C#的DLL工程都不能被EXE识别,有方法2也不在意方法0了。 怎么结贴,似乎应该结给自己{:sweat:} 自定义解码没有event输出 看了下,感觉用工具做深入分析应该是可以自己造出event 我是把这个东西移植成了C++ CLI了.感觉没啥用啊 得.一分都没赚到..
页:
[1]