厦门宇电AIBUS通讯程序驱动部分源码 点击:1030 | 回复:1



黑杰克

    
  • 精华:0帖
  • 求助:0帖
  • 帖子:17帖 | 119回
  • 年度积分:0
  • 历史总积分:178
  • 注册:2005年12月02日
发表于:2007-12-04 11:13:00
楼主
都使用VB制作。
1使用磁盘格式化数据。
Dim s
Dim aipv As Integer
Dim aisv As Integer
Dim aimv As Integer
Dim rwdata As Integer
Dim crc As Integer
Dim x(0 To 7) As Byte
Private Sub Command1_Click()

    
    Label1.Caption = ""
    
    x(0) = &H81
    x(1) = &H81
    x(2) = &H43
    x(3) = &H1
    x(4) = &H1
    x(5) = &H0
    x(6) = &H45
    x(7) = &H1
    MSComm1.Output = x
    
    Timer1.Enabled = True
    
    
   
End Sub

Private Sub Command2_Click()
    MSComm1.PortOpen = True

End Sub

Private Sub Command3_Click()
    MSComm1.PortOpen = False

End Sub


Private Sub MSComm2_OnComm()

End Sub



Private Sub Timer1_Timer()
    Timer1.Enabled = False

    s = MSComm1.Input
    Open "datafile.bin" For Binary As #1
    Put #1, 1, s
    Get #1, 13, aipv
    Get #1, 15, aisv
    Get #1, 17, aimv
    Get #1, 19, rwdata
    Get #1, 21, crc
    
   
    Label2.Caption = aipv
    Label3.Caption = aisv
    Label4.Caption = aimv
    Label5.Caption = rwdata
    Label6.Caption = crc
    Close #1
    
    
 

End Sub


串口设置为 
InputMode:1 - comInputModeBinary 
RThreshold:0 
Settings:"9600,n,8,2"


2使用自定义函数处理

Dim Cmdout (0 To 7) As Byte

  Cmdout(0)=129
  Cmdout(1)=129
  Cmdout(2)=67
  Cmdout(3)=0
  Cmdout(4)=232
  Cmdout(5)=3
  Cmdout(6)=44
  Cmdout(7)=4
COMM1.OUTPUT=Cmdout

仪表返回数据:
Dim instring() as byte
  Dim pv as integer, sv as integer, mv as integer, alm as integer, cs as integer, crc as integer

  instring = MSComm1.Input    '假设已经有数据返回

  pv= Join2Byte(instring(0), instring(1))
  sv= Join2Byte(instring(2), instring(3))
  mv= (instring(4))
alm= integer(instring(5))
cs= Join2Byte(instring(6), instring(7))
crc= Join2Byte(instring(8), instring(9))

Public Function Join2Byte(lowbyte As Byte, highbyte As Byte)
Dim c As Integer
c = highbyte
If c > 127 Then
  c = (c - 256) * 256
Else
  c = c * 256
End If
Join2Byte = c + lowbyte
End Function



Servant198104

  • 精华:0帖
  • 求助:0帖
  • 帖子:4帖 | 37回
  • 年度积分:0
  • 历史总积分:74
  • 注册:2006年2月28日
发表于:2009-12-31 12:13:22
1楼
学习学习学习学习学习中。

热门招聘
相关主题

官方公众号

智造工程师