stinky
 
 
  Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| PK2CMD && CCS && RUBY[off topic] | 
			 
			
				 Posted: Mon Feb 09, 2015 5:06 pm     | 
				     | 
			 
			
				
  | 
			 
			
				I'm not sure how many of you here are command line junkies.  If you are, I've been using a ruby script that has been most helpful for running the command line version of the PICKit2.
 
 
You'll need these:
 
PK2CMD and more from microchip
 
Ruby for windows
 
Rupy for other OSes
 
 
-I don't keep more than one .hex in a given directory.  If you do, this script will try and load all the .hex files it finds.  YMMV.
 
-You must add pk2cmd.exe to your path.  
 
-You must add ruby to your path, but the installers may do it for you.
 
-I have it set to release MCLR after programming.
 
-Copy, paste, and save it as whatever.rb
 
-Call the script with "ruby whatever.rb" from the directory that has the generated .hex file. 
 
-Hope this helps.  I know ruby is outside of this forum's scope.  I promise it is easy to pickup though.  Lots of good info out there.
 
 
 
 	  | Code: | 	 		  #call script from the same directory
 
#that the compiled HEX file is in.
 
Dir.glob("*.hex").each do |f|
 
   path_to_file = File.path("#{f}").gsub('/', '\\')
 
   puts "#{f}"
 
 
  #ccs hex files have the devie
 
  #name inside.  This looks for 
 
  #that name.
 
  query = 'PIC'
 
  names = File.readlines(path_to_file)
 
  matches = names.select { |name| name[/#{query}/i] }
 
  device = matches[0].to_s.sub!(/^;/,'').chomp
 
 
  #use the device name and file to 
 
  #create the command passed to the 
 
  #pickit2 programmer-T
 
  command = "pk2cmd /P#{device} /R /M /F#{path_to_file}"
 
 
  #program the device and return
 
  #the stderr display
 
  pk2 = (IO.popen "#{command}")
 
  puts pk2.readlines
 
 
  puts
 
end | 	 
  | 
			 
		  |