MidNite USB Firmware Update Utility
Copyright MidNite Solar Inc. 2012--2014
Andrew Meares, andy@midnitesolar.com
3/24/2014

Mac OS X 

Description:
The mnupdate utility is a Python script that uploads a MidNite firmware through
a USB COM port.  The script requires Python 2.7 and the pyserial 
module. This update method uses Terminal and I expect you to be able to find and open it.
I also will refer to file locations as /users/username/downloads this may differ depending
on the version of OS X you are using or where you choose to download things. I will assume
you can figure out your username and where you downloaded things. It is up to you to be able 
navigate your Computer not us.

Mac OSX comes with Python but you should check that you have version 2.7.
From the Terminal command line type

python

The response will be the version of Python installed.  Type control d to exit python.
If you need to upgrade Python go to:

www.python.org/download/releases/2.7/

The pyserial module is not included with python. It can be downloaded from here:

https://pypi.python.org/pypi/pyserial

Download: pyserial-2.7.tar.gz Extract the contents (Just double click).

Now Open Terminal. Then type: cd users/username/downloads/pyserial-2.7 (press return)
then type: python setup.py install (press return)
pyserial is now installing.

In order to function, the mnupdate.py script must have execute permissions and
have permissions to access the serial port device.  From Terminal, cd to the directory
with your Midnite Solar firmware (cd /users/username/downloads/MNupdateForLinux_MAC_"date")
and then type:

chmod +x mnupdate.py

To find the device name in Mac OSX, type:

ls /dev/tty.*

Do this once with the USB from your Midnite device not plugged into the computer and then
with it plugged in type it again to figure out your device name.  For a Classic charge
controller it should be something like 'tty.usbmodemDEADC0D1'. Replace the 1 at the end in 
the examples if yours differs.

If you do not see tty.usbmodemDEADC0D*, ensure the Classic is on and connected to the computer.
If it still not there try typing:

system_profiler SPUSBDataType (press return) this will list all usb ports. The Classic will show
up as Bootloader 1.04 - Serial Number: DEADC0DE - Manufacturer: Midnite Solar Classic

Run the update script once for the Classic and then again for the MNGP.  After first
updating the Classic, turn off the power and run the script a second time to upgrade the
MNGP.


Instructions:
To update the firmware on your Classic Charge Controller use the following
procedure:
1. Switch off the Classic battery and PV inputs.  This turns your Classic off 
   completely.
2. Plug your computer into the USB port on the Classic.
3. With the Classic off, run the mnupdate utility in your terminal with the
   proper options.  The options are described later in this document.
4. When "Waiting for serial device." is displayed, switch the battery breaker to
   turn on your Classic.  The Classic should boot and the mnupdate utility 
   should connect and automatically begin uploading the firmware.
5. The firmware can take a few minutes to upload, so be patient.
6. Once the mnupdate utility has finished running, cycle the power on your
   Classic.

   
Command Line Options:
usage: mnupdate.py [-h] [-d DEVICE] [-b {9600,19200,57600}] [-t TIMEOUT]
                   [-m MESSAGE] [-z SLEEP] [-r] [-x REPEAT_SLEEP] [-s]
                   filename

A utility for updating firmware via a USB COM port.

positional arguments:
  filename              Firmware file path/name

optional arguments:
  -h, --help            show this help message and exit
  -d DEVICE, --device DEVICE
                        Device path/name
  -b {9600,19200,57600}, --baudrate {9600,19200,57600}
                        Device baudrate
  -t TIMEOUT, --timeout TIMEOUT
                        Device timeout in seconds
  -m MESSAGE, --message MESSAGE
                        Upload message
  -z SLEEP, --sleep SLEEP
                        Sleep time for serial port in seconds
  -r, --repeat          Repeat upload message?
  -x REPEAT_SLEEP, --repeat-sleep REPEAT_SLEEP
                        Repeat upload sleep time in seconds
  -s, --silent          Silent mode?


Examples: **Since this version is for MAC I have added "-d /dev/tty.usbmodemDEADC0D1" to all examples because it is required.**
For a basic Classic update simply type:
python mnupdate.py -d /dev/tty.usbmodemDEADC0D1 INSERT_FILENAME.ctl  (press return)

In order to update your MNGP you must use the repeat option and a special message. (uPlDrEMaLLfl is case sensitive)
python mnupdate.py -d /dev/tty.usbmodemDEADC0D1 -r -m uPlDrEMaLLfl INSERT_FILENAME.rem

The '-d' option can be used to specify a device other than '/dev/ttyACM0' (ACM0 is for Linux). **required for MAC users**
python mnupdate.py -d /dev/tty.usbmodemDEADC0D1 INSERT_FILENAME.ctl  (press return)

If for some reason the program tries to acquire the serial port too quickly, it
may work to increase the sleep time as follows.
python mnupdate.py -d /dev/tty.usbmodemDEADC0D1 -z 1.5 INSERT_FILENAME.ctl  (press return)

If the firmware update fails on the MNGP try adding both -z and -x options:
python mnupdate.py -d /dev/tty.usbmodemDEADC0D1 -x 0.1 -z 1.5 -r -m uPlDrEMaLLfl FILENAME.rem  (press return)


Choosing a Firmware Update File:
The proper file for your particular device must be chosen.  There are different
firmwares for different Classic voltages and for the MNGP.  The firmware files
have the extension '.ctl' or '.rem' and are available from the MidNite Solar
web page.


Resources:
http://www.midnitesolar.com/
http://pyserial.sourceforge.net/
