Hi everyone!, Please help me out on this code.
The situation is like this that i am getting a string on the serial port in this format: [00200][00210][00215], the numbers inside parenthesis is the weight in grams, i have to convert it to integer & compare it with the user defined value.
I have written a code to do all this but the problem is that the code works well when i am debugging it with "step into" but doesn't gives any result when i run it. here is the code (sorry to dump full code but i have to provide full information of what i am doing).
the system flowchart is like this:
1. RFID_validation->
2. switch_between_users->
3. get_user_values->
4. open_container_1->
5. wait_till_the_current_weight_is_equal_to_user_input
6. close container 1
7. open container 5
8. wait for sometime(10 seconds)
9. close container 5
10. repeat from step 4 for other three containers.
11. show notification for process completion.
Code starts form here:
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
LCCOM.CommPort = lcport.Text
RFIDCOM.CommPort = rfidport.Text
Label3.Caption = "Plaease Swipe your card and enter the desired quantity values"
Call rfid_validation
End Sub
Private Sub Form_Load()
LCCOM.RThreshold = 7
LCCOM.InputLen = 0
LCCOM.Settings = "2400,n,8,1"
RFIDCOM.RThreshold = 12
RFIDCOM.InputLen = 0
RFIDCOM.Settings = "9600,n,8,1"
Label3.Caption = "Enter the port numbers"
End Sub
Function get_load_cell_value() As String
Dim i As Integer
Dim StartTime
Dim SerialInputString As String
If LCCOM.PortOpen = True Then LCCOM.PortOpen = False
LCCOM.PortOpen = True
StartTime = Now
ReturnFlag = ""
Do
If LCCOM.InBufferCount >= 7 Then Exit Do:
i = DateDiff("s", StartTime, Now)
If i > 5 Then ReturnFlag = "Timeout": Exit Do:
Loop
If ReturnFlag <> "Timeout" Then
SerialInputString = LCCOM.Input
get_load_cell_value = SerialInputString
Else
SerialInputString = "No data"
End If
LCCOM.PortOpen = False
Exit Function
GetSerialError: LCCOM.PortOpen = False
End Function
Function load_value_in_gms(serin As String) As Integer
Dim x As Integer
x = InStr(serin, "[")
If x Then
If x = 1 Then
serin = Mid$(serin, x + 1, 5)
Else
serin = Mid$(serin, x + 1) & Left$(serin, x - 2)
End If
End If
load_value = Val(serin)
End Function
Sub rfid_validation()
Dim rfvalid As String * 12
Dim i As Integer
Dim StartTime
RFIDCOM.PortOpen = True
StartTime = Now
ReturnFlag = ""
Do
If RFIDCOM.CommEvent = comEvReceive Then Exit Do:
i = DateDiff("s", StartTime, Now)
If i > 5 Then ReturnFlag = "Timeout": Exit Do:
Loop
If ReturnFlag <> "Timeout" Then
rfvalid = RFIDCOM.Input
Else
Label3.Caption = "Try again!"
RFIDCOM.PortOpen = False
Exit Sub
End If
load_a = Val(Text1.Text)
load_b = Val(Text2.Text)
load_c = Val(Text3.Text)
load_d = Val(Text4.Text)
Select Case rfvalid
Case "4A00C36058B1"
Label3.Caption = "Welcome Farmer A" & vbCrLf & "Enter the values"
Call Dispence(load_a, load_b, load_c, load_d)
Case "4A00C38E9D9A"
Label3.Caption = "Welcome Farmer B" & vbCrLf & "Enter the values"
Call Dispence(load_a, load_b, load_c, load_d)
Case "4A00C38E9B9C"
Label3.Caption = "Welcome Farmer C" & vbCrLf & "Enter the values"
Call Dispence(load_a, load_b, load_c, load_d)
End Select
RFIDCOM.PortOpen = False
End Sub
Sub Dispence(ByVal load_a As Integer, ByVal load_b As Integer, ByVal load_c As Integer, ByVal load_d As Integer)
Dim gms As Integer
Dim counter As Integer
Do
Label3.Caption = "Dispensing fertilizer 1"
counter = 1
Do
gms = load_value_in_gms(get_load_cell_value())
Loop Until (gms = load_a)
Label3.Caption = "Fertilizer 1 filling complete"
Exit Do
Loop
Do
Label3.Caption = "Dispensing fertilizer 2"
counter = 2
Do
gms = load_value_in_gms(get_load_cell_value())
Loop Until (gms = load_b)
Label3.Caption = "Fertilizer 2 filling complete"
Exit Do
Loop
Do
Label3.Caption = "Dispensing fertilizer 3"
counter = 3
Do
gms = load_value_in_gms(get_load_cell_value())
Loop Until (gms = load_c)
Label3.Caption = "Fertilizer 3 filling complete"
Exit Do
Loop
Do
Label3.Caption = "Dispensing fertilizer 4"
counter = 4
Do
gms = load_value_in_gms(get_load_cell_value())
Loop Until (gms = load_d)
Label3.Caption = "Fertilizer 4 filling complete"
Exit Do
Loop
End Sub