Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB6
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
 
'RFID CARD VALUES
'24664=4A00C36058B1      'farmer 1
'36509=4A00C38E9D9A      'farmer 2
'36507=4A00C38E9B9C      'farmer 3

 
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 * 7
    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: ' got enough bytes
                i = DateDiff("s", StartTime, Now)
                If i > 5 Then ReturnFlag = "Timeout": Exit Do: ' timeout in 5 seconds
                Loop
 
            If ReturnFlag <> "Timeout" Then
                SerialInputString = LCCOM.Input
                get_load_cell_value = SerialInputString         'return value
            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)       'if serin = [00020][00020]
            Else
                serin = Mid$(serin, x + 1) & Left$(serin, x - 2)    'if serin = 020][00
            End If
        End If
    load_value = Val(serin)               'return value

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: ' got enough bytes
                i = DateDiff("s", StartTime, Now)
                If i > 5 Then ReturnFlag = "Timeout": Exit Do: ' timeout in 5 seconds
        Loop
 
            If ReturnFlag <> "Timeout" Then
                rfvalid = RFIDCOM.Input
            Else
                Label3.Caption = "Try again!"
                RFIDCOM.PortOpen = False
                Exit Sub    ' if no card is swiped then exit the validation function
            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 temp As String * 7
    Dim gms  As Integer
    Dim counter As Integer
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 'CONTAINER 1
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Do
            Label3.Caption = "Dispensing fertilizer 1"
            counter = 1
            'UCcom.output = "1"
'                Do
'                    gms = load_value_in_gms(get_load_cell_value())
'                Exit Do
'                Label3.Caption = "Fertilizer 1 filling complete"
'                Loop Until (load_a = gms)
'
                Do
                    gms = load_value_in_gms(get_load_cell_value())
                  '  If (gms = load_a) Then Exit Do:
'                    If (gms < load_a) Then
                Loop Until (gms = load_a)
 
                Label3.Caption = "Fertilizer 1 filling complete"
                Exit Do
        Loop
 
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 'CONTAINER 2
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Do
            Label3.Caption = "Dispensing fertilizer 2"
            counter = 2
            'UCcom.output = "1"
'                Do
'                    gms = load_value_in_gms(get_load_cell_value())
'                Exit Do
'                Label3.Caption = "Fertilizer 2 filling complete"
'                Loop Until (load_b = gms)
'
                Do
                    gms = load_value_in_gms(get_load_cell_value())
                    'If (gms = load_a) Then Exit Do
                    Loop Until (gms = load_b)
                Label3.Caption = "Fertilizer 2 filling complete"
 
        Exit Do
        Loop
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 'CONTAINER 3
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Do
            Label3.Caption = "Dispensing fertilizer 3"
            counter = 3
            'UCcom.output = "1"
'                Do
'                    gms = load_value_in_gms(get_load_cell_value())
'                Exit Do
'                Label3.Caption = "Fertilizer 3 filling complete"
'                Loop Until (load_c = gms)
''
                Do
                    gms = load_value_in_gms(get_load_cell_value())
                   ' If (gms = load_a) Then Exit Do
                   ' If (gms < load_c) Then
                   ' Loop
                    Loop Until (gms = load_c)
                Label3.Caption = "Fertilizer 3 filling complete"
 
        Exit Do
        Loop
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 'CONTAINER 4
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Do
            Label3.Caption = "Dispensing fertilizer 4"
            counter = 4
            'UCcom.output = "1"
'                Do
'                    gms = load_value_in_gms(get_load_cell_value())
'                Exit Do
'                Label3.Caption = "Fertilizer 4 filling complete"
'                Loop Until (load_d = gms)
''
                Do
                    gms = load_value_in_gms(get_load_cell_value())
                   ' If (gms = load_a) Then Exit Do
                   ' If (gms < load_d) Then
                   ' Loop
                    Loop Until (gms = load_d)
                Label3.Caption = "Fertilizer 4 filling complete"
 
        Exit Do
       Loop
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

       'UCcom.output = "5"

 
End Sub
Posted 11-Nov-12 5:52am
preet94441

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

With just a quick look I dont see the 'OnComm' section so how do you know if there is anything to read?
Also from experience, I found putting a delay in getting information from a comm port helps a lot...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 458
1 OriginalGriff 344
2 George Jonsson 233
3 Animesh Datta 130
4 Shemeemsha RA 128
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 4 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100