Changeset 42 for trunk


Ignore:
Timestamp:
06/03/10 09:07:22 (14 years ago)
Author:
pinwc4
Message:

Added logic to close and reopen the port for each read or write operation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/desktop/ICSSerialPort.rbbas

    r37 r42  
    565565        #tag Method, Flags = &h0 
    566566                Sub readCar() 
    567                   //Read values from the currently attached car 
    568                   dim sendstring as string 
    569                    
    570                   mode = "read" 
    571                    
    572                   sendstring = chrb(&hC5) 
    573                    
    574                   me.Write(sendstring) 
     567                  dim portstatus as boolean 
     568                  //Reopen the port just in case communication was interrupted previously 
     569                  //This will return true if the port is opened 
     570                  portstatus = reOpenPort 
     571                   
     572                  if portstatus = true then 
     573                    //Read values from the currently attached car 
     574                    dim sendstring as string 
     575                     
     576                    mode = "read" 
     577                     
     578                    sendstring = chrb(&hC5) 
     579                     
     580                    me.Write(sendstring) 
     581                  end if 
    575582                End Sub 
    576583        #tag EndMethod 
     
    725732        #tag Method, Flags = &h0 
    726733                Sub writeCar() 
    727                   //Send set bytes to the car 
    728                   mode = "write" 
    729                    
    730                   dim sendstring as string 
    731                    
    732                   calculateChecksum() 
    733                    
    734                   sendstring = byte01 + byte02 + byte03 + byte04 + byte05 + byte06 + byte07 + byte08 + byte09 + byte10 + byte11 + byte12 + byte13 + byte14 + byte15 + byte16 + byte17 + byte18 
    735                    
    736                   me.Write(sendstring) 
    737                 End Sub 
     734                  dim portstatus as boolean 
     735                  //Reopen the port just in case communication was interrupted previously 
     736                  //This will return true if the port is opened 
     737                  portstatus = reOpenPort 
     738                   
     739                  if portstatus = true then 
     740                     
     741                    //Send set bytes to the car 
     742                    mode = "write" 
     743                     
     744                    dim sendstring as string 
     745                     
     746                    calculateChecksum() 
     747                     
     748                    sendstring = byte01 + byte02 + byte03 + byte04 + byte05 + byte06 + byte07 + byte08 + byte09 + byte10 + byte11 + byte12 + byte13 + byte14 + byte15 + byte16 + byte17 + byte18 
     749                     
     750                    me.Write(sendstring) 
     751                     
     752                  end if 
     753                End Sub 
     754        #tag EndMethod 
     755 
     756        #tag Method, Flags = &h21 
     757                Private Function reOpenPort() As Boolean 
     758                  dim status as boolean 
     759                  //Set the return code to false unless the port successfully opens 
     760                  status = false 
     761                   
     762                  //First close the port just in case 
     763                  me.Close 
     764                   
     765                  if not me.Open then 
     766                    //Could not open 
     767                    MsgBox "Error opening defined com port" 
     768                  else 
     769                    status = true 
     770                  end if 
     771                End Function 
    738772        #tag EndMethod 
    739773 
Note: See TracChangeset for help on using the changeset viewer.