PR23 Controlling using VB problem.

LED Blinking, Walking with Cytron Servo, Displaying RFID, Multi-function Mobile Robot......

PR23 Controlling using VB problem.

Postby zamlak » Wed Feb 24, 2010 5:05 pm

For your information,I'm using PR23 that i buy from cytron.I also buy starter kit XBEE PRO to communicate between PC and the robot.So i have invent VB window application to replace X-CTU. When we use the VB code , the communication between the skxbee worked well .But when i try to control the robot by sending number 8(forward) to PR23 robot its cannot detect.

The coding for the robot

void wireless_xbee (void)
{
lcd_clr(); // clear the lcd
while(1) // looping forever
{
lcd_goto (0);
if (data[0] == 100) // check if UART start byte is met
{
send_string(" XBEE CONTROL "); // display string
SPEEDL = 200; // set the motor speed
SPEEDR = 200;
while(1)
{
lcd_goto(20);
if (RCREG == '8') // if character '8' is detected, the robot move forward
{
forward();
send_string("FORWARD ");
}

else if (RCREG == '2') // if character '2' is detected, the robot move backward
{
backward();
send_string("BACKWARD ");
}
else if (RCREG == '6') // if character '6' is detected, the robot turn right
{
right();
send_string("TURN RIGHT ");
}

else if (RCREG == '4') // if character '4' is detected, the robot turn left
{
left();
send_string("TURN LEFT ");
}

else if (RCREG == '5') // if character '5' is detected, then stop the robot
{
stop();
send_string("INVALID COMMAND ");
}

else // else then stop the robot
{
stop();
send_string("INVALID COMMAND ");
}
}
}
else send_string("COMMAND");
}
}



Coding for the VB

' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' DO NOT FORGET: ADD A REFERENCE TO THE ACTIVECOMPORT LIBRARY FROM THE PROJECT->REFERENCE MENU
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Public lTimerID As Long
Public objComport As ACOMPORTLib.ComPort

Private Sub buttonSubmit_Click()
textReceived = "--->"
objComport.WriteString (textSend)

GetResult
End Sub

Private Sub buttonView_Click()
If FileExists(textLogfile.Text) = True Then
Shell "notepad " + textLogfile.Text, vbNormalFocus
End If
End Sub

Private Sub CheckDTR_Click()

objComport.RaiseDTR (CheckDTR.Value)
GetResult

End Sub

Private Sub CheckRTS_Click()

objComport.RaiseRTS (CheckRTS.Value)
GetResult

End Sub

Public Function FileExists(sFileName As String) As Boolean
FileExists = CBool(Len(Dir$(sFileName))) And CBool(Len(sFileName))
End Function

Private Sub Form_Load()
textSend = "Text"

Set objComport = CreateObject("ActiveXperts.ComPort")

objComport.ComTimeout = 100

For i = 0 To objComport.GetDeviceCount() - 1
comboDevice.AddItem (objComport.GetDevice(i))
Next

comboDevice.AddItem "COM1"
comboDevice.AddItem "COM2"
comboDevice.AddItem "COM3"
comboDevice.AddItem "COM4"
comboDevice.AddItem "COM5"
comboDevice.AddItem "COM6"
comboDevice.AddItem "COM7"
comboDevice.AddItem "COM8"

comboDevice.ListIndex = 0

comboSpeed.AddItem "Default"
comboSpeed.AddItem "110"
comboSpeed.AddItem "300"
comboSpeed.AddItem "600"
comboSpeed.AddItem "1200"
comboSpeed.AddItem "2400"
comboSpeed.AddItem "4800"
comboSpeed.AddItem "9600"
comboSpeed.AddItem "14400"
comboSpeed.AddItem "19200"
comboSpeed.AddItem "38400"
comboSpeed.AddItem "57600"
comboSpeed.AddItem "64000"
comboSpeed.AddItem "115200"
comboSpeed.AddItem "128000"
comboSpeed.AddItem "256000"

comboSpeed.ListIndex = 0

comboHWFlowControl.AddItem "Default"
comboHWFlowControl.AddItem "Disable"
comboHWFlowControl.AddItem "Enable"

comboHWFlowControl.ListIndex = 0

comboSWFlowControl.AddItem "Default"
comboSWFlowControl.AddItem "Disable"
comboSWFlowControl.AddItem "Enable"

comboSWFlowControl.ListIndex = 0

comboDataFormat.AddItem "Default"
comboDataFormat.AddItem "8,n,1"
comboDataFormat.AddItem "7,e,1"

comboDataFormat.ListIndex = 0

textReceived = ""

EnableControls

End Sub

Private Sub buttonOPEN_Click()

objComport.Device = comboDevice.List(comboDevice.ListIndex)

If (comboSpeed.Text = "Default") Then
objComport.BaudRate = 0
Else
objComport.BaudRate = comboSpeed.Text
End If

objComport.LogFile = textLogfile.Text

objComport.HardwareFlowControl = comboHWFlowControl.ListIndex
objComport.SoftwareFlowControl = comboSWFlowControl.ListIndex

If (comboDataFormat.ListIndex = 0) Then
objComport.DataBits = objComport.asDATABITS_DEFAULT
objComport.StopBits = objComport.asSTOPBITS_DEFAULT
objComport.Parity = objComport.asPARITY_DEFAULT
End If


If (comboDataFormat.ListIndex = 1) Then
objComport.DataBits = objComport.asDATABITS_8
objComport.StopBits = objComport.asSTOPBITS_1
objComport.Parity = objComport.asPARITY_NONE
End If


If (comboDataFormat.ListIndex = 2) Then
objComport.DataBits = objComport.asDATABITS_7
objComport.StopBits = objComport.asSTOPBITS_1
objComport.Parity = objComport.asPARITY_EVEN
End If

objComport.Open

GetResult

EnableControls

End Sub

Private Sub buttonClose_Click()
objComport.Close

GetResult

EnableControls
End Sub


Private Sub Form_Unload(Cancel As Integer)
Timer1.Enabled = False
End Sub

Private Sub EnableControls()

Dim bOpened

bOpened = objComport.IsOpened

CheckDTR.Enabled = bOpened
CheckRTS.Enabled = bOpened
checkCTS.Enabled = bOpened
checkDCD.Enabled = bOpened
checkRI.Enabled = bOpened
checkDSR.Enabled = bOpened
buttonOpen.Enabled = bOpened + 1
buttonClose.Enabled = bOpened
buttonSubmit.Enabled = bOpened

Timer1.Enabled = bOpened

End Sub





Private Sub Timer1_Timer()
Dim strString

strString = objComport.ReadString

If (strString <> "") Then
textReceived = textReceived & strString & vbCrLf
End If

checkDCD.Value = Abs(objComport.QueryDCD)
checkCTS.Value = Abs(objComport.QueryCTS)
checkDSR.Value = Abs(objComport.QueryDSR)
checkRI.Value = Abs(objComport.QueryRI)

End Sub

Private Sub GetResult()
If objComport.LastError = 0 Then
textResult.Caption = "SUCCESS"
Else
textResult.Caption = "ERROR " & objComport.LastError & " ( " & objComport.GetErrorDescription(objComport.LastErro r) & " )"
End If
End Sub

Please help me :geek:
zamlak
Newbie
 
Posts: 9
Joined: Mon Feb 22, 2010 11:11 pm

Re: PR23 Controlling using VB problem.

Postby yonghui » Sat Feb 27, 2010 5:35 pm

hi,

will like to know how u setup your xbee modules. the xbee modules are in transparent mode? AP=0?


regards,
yh
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: PR23 Controlling using VB problem.

Postby ober » Mon Mar 01, 2010 11:37 am

zamlak, please do not paste the source code in such method.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm


Return to DIY Project Set

Who is online

Users browsing this forum: No registered users and 9 guests

cron