搜索
bottom↓
回复: 48

哪位能帮把USBEE逻辑仪自定义解码的VB工程转成VC工程

[复制链接]

出0入0汤圆

发表于 2016-8-4 15:47:52 | 显示全部楼层 |阅读模式
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工程就都能自己改了重编译。   工程已经从安装目录打包上来,  谢谢。


阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
头像被屏蔽

出0入0汤圆

发表于 2016-8-4 15:47:53 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

出0入0汤圆

 楼主| 发表于 2016-8-4 15:49:21 | 显示全部楼层
        原始VB工程打包

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
头像被屏蔽

出0入0汤圆

发表于 2016-8-5 11:55:55 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

出0入0汤圆

 楼主| 发表于 2016-8-5 12:01:19 | 显示全部楼层
bbs2009 发表于 2016-8-5 11:55
感觉这么折腾 还不如用 VB.net  方便。  也不是多大的程序 , VB.net  也没那么难。 装 VS2008 也不难。

...

vc2008 以后版本啊  

出0入0汤圆

发表于 2016-8-5 17:24:07 | 显示全部楼层
你这主要就是把这个“CustomUSBeeSuiteDecoder.vb”转换一下就可以了嘛。这个是原代码吧?
  1. Option Explicit On
  2. Option Strict On
  3. Imports System.IO


  4. Public Class CustomUSBeeSuiteDecoder

  5.     Declare Function SampleData Lib "usbeeste.dll" Alias "?LoggedData@@YGJK@Z" (ByVal Index As Integer) As UInteger
  6.     ' The SampleData routine returns a 4 byte value that contains a single sample of all the signals
  7.     ' The format of the 32 bits is as follows:
  8.     '
  9.     ' MSB                          LSB
  10.     ' XXXXXXXXYYYYYYYYFEDCBA9876543210
  11.     '
  12.     ' where XXXXXXXX is Channel 2 Analog value (0=-10V, 255 = +10V)
  13.     '       YYYYYYYY is Channel 1 Analog value (0=-10V, 255 = +10V)
  14.     '       F is logic level (0 or 1) for channel F
  15.     '       E is logic level (0 or 1) for channel E
  16.     '       D is logic level (0 or 1) for channel D
  17.     '       ...
  18.     '       0 is logic level (0 or 1) for channel 0

  19.     Dim GTriggerSample As UInteger
  20.     Dim GX1Sample As UInteger
  21.     Dim GX2Sample As UInteger

  22.     Public Sub SetCaptureParameters(ByVal TriggerSample As UInteger, ByVal X1Sample As UInteger, ByVal X2Sample As UInteger)
  23.         ' 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
  24.         ' custom decoding process.
  25.         GTriggerSample = TriggerSample
  26.         GX1Sample = X1Sample
  27.         GX2Sample = X2Sample

  28.     End Sub


  29.     Public Sub DecodeCustom(ByVal OutFilename As String, ByVal NumberOfSamples As Integer, ByVal RateIndex As Byte, ByVal Parameters As String)
  30.         Dim OldSample As UInteger

  31.         Try

  32.             ' This is a custom bus decoder Processing Routine
  33.             '
  34.             ' The passed in variables are as follows:
  35.             ' OutFilename     - the file that all of the decoded Entries get written to.  This is the file that the USBee Suite
  36.             '                   will read to display the data on the waveline.
  37.             ' NumberOfSamples - How many samples are in the sample buffer
  38.             ' RateIndex       - An index of the sample rate that the samples were taken.  
  39.             '                   17=1Msps,27=2Msps,37=3Msps,47=4Msps,67=6Msps,87=8Msps,127=12Msps,167=16Msps,247=24Msps
  40.             ' Parameters      - User defined string passed from the USBee Suite user interface Channel Setting for the custom decoder.
  41.             '                   Use this string to pass in any parameters that your decoder needs to know, such as what channels to use
  42.             '                   in decoding, which protocol if you have multiple protocols supported here, and how you want the data formatted.

  43.             ' 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.

  44.             ' Setup the File Stream that stores the Output Entry Information
  45.             Dim FS As New FileStream(OutFilename, FileMode.Append, FileAccess.Write)
  46.             Dim BW As New BinaryWriter(FS)
  47.             Dim SamplingRate As Double

  48.             ' Determining the actual sample rate so it can be written in the OutputFile
  49.             '                   17=1Msps,27=2Msps,37=3Msps,47=4Msps,67=6Msps,87=8Msps,127=12Msps,167=16Msps,247=24Msps
  50.             If RateIndex = 17 Then
  51.                 SamplingRate = 1000000
  52.             ElseIf RateIndex = 27 Then
  53.                 SamplingRate = 2000000
  54.             ElseIf RateIndex = 37 Then
  55.                 SamplingRate = 3000000
  56.             ElseIf RateIndex = 47 Then
  57.                 SamplingRate = 4000000
  58.             ElseIf RateIndex = 67 Then
  59.                 SamplingRate = 6000000
  60.             ElseIf RateIndex = 87 Then
  61.                 SamplingRate = 8000000
  62.             ElseIf RateIndex = 127 Then
  63.                 SamplingRate = 12000000
  64.             ElseIf RateIndex = 167 Then
  65.                 SamplingRate = 16000000
  66.             ElseIf RateIndex = 247 Then
  67.                 SamplingRate = 24000000
  68.             End If

  69.             ' Since this file supports 3 different custom decoders, we need to see which one to run for this pass based on the Parameters string
  70.             If CBool(InStr(Parameters.ToUpper, "CHANGE")) Then
  71.                 ' Sample Decoder that just detects when a signal changes state
  72.                 ' The signal to use for the detection is specified in the Parameters as the second parameter

  73.                 Dim Params() = Parameters.Split(CChar(" ,-"))
  74.                 Dim SignalToUse As Double = Val(Params(1))
  75.                 Dim SignalMask As Integer = 1 << CInt(SignalToUse)       ' Make the mask that will mask off the channel we want in the sample

  76.                 ' Now go from the start of the samples to the end and process the decoder
  77.                 For Sample = 0 To NumberOfSamples - 1
  78.                     ' This example decoder places a label at every transition of a digital signal
  79.                     Dim DigitalChannel As UInteger = CUInt(SampleData(Sample) And SignalMask)
  80.                     If DigitalChannel <> OldSample Then
  81.                         WriteEntry(BW, CUInt(Sample), CUInt(Sample + 100), "Changed!")
  82.                     End If
  83.                     OldSample = DigitalChannel
  84.                 Next

  85.             ElseIf CBool(InStr(Parameters.ToUpper, "RISE")) Then
  86.                 ' Sample Decoder that just detects when a signal changes state
  87.                 ' The signal to use for the detection is specified in the Parameters as the second parameter

  88.                 Dim Params() = Parameters.Split(CChar(" ,-"))
  89.                 Dim SignalToUse As Double = Val(Params(1))
  90.                 Dim SignalMask As Integer = 1 << CInt(SignalToUse)       ' Make the mask that will mask off the channel we want in the sample

  91.                 ' Now go from the start of the samples to the end and process the decoder
  92.                 For Sample = 0 To NumberOfSamples - 1
  93.                     ' This example decoder places a label at every transition of digital signal 0
  94.                     Dim DigitalChannel As UInteger = CUInt(SampleData(Sample) And SignalMask)
  95.                     If (DigitalChannel <> OldSample) And (OldSample = 0) Then
  96.                         WriteEntry(BW, CUInt(Sample), CUInt(Sample + 100), "Rise!")
  97.                     End If
  98.                     OldSample = DigitalChannel
  99.                 Next

  100.             ElseIf CBool(InStr(Parameters.ToUpper, "HELLOWORLD")) Then

  101.                 ' Simplest Decoder Possible
  102.                 ' Print Hello World at the start of the buffer

  103.                 WriteEntry(BW, 0, 100, "Hello World!")
  104.                 WriteEntry(BW, GTriggerSample, CUInt(GTriggerSample + 100), "Trigger Is Here!")
  105.                 WriteEntry(BW, GX1Sample, CUInt(GX1Sample + 100), "X1 Is Here!")
  106.                 WriteEntry(BW, GX2Sample, CUInt(GX2Sample + 100), "X2 Is Here!")

  107.             ElseIf CBool(InStr(Parameters.ToUpper, "NECIR")) Then
  108.                 ' Sample Decoder that just detects when a signal changes state
  109.                 ' The signal to use for the detection is specified in the Parameters as the second parameter
  110.                 WriteEntry(BW, CUInt(0), CUInt(100), "NEC IR Decoder 3.0")


  111.                 Dim Params() = Parameters.Split(CChar(" ,-"))
  112.                 Dim SignalToUse As Double = Val(Params(1))
  113.                 Dim SignalMask As Integer = 1 << CInt(SignalToUse)      'Make the mask that will mask off the channel we want in the sample

  114.                 Const LOOKING_FOR_HEADER As Integer = 1
  115.                 Const LOOKING_FOR_BITS As Integer = 2
  116.                 Dim DecodeState As Integer = LOOKING_FOR_HEADER     ' Holds what state of the decoder we are in

  117.                 Dim ByteAccumlator As Integer = 0                   ' Holds the accumulated bits for each byte
  118.                 Dim BitCounter As Integer = 0                       ' Holds how many bits we have accumulated in this byte so far
  119.                 Dim ByteStartSample As Integer                      ' Holds the sample at the start of the byte

  120.                 Dim Data As UInteger                                ' Holds the state of the signal at the current sample
  121.                 Dim tEdge1 As Integer                               ' Where the first edge is
  122.                 Dim tEdge2 As Integer                               ' Where the second edge is
  123.                 Dim tPulseWidth As Double                           ' The pulsewidth in seconds

  124.                 ' Now go from the start of the samples to the end and process the signal
  125.                 For Sample As Integer = 0 To NumberOfSamples - 1

  126.                     Data = CUInt(SampleData(Sample) And SignalMask)

  127.                     If DecodeState = LOOKING_FOR_HEADER Then

  128.                         If Data <> 0 Then
  129.                             ' We found a High which starts the Header
  130.                             ' Now look for the next edge

  131.                             tEdge1 = WhereIsTheNextEdge(Sample, SignalMask, NumberOfSamples)

  132.                             If tEdge1 >= 0 Then

  133.                                 ' Check to see if this falling edge is in the right timeframe
  134.                                 tPulseWidth = (tEdge1 - Sample) / SamplingRate

  135.                                 If (tPulseWidth >= 0.008) And (tPulseWidth <= 0.01) Then

  136.                                     ' Now look for the rising edge

  137.                                     tEdge2 = WhereIsTheNextEdge(tEdge1, SignalMask, NumberOfSamples)

  138.                                     If tEdge2 >= 0 Then
  139.                                         ' Check to see if this rising edge is in the right timeframe
  140.                                         tPulseWidth = (tEdge2 - tEdge1) / SamplingRate
  141.                                         If (tPulseWidth >= 0.004) And (tPulseWidth <= 0.005) Then
  142.                                             ' Great!  Valid Header Format!  Look for bits from this point on

  143.                                             ' Write out a Header Marker (remove this if you don't need the header)
  144.                                             WriteEntry(BW, CUInt(Sample), CUInt(tEdge2), "Lead Code")

  145.                                             DecodeState = LOOKING_FOR_BITS
  146.                                             Sample = tEdge2

  147.                                             ' Initialize the Byte Accumulation variables
  148.                                             ByteStartSample = Sample
  149.                                             ByteAccumlator = 0
  150.                                             BitCounter = 0

  151.                                             Continue For
  152.                                         ElseIf (tPulseWidth >= 0.002) And (tPulseWidth <= 0.003) Then
  153.                                             ' Great!  Valid Repeat Format!  

  154.                                             ' Find the next falling edge to complete the Repeat
  155.                                             tEdge2 = WhereIsTheNextEdge(tEdge2, SignalMask, NumberOfSamples)

  156.                                             ' Write out a Repeat Marker (remove this if you don't need the Repeat)
  157.                                             WriteEntry(BW, CUInt(Sample), CUInt(tEdge2), "Repeat")

  158.                                             Sample = tEdge2
  159.                                             Continue For

  160.                                         Else
  161.                                             ' Pulse is not the right size so bail and keep looking
  162.                                             Sample = tEdge2
  163.                                             Continue For
  164.                                         End If
  165.                                     Else
  166.                                         ' No edges at all!  So we are done
  167.                                         Exit For
  168.                                     End If

  169.                                 Else
  170.                                     ' Pulse is not the right size so bail and keep looking
  171.                                     Sample = tEdge1
  172.                                     Continue For
  173.                                 End If
  174.                             Else
  175.                                 ' No edges at all!  So we are done
  176.                                 Exit For
  177.                             End If

  178.                         End If

  179.                     ElseIf DecodeState = LOOKING_FOR_BITS Then

  180.                         If BitCounter = 8 Then
  181.                             ' We have an entire byte worth of data so output the information
  182.                             WriteEntry(BW, CUInt(ByteStartSample), CUInt(tEdge2), Hex(ByteAccumlator))
  183.                             BitCounter = 0
  184.                             ByteAccumlator = 0
  185.                         End If

  186.                         If Data <> 0 Then
  187.                             ' We found a High which starts the bit
  188.                             ' Now look for the next edge

  189.                             tEdge1 = WhereIsTheNextEdge(Sample, SignalMask, NumberOfSamples)

  190.                             If tEdge1 >= 0 Then

  191.                                 ' Check to see if this falling edge is in the right timeframe
  192.                                 tPulseWidth = (tEdge1 - Sample) / SamplingRate

  193.                                 If (tPulseWidth >= 0.0005) And (tPulseWidth <= 0.0007) Then
  194.                                     ' Good start of a bit
  195.                                     ' Now look for the rising edge

  196.                                     tEdge2 = WhereIsTheNextEdge(tEdge1, SignalMask, NumberOfSamples)

  197.                                     If tEdge2 >= 0 Then
  198.                                         ' Check to see if this rising edge is in the right timeframe for a logic "0"
  199.                                         tPulseWidth = (tEdge2 - tEdge1) / SamplingRate
  200.                                         If (tPulseWidth >= 0.0004) And (tPulseWidth <= 0.0006) Then
  201.                                             ' Great!  Valid 0 Bit Format!  

  202.                                             ' Write out a Bit Marker (remove this if you don't need the bit)
  203.                                             'WriteEntry(BW, CUInt(Sample), CUInt(tEdge2), "0")

  204.                                             ' Add this bit to the accumulators (LSB first)
  205.                                             ByteAccumlator = ByteAccumlator >> 1    ' Shift the Accumulator
  206.                                             ByteAccumlator = ByteAccumlator And &H7F ' Clear out the MSBit

  207.                                             ' Mark the start of the byte if so
  208.                                             If BitCounter = 0 Then ByteStartSample = Sample

  209.                                             ' Next Bit next time
  210.                                             BitCounter = BitCounter + 1

  211.                                             Sample = tEdge2
  212.                                             Continue For
  213.                                         ElseIf (tPulseWidth >= 0.001) And (tPulseWidth <= 0.002) Then
  214.                                             ' Great!  Valid 1 Bit Format!  

  215.                                             ' Write out a Bit Marker (remove this if you don't need the bit)
  216.                                             'WriteEntry(BW, CUInt(Sample), CUInt(tEdge2), "1")

  217.                                             ' Add this bit to the accumulators (LSB first)
  218.                                             ByteAccumlator = ByteAccumlator >> 1    ' Shift the Accumulator
  219.                                             ByteAccumlator = ByteAccumlator Or &H80 ' Set the MSBit

  220.                                             ' Mark the start of the byte if so
  221.                                             If BitCounter = 0 Then ByteStartSample = Sample

  222.                                             ' Next Bit next time
  223.                                             BitCounter = BitCounter + 1

  224.                                             Sample = tEdge2
  225.                                             Continue For

  226.                                         Else
  227.                                             ' Pulse is not the right size so bail and keep looking
  228.                                             DecodeState = LOOKING_FOR_HEADER
  229.                                             Sample = tEdge2
  230.                                             Continue For
  231.                                         End If
  232.                                     Else
  233.                                         ' No edges at all!  So we are done
  234.                                         Exit For
  235.                                     End If

  236.                                 Else
  237.                                     ' Pulse is not the right size so bail and keep looking
  238.                                     Sample = tEdge1
  239.                                     DecodeState = LOOKING_FOR_HEADER
  240.                                     Continue For
  241.                                 End If
  242.                             Else
  243.                                 ' No edges at all!  So we are done
  244.                                 Exit For
  245.                             End If

  246.                         End If

  247.                     End If
  248.                 Next

  249.             End If

  250.             ' Close the Output File
  251.             FS.Close()

  252.         Catch ex As Exception

  253.         End Try

  254.     End Sub

  255.     Public Function WhereIsTheNextEdge(ByVal tSample As Integer, ByVal tSignalMask As Integer, ByVal NumberOfSamples As Integer) As Integer
  256.         ' This function finds where the next edge is starting at Sample tSample

  257.         Dim OldData As UInteger = CUInt(SampleData(tSample) And tSignalMask)

  258.         For Sample As Integer = tSample To NumberOfSamples - 1

  259.             Dim Data As UInteger = CUInt(SampleData(Sample) And tSignalMask)

  260.             If Data <> OldData Then
  261.                 Return Sample
  262.             End If

  263.         Next

  264.         Return -1

  265.     End Function

  266.     Public Sub WriteEntry(ByRef BW As BinaryWriter, ByVal StartSample As UInt32, ByVal EndSample As UInt32, ByRef TextString As String)

  267.         ' DO NOT CHANGE THIS ROUTINE!!!
  268.         ' This routine writes the Entry in the file format that is used by the Custom Decoder
  269.         ' This entry specifies the Start Sample, End Sample and the text string to display
  270.         Try

  271.             BW.Write(StartSample)
  272.             BW.Write(EndSample)

  273.             ' Write the length of the string in bytes (include the 0 at the end in the count)
  274.             Dim tStrLen As UInt32
  275.             tStrLen = CUInt(TextString.Length + 1)
  276.             BW.Write(tStrLen)

  277.             ' Now write out the characters one byte at a time and put a 0 at the end
  278.             For x As Integer = 0 To CInt(tStrLen - 2)
  279.                 BW.Write(CByte(Asc(TextString.Chars(x))))
  280.             Next
  281.             BW.Write(CByte(0))

  282.         Catch ex As Exception

  283.         End Try


  284.     End Sub

  285. End Class
复制代码

出0入0汤圆

 楼主| 发表于 2016-8-5 17:43:40 | 显示全部楼层
本帖最后由 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

出0入0汤圆

发表于 2016-8-5 20:09:31 来自手机 | 显示全部楼层
用Saleae的,有demo

出0入0汤圆

发表于 2016-8-5 22:36:30 | 显示全部楼层
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网上有方法,不过看了几篇也是很麻烦的事.祝楼主好运.

高级语言调用低级的简单,低级调用高级的麻烦.

出0入0汤圆

发表于 2016-8-5 22:43:35 | 显示全部楼层
可以再包一层皮啊~
如果是VB的话,也可以编译成支持CLI的版本,用比较新的VS,实际上你现在的版本就应该已经支持了。
然后就回到M$的统一框架下了,VC和C#都可以通过Dllimport调用你这个和“目标程序接口”是好的DLL,至于这个DLL里面要干嘛,你大可以另写一个程序,让这个VB工程去调用,相当于callback的形式。
只需要一个确定好用的框架和接口,你现在框架是有的,所以你可能还需要研究一下VB引入外部工程的方式,我只搞过C#的。
但是一旦知道那个DLL里面都有什么(所谓的资源,类,函数什么的),声明引入后就可以直接用,很爽的~

出0入0汤圆

 楼主| 发表于 2016-8-6 09:33:15 | 显示全部楼层
e1ki0lp 发表于 2016-8-5 22:36
1.CustomUSBeeSuiteDecoder.dll必须要与usbeeste.dll放在同一目录下.
主要原因就是这句:
Declare Function  ...

额,先不看代码, 不管这个加载DLL     现在已经把VB代码简化成一个CLASS带2个空函数了,照着各种建VC C#工程,生成的DLL都没法用。

出0入0汤圆

 楼主| 发表于 2016-8-6 09:34:41 | 显示全部楼层
error_dan 发表于 2016-8-5 22:43
可以再包一层皮啊~
如果是VB的话,也可以编译成支持CLI的版本,用比较新的VS,实际上你现在的版本就应该已 ...

能否给个DEMO,谢谢。  VB代码已经简化成一个CLASS带2个空函数。

出0入0汤圆

发表于 2016-8-6 09:36:18 | 显示全部楼层
本帖最后由 gylg3344love 于 2016-8-6 09:44 编辑

才这么点莫元啊,不过我想来挑战一下 .没看到需要调用.Net的地方啊?

出0入0汤圆

 楼主| 发表于 2016-8-6 09:44:34 | 显示全部楼层
  实在折腾不来的话,下次要用还得接着用VB了。

额,上面各位回复没看太懂,不确定我描述清楚了没。   USBEE.exe是逻辑仪软件,调用一个CustomUSBeeSuiteDecoder.DLL解码,这个DLL有VB源码工程可以自己修改,手册也说可以将这个VB的DLL工程改成VS2008以后的其他语言写,这不电工都习惯用C么,想将这个VB的DLL工程改成C工程。   VB代码已经简化成一个CLASS带2个空函数编译成DLL后拷给EXE用没问题,但是各种建VC ,C#的DLL工程写个CLASS带两空函数给EXE用都报错列表不符合还是什么的    所以首要问题不是代码,是建的工程都不行。   

出0入0汤圆

 楼主| 发表于 2016-8-6 09:55:40 | 显示全部楼层
本帖最后由 huangqi412 于 2016-8-6 09:57 编辑
gylg3344love 发表于 2016-8-6 09:36
才这么点莫元啊,不过我想来挑战一下 .没看到需要调用.Net的地方啊?


发悬赏贴随手的数,我看看貌似我有上千莫元?  莫元花出去了不会掉等级进不了非技术版吧,如何在帖子悬赏再加莫元。

USBEE是个好东西啊,把自定义解码工程改成C工程,就跟写IO模拟IIC时序,SPI时序的单片机程序差不多了,造福广大电工自己解码。

出0入0汤圆

发表于 2016-8-6 10:01:07 | 显示全部楼层
huangqi412 发表于 2016-8-6 09:55
发悬赏贴随手的数,我看看貌似我有上千莫元?  莫元花出去了不会掉等级进不了非技术版吧,如何在 ...

这个怎么测试我写的对不对,是不是还要一台逻辑分析仪才能试这个解码对不对?

出0入0汤圆

 楼主| 发表于 2016-8-6 10:09:52 | 显示全部楼层
gylg3344love 发表于 2016-8-6 10:01
这个怎么测试我写的对不对,是不是还要一台逻辑分析仪才能试这个解码对不对? ...

不用硬件测试,只要安装USBEE suite软件(论坛似乎就有), 打开目录下的DEMO波形文件,  
双击波形左侧弹出解码对话框,选择自定义,输入参数后会解码显示。   手册有具体说明。

出0入0汤圆

发表于 2016-8-6 10:30:37 | 显示全部楼层
huangqi412 发表于 2016-8-6 10:09
不用硬件测试,只要安装USBEE suite软件(论坛似乎就有), 打开目录下的DEMO波形文件,  
双击波形左侧弹 ...

要输入参数.怎么输入.输入了好像没反应

出0入0汤圆

 楼主| 发表于 2016-8-6 10:58:29 | 显示全部楼层
本帖最后由 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出错误窗口然后自动关闭。

出0入0汤圆

发表于 2016-8-6 11:04:39 | 显示全部楼层
操           ..Net的工程.不懂.普通的VB还是没问题的
头像被屏蔽

出0入0汤圆

发表于 2016-8-6 11:15:33 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
头像被屏蔽

出0入0汤圆

发表于 2016-8-6 11:25:39 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

出0入0汤圆

 楼主| 发表于 2016-8-6 11:52:15 来自手机 | 显示全部楼层
bbs2009 发表于 2016-8-6 11:25
这个其实也有难度。
虽然说 DLL 可以在不同的编译器编译的程序间调用 , 但实际做起来 想处处通用 还是 ...

有没可能保留vb. 新写个vc.  然后vb的dll调用vc的dll  vb的相当vc的一层皮  
原工程里vb就是导入了另一个dll中一个函数啊
头像被屏蔽

出0入0汤圆

发表于 2016-8-6 11:57:08 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

出0入0汤圆

 楼主| 发表于 2016-8-6 12:08:16 来自手机 | 显示全部楼层
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.说的跟和蛋汤一样 我以为新建个工程就完事 看来不是很容易?

出0入0汤圆

 楼主| 发表于 2016-8-6 12:12:00 来自手机 | 显示全部楼层
bbs2009 发表于 2016-8-6 11:57
早年间 用 VB6 写程序 , 不喜欢VB的语法, 做算法不如 C 痛快, 就写一个 DLL , 让 VB 调用。
你保留 V ...

这样理论上只剩下vb的dll调用vc的dll了

出0入0汤圆

 楼主| 发表于 2016-8-6 12:19:02 来自手机 | 显示全部楼层
bbs2009 发表于 2016-8-6 11:52
实在折腾不来的话,下次要用还得接着用VB了。

    额,上面各位回复没看太懂,不确定我描述清楚了 ... ...

实际上安装目录下还有个addin的vc的dll工程 也是给同一个exe调用的  里面没有class. 就一个函数
头像被屏蔽

出0入0汤圆

发表于 2016-8-6 12:24:04 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

出0入0汤圆

 楼主| 发表于 2016-8-6 14:01:26 | 显示全部楼层
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中的函数吧。 大神能否帮看看。

出0入0汤圆

 楼主| 发表于 2016-8-6 14:18:34 | 显示全部楼层
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.

出0入0汤圆

 楼主| 发表于 2016-8-6 14:32:17 | 显示全部楼层
另建一个VC的DLL工程给现有的VB的DLL工程调用经过测试可行
VC_DLL:
CWAV_EXPORT unsigned int CWAV_API  aa( unsigned long a )
{
        return a+5;
}
CWAV_EXPORT unsigned int CWAV_API  bb( 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.

出0入0汤圆

 楼主| 发表于 2016-8-6 14:35:45 | 显示全部楼层
要新建一个解决方案,包含两个工程,编译后把两个DLL都拷贝到安装目录。

出0入0汤圆

 楼主| 发表于 2016-8-6 14:39:56 | 显示全部楼层
VB的那个DLL在DLL查看工具下是空的 看不到里面函数  是因为里面是CLASS还是因为VB的缘故?  
看不到函数,VC的DLL没法反向调用了。只能写函数把VB的函数指针传给VC?

出0入0汤圆

 楼主| 发表于 2016-8-6 14:48:09 | 显示全部楼层
VC调用usbeeste.dll自然没问题,VB也不调用usbeeste.dll了   现在VB真是层皮了,   VB仅仅是一个CLASS带2个空函数,空函数里就一句话:调用VC中一模一样函数。

出0入0汤圆

 楼主| 发表于 2016-8-6 15:08:44 | 显示全部楼层
本帖最后由 huangqi412 于 2016-8-6 15:15 编辑

接下来真是语法问题了
1  VB的STRING怎么传递给VC
2  VB里这段怎么变成VC
   Dim FS As New FileStream(OutFilename, FileMode.Append, FileAccess.Write)
   Dim BW As New BinaryWriter(FS)
3  怎么把一个VB函数的地址传递给VC

出0入0汤圆

 楼主| 发表于 2016-8-6 17:39:56 | 显示全部楼层
本帖最后由 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没毛钱关系了,但这个更蛋疼一层了,还是用1或2好些。

so,上位机高手们指点一下吧,现在只剩纯语法问题了,工程问题没了。

出0入0汤圆

 楼主| 发表于 2016-8-6 17:58:24 | 显示全部楼层
问题变成了将如下两个函数  转换成功能一模一样的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
头像被屏蔽

出0入0汤圆

发表于 2016-8-6 23:29:07 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

出0入0汤圆

 楼主| 发表于 2016-8-7 06:48:53 来自手机 | 显示全部楼层
bbs2009 发表于 2016-8-6 23:29
FileStream Class
参考
https://msdn.microsoft.com/en-us/library/system.io.filestream(v=vs.110).aspx

.net.  完全搞不懂啊

出0入0汤圆

 楼主| 发表于 2016-8-7 06:58:10 来自手机 | 显示全部楼层
还有第四种方法 vc将解析结果存在buf  解析完后vb获取buf长度并且全部提取显示

出0入0汤圆

 楼主| 发表于 2016-8-7 11:39:42 | 显示全部楼层
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模拟时序方法任意解码了(个别只用汇编的电工除外)。  

出0入0汤圆

发表于 2016-8-7 18:21:14 | 显示全部楼层
兄弟.把里面的函数移植完了麻烦回传一份.函数入口我已经给你改好了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2016-8-7 18:38:33 | 显示全部楼层
VB .NET 和vb只是长的像.里面的东西全都换过来了DNA 不一样

出0入0汤圆

 楼主| 发表于 2016-8-7 18:43:50 来自手机 | 显示全部楼层
gylg3344love 发表于 2016-8-7 18:21
兄弟.把里面的函数移植完了麻烦回传一份.函数入口我已经给你改好了

没问题  这几天先暂停了 过几天整理好发出来

出0入0汤圆

 楼主| 发表于 2016-8-10 17:17:42 | 显示全部楼层
中间停了几天,今天上午拿出来重新开干。  
方法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了。

出0入0汤圆

 楼主| 发表于 2016-8-10 17:19:19 | 显示全部楼层
怎么结贴,似乎应该结给自己

出0入0汤圆

 楼主| 发表于 2016-8-10 17:37:25 | 显示全部楼层
自定义解码没有event输出 看了下,感觉用工具做深入分析应该是可以自己造出event

出0入0汤圆

发表于 2016-8-12 09:57:23 | 显示全部楼层
我是把这个东西移植成了C++ CLI了.感觉没啥用啊

出0入0汤圆

发表于 2016-8-12 10:06:03 | 显示全部楼层
得.一分都没赚到..
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-25 19:19

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表