Foxtable(狐表)用户栏目专家坐堂 → vb代码在ft怎么用


  共有2627人关注过本帖树形打印复制链接

主题:vb代码在ft怎么用

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/11/16 9:19:00 [显示全部帖子]

1、全局代码

 

'''全局引用dll,引用的dll在附件中
Public Declare Function API_PCDRead Lib "mi.dll" (ByVal handle As Integer, ByVal deviceAddr As Integer, ByVal mode As Byte, ByVal blk_Addr As Byte, ByVal Num_blk As Byte, ByRef snr As Byte, ByRef Buffer As Byte) As Integer

Public Function myVal(ByVal str As String)
Dim retVal As Integer

retVal = 0
If Len(str) = 1 Then
    If str >= "0" And str <= "9" Then
        retVal = Val(str)
    ElseIf str >= "a" And str <= "z" Then
        retVal = Asc(str) - Asc("a") + 10
    ElseIf str >= "A" And str <= "Z" Then
        retVal = Asc(str) - Asc("A") + 10
    End If
End If

myVal = retVal


End Function


Public Function hexToBin(ByVal str As String, ByRef Buffer() As Byte)
Dim strRemain As String
Dim firstChar As Boolean
Dim i, count, inputLen, remainLen As Integer

i = 0
count = 0
firstChar = True
strRemain = str

Do While Len(strRemain) > 0
    If Mid(strRemain, 1, 1) = " " Then
        firstChar = True
        strRemain = Mid(strRemain, 2)
    ElseIf firstChar = True Then
        If Len(strRemain) = 1 Then
            Buffer(count) = myVal(strRemain)
        ElseIf Len(strRemain) >= 2 Then
            Buffer(count) = myVal(Mid(strRemain, 1, 1)) * 16 + myVal(Mid(strRemain, 2, 1))
           
            strRemain = Mid(strRemain, 3)
        End If
       
        count = count + 1
        firstChar = False
    Else
        strRemain = Mid(strRemain, 2)
    End If
Loop

hexToBin = count
End Function

'从数组中取多少为
Public Function strByHex(ByRef Buffer() As Byte, ByVal bufferSize As Integer)
Dim i As Integer
Dim strRet, strSingle As String

strRet = ""
For i = 0 To bufferSize - 1
    strSingle = Hex$(Buffer(i))
    If Len(strSingle) = 1 Then
        strSingle = "0" & strSingle
    End If
   
    If bufferSize = 1 Then
        strRet = strSingle
    Else
        strRet = strRet + strSingle + " "
    End If
   
Next

strByHex = strRet
End Function

 

 

2、调用代码,涉及到对应的控件,无法直接改写执行。请自行测试。

[此贴子已经被作者于2018/11/16 9:21:41编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/11/16 9:37:00 [显示全部帖子]

改成

 

ret = API_PCDRead(hComm, devAddr, mode, blk_Addr, Num_blk, asnr, aRecvBuffer)


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/11/16 9:40:00 [显示全部帖子]

全局代码改成

 

Declare Function API_PCDRead Lib "mi.dll" (ByVal handle As Integer, ByVal deviceAddr As Integer, ByVal mode As Byte, ByVal blk_Addr As Byte, ByVal Num_blk As Byte, ByRef snr As Byte(), ByRef Buffer As Byte()) As Integer


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/11/16 10:28:00 [显示全部帖子]

1、叫对方给你一个vb.net或者c#的实例,贴出对应代码。

 

2、试试改成

 

Declare Function API_PCDRead Lib "mi.dll" (ByVal handle As Integer, ByVal deviceAddr As Integer, ByVal mode As Byte, ByVal blk_Addr As Byte, ByVal Num_blk As Byte, ByRef snr As stringbuilder, ByRef Buffer As stringbuilder) As Integer

 

 

    Dim asnr as New StringBuilder(20)     ''''定义一个20字节的指针
    Dim aRecvBuffer As new StringBuilder(2048)      '''''''定义一个2048字节的指针

 

ret = API_PCDRead(hComm, devAddr, mode, blk_Addr, Num_blk, asnr, aRecvBuffer)


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/11/16 11:28:00 [显示全部帖子]

改成

 

Declare Function API_PCDRead Lib "mi.dll" (ByVal handle As Integer, ByVal deviceAddr As Integer, ByVal mode As Byte, ByVal blk_Addr As Byte, ByVal Num_blk As Byte, ByVal snr As stringbuilder, ByVal Buffer As stringbuilder) As Integer

 

或者

 

Declare Function API_PCDRead Lib "mi.dll" (ByVal handle As Integer, ByVal deviceAddr As Integer, ByVal mode As Byte, ByVal blk_Addr As Byte, ByVal Num_blk As Byte, ByVal snr As Byte(), ByVal Buffer As Byte()) As Integer


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/11/16 14:58:00 [显示全部帖子]

1、叫厂家给你vb.net或者C#的实例;

 

2、别人没有设备无法测试。


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/11/16 15:35:00 [显示全部帖子]

 

我把 USB.dll 拷贝到foxtable安装目录下以后,可以通过测试。

 


 回到顶部