09 Sep 2010 
Support Center » Knowledgebase » Using Visual Basic with HMI
 Using Visual Basic with HMI
Solution This is small code snippet for HMI and Visual Basic. This requires appropriate serial connetion from Servo to PC Com Port. This cable will be available soon from us.

Option Explicit

Dim ReceiveOK As Boolean
Dim code As Integer
Dim commport As Byte 'comm port setting

Private Sub comm_OnComm()
Dim dt As Variant
Dim arr_num As Long

Select Case comm.CommEvent
Case comEvReceive

dt = comm.Input
arr_num = UBound(dt)
If arr_num = 6 Then
Select Case code
Case 0:
Case 1:

Text3.Text = Str(dt(5))
Text4.Text = Str(dt(6))

End Select

End If

ReceiveOK = True

End Select


End Sub

Private Sub Command1_Click()

On Error GoTo err1

If IsNumeric(Text6.Text) = False Then
MsgBox "CommPort Numeric"
Exit Sub
End If
commport = CByte(Text6.Text)

If comm.PortOpen = False Then

With comm
.commport = commport

.Settings = "19200,N,8,2"
.PortOpen = True
.InBufferCount = 0
End With

ReceiveOK = False

code = 0
Command1.Caption = "NotConnect"
Else
comm.PortOpen = False
Command1.Caption = "Connect"
End If
Exit Sub
err1:
MsgBox "Connect error!"

End Sub

Private Sub Command2_Click()
Dim tmpDt() As Byte
ReDim tmpDt(6) As Byte

If comm.PortOpen Then
tmpDt(0) = &H80
tmpDt(1) = &HEF
tmpDt(2) = 0
tmpDt(3) = 0
tmpDt(4) = CByte(RxTx_chk(tmpDt(0), tmpDt(1), tmpDt(2), tmpDt(3)))
tmpDt(5) = 0
tmpDt(6) = 0

comm.InBufferCount = 0
comm.Output = tmpDt
comm.PortOpen = False
End If

End
End Sub

Private Sub Command3_Click()
Dim tmpDt() As Byte
ReDim tmpDt(6) As Byte

code = 1
If comm.PortOpen Then
tmpDt(0) = &H80
tmpDt(1) = &HE8
tmpDt(2) = 0
tmpDt(3) = 0
tmpDt(4) = CByte(RxTx_chk(tmpDt(0), tmpDt(1), tmpDt(2), tmpDt(3)))
tmpDt(5) = 0
tmpDt(6) = 0

comm.InBufferCount = 0
comm.Output = tmpDt

End If
End Sub

Private Sub Command4_Click()
Dim tmpDt() As Byte
ReDim tmpDt(6) As Byte
Dim motor_stop As Byte

If Command4.Caption = "Stop" Then
motor_stop = False
motor_stop = 0
Command4.Caption = "GO"
Else
motor_stop = True
motor_stop = 1
Command4.Caption = "Stop"
End If
code = 0
If comm.PortOpen Then

tmpDt(0) = &H80
tmpDt(1) = &HEB
tmpDt(2) = 0
tmpDt(3) = motor_stop
tmpDt(4) = CByte(RxTx_chk(tmpDt(0), tmpDt(1), tmpDt(2), tmpDt(3)))
tmpDt(5) = 0
tmpDt(6) = 0


comm.InBufferCount = 0
comm.Output = tmpDt
End If
End Sub



Private Sub HScroll1_Change()
Text1.Text = HScroll1.Value
End Sub

Private Sub HScroll2_Change()
Text2.Text = HScroll2.Value

Call id_move_pos(CInt(Text1.Text), CInt(HScroll2.Value))
End Sub

Private Function RxTx_chk(dt0, dt1, dt2, dt3)
Dim temp As Long

temp = (dt0 + dt1 + dt2 + dt3) Mod 256
RxTx_chk = CByte((256 - temp) Mod 256)

End Function


Private Sub id_move_pos(Id, pos)
Dim tmpDt() As Byte

ReDim tmpDt(6) As Byte
code = 0
If comm.PortOpen Then

tmpDt(0) = &H80
tmpDt(1) = Id
tmpDt(2) = Fix(pos / 256)
tmpDt(3) = pos Mod 256
tmpDt(4) = CByte(RxTx_chk(tmpDt(0), tmpDt(1), tmpDt(2), tmpDt(3)))
tmpDt(5) = 0
tmpDt(6) = 0


comm.InBufferCount = 0
comm.Output = tmpDt
End If
End Sub

Private Sub id_speed(Id, speed)
Dim tmpDt() As Byte

ReDim tmpDt(6) As Byte
code = 0
If comm.PortOpen Then

tmpDt(0) = &H80
tmpDt(1) = &HE9
tmpDt(2) = Id
tmpDt(3) = speed
tmpDt(4) = CByte(RxTx_chk(tmpDt(0), tmpDt(1), tmpDt(2), tmpDt(3)))
tmpDt(5) = 0
tmpDt(6) = 0
comm.InBufferCount = 0
comm.Output = tmpDt
End If
End Sub

Private Sub HScroll2_Scroll()

Text2.Text = HScroll2.Value

Call id_move_pos(CInt(Text1.Text), CInt(HScroll2.Value))
End Sub

Private Sub HScroll3_Change()
Text5.Text = HScroll3.Value
Call id_speed(CInt(Text1.Text), CInt(HScroll3.Value))

End Sub

Private Sub HScroll3_Scroll()
Text5.Text = HScroll3.Value
Call id_speed(CInt(Text1.Text), CInt(HScroll3.Value))
End Sub


Private Sub Text1_Change()

End Sub

additional information :
http://www.hitecrobotics.com/Tony%20information/HMI%20Protocol.pdf
http://www.robonova.de/store/down/download/files/anleitung_8498.pdf
http://web.ukonline.co.uk/r.ibbotson/files/C3024%20Internals.pdf
http://web.ukonline.co.uk/r.ibbotson/files/RoboNova%20IM%20Code.pdf
http://web.ukonline.co.uk/r.ibbotson/files/C3024Serial.pdf


Article Details
Article ID: 5
Created On: 24 Nov 2006 02:08 PM

 This answer was helpful  This answer was not helpful

 Login [Lost Password] 
Email:
Password:
Remember Me:
 
 Search
 Article Options
Home | Register | Submit a Ticket | Knowledgebase | Troubleshooter | News | Downloads
Language: