Beispiel #1
0
def writeDetails(csvFile):
    # Get a list of matched roster entries;
    # the list of None's means match everything
    rosterlist = jmri.jmrit.roster.Roster.instance().matchingList(None, None, None, None, None, None, None)

    # now loop through the matched entries, outputing things
    for entry in rosterlist.toArray() :
        # Most parameters are text-based, so can be output directly
        csvFile.write(entry.getId())
        csvFile.write(entry.getRoadName())
        csvFile.write(entry.getRoadNumber())
        csvFile.write(entry.getMfg())
        csvFile.write(entry.getOwner())
        csvFile.write(entry.getModel())
        csvFile.write(entry.getDccAddress())

        # 'isLongAddress' is a boolean function so we need
        # to deal with outputting that in this way
        if entry.longAddress:
            csvFile.write("Yes")
        else:
            csvFile.write("No")

        # Max Speed is a number - we need to convert to a string
        csvFile.write("%d%%" % entry.getMaxSpeedPCT())

        csvFile.write(entry.getComment())
        csvFile.write(entry.getDecoderFamily())
        csvFile.write(entry.getDecoderModel())
        csvFile.write(entry.getDecoderComment())

        # Now output function labels
        for func in range(0,28+1):
            csvFile.write(entry.getFunctionLabel(func))

        # Finally, we deal with reading in the CV values and
        # outputing those we're interested in

        # First we need to create and populate both CV and
        # indexed CV tables - remember to call the readFile
        # method before trying to populate the CV tables
        cvTable = CvTableModel(None, None)
        icvTable = IndexedCvTableModel(None, None)
        entry.readFile()
        entry.loadCvModel(cvTable, icvTable)

        # Now we can grab the CV values we're interested in
        # Bear in mind that these need to be converted from
        # integers into strings so we use the 'writeCvValue'
        # function defined earlier.
        # These examples are all in decimal - if you require
        # hex, change "%d" to "0x%x" or "0x%X"
        csvFile.write(writeCvValue(cvTable.getCvByNumber("19"), "%d"))
        csvFile.write(writeCvValue(cvTable.getCvByNumber("7"), "%d"))
        csvFile.write(writeCvValue(cvTable.getCvByNumber("8"), "%d"))

        # Notify the writer of the end of this detail record
        csvFile.endRecord()
        csvFile.flush()
        print "Entry", entry.getId(), "written"
Beispiel #2
0
def writeDetails(csvFile):
    # Get a list of matched roster entries;
    # the list of None's means match everything
    rosterlist = jmri.jmrit.roster.Roster.getDefault().matchingList(None, None, None, None, None, None, None)

    # now loop through the matched entries, outputing things
    for entry in rosterlist.toArray() :
        # Most parameters are text-based, so can be output directly
        csvFile.write(entry.getId())
        csvFile.write(entry.getRoadName())
        csvFile.write(entry.getRoadNumber())
        csvFile.write(entry.getMfg())
        csvFile.write(entry.getOwner())
        csvFile.write(entry.getModel())
        csvFile.write(entry.getDccAddress())

        # 'isLongAddress' is a boolean function so we need
        # to deal with outputting that in this way
        if entry.longAddress:
            csvFile.write("Yes")
        else:
            csvFile.write("No")

        # Max Speed is a number - we need to convert to a string
        csvFile.write("%d%%" % entry.getMaxSpeedPCT())

        csvFile.write(entry.getComment())
        csvFile.write(entry.getDecoderFamily())
        csvFile.write(entry.getDecoderModel())
        csvFile.write(entry.getDecoderComment())

        # Now output function labels
        for func in range(0,28+1):
            csvFile.write(entry.getFunctionLabel(func))

        # Finally, we deal with reading in the CV values and
        # outputing those we're interested in

        # First we need to create and populate both CV and
        # indexed CV tables - remember to call the readFile
        # method before trying to populate the CV tables
        cvTable = CvTableModel(None, None)
        icvTable = IndexedCvTableModel(None, None)
        entry.readFile()
        entry.loadCvModel(None, cvTable, icvTable)  # just load CVs, not variables

        # Now we can grab the CV values we're interested in
        # Bear in mind that these need to be converted from
        # integers into strings so we use the 'writeCvValue'
        # function defined earlier.
        # These examples are all in decimal - if you require
        # hex, change "%d" to "0x%x" or "0x%X"
        csvFile.write(writeCvValue(cvTable.getCvByNumber("19"), "%d"))
        csvFile.write(writeCvValue(cvTable.getCvByNumber("7"), "%d"))
        csvFile.write(writeCvValue(cvTable.getCvByNumber("8"), "%d"))

        # Lastly, we deal with examining specific bits of CV29.
        #
        # First, we read CV29 and store it temporarily as we will then use
        # bitwise comparisons later.
        #
        # For the bitwise comparisons, use the following pattern to read the
        # individual bits:
        #
        #   if (cv29Value & {value}) == {value}:
        #       csvFile.write("bit set")
        #   else:
        #       csvFile.write("bit clear")
        #
        # where {value} is one of the following:
        #
        #   Pos  Bit  Value
        #   1st    0      1
        #   2nd    1      2
        #   3rd    2      4
        #   4th    3      8
        #   5th    4     16
        #   6th    5     32
        #   7th    6     64
        #   8th    7    128

        # OK, read the value of CV29
        cv29Value = 0;
        if cvTable.getCvByNumber("29")  != None :
            cv29Value = cvTable.getCvByNumber("29").getValue()
        else :
            Print "Did not find a CV29 value, using zero"
        
        # Now do the bitwise comparisons.
        # First example is speedsteps, which is the second bit 
        if (cv29Value & 2) == 2:
            csvFile.write("28/128 Steps")
        else:
            csvFile.write("14 Steps")

        # Second example is DC mode, which is the third bit 
        if (cv29Value & 4) == 4:
            csvFile.write("On")
        else:
            csvFile.write("Off")

        # Notify the writer of the end of this detail record
        csvFile.endRecord()
        csvFile.flush()
        print "Entry", entry.getId(), "written"