Exemplo n.º 1
0
def ReadNumber(port, with_error=True):

    def TestResponse(allstr, with_error):
        if CheckRespond(allstr, with_error) != True:
            return [False, 0]
        fox_number = allstr[0]
        try:
            if int(fox_number) < settings.FOX_NUMBER_MIN or int(fox_number) > settings.FOX_NUMBER_MAX:
                if with_error:
                    utils.MessageBox("Fox returned wrong number: \"" + fox_number + "\". Number must be between " + settings.FOX_NUMBER_MIN + " and " + settings.FOX_NUMBER_MAX + ".")
                return [False, 0]
        except ValueError:
            if with_error:
                utils.MessageBox("Fox returned wrong number: \"" + str(fox_number) + "\". Number must be between " + str(settings.FOX_NUMBER_MIN) + " and " + str(settings.FOX_NUMBER_MAX) + ".")
            return [False, 0]
        int_fox_num = int(fox_number)
        return [True, int_fox_num]
    
    con = fox_serial.Open(port, with_error=False)
    if con == None:
       if with_error:
           utils.MessageBox("Cannot open COM-port " + str(port))
       return [False, 0]
   
    # this is necessary to clear the uart buffer if the welcome message is sent
    # -> sent one command and receive the answer
    # first time uart will receive binary zeros, second command is then correct

    fox_serial.ClearBuffer(con)

    fox_serial.Writeln(con, settings.COMMAND_GET_FOX_NUMBER)
    allstr = fox_serial.ReadToPrompt(con, False)

    ret = TestResponse(allstr, False)

    if ret[0] != True:
        fox_serial.ClearBuffer(con)
        fox_serial.ReadAll(con)
        fox_serial.Writeln(con, "exit")
        allstr3 = fox_serial.ReadToPrompt(con, False)

        #fox_serial.Writeln(con, "exit")
        #allstr3 = fox_serial.ReadToPrompt(con, False)
    
        fox_serial.Writeln(con, settings.COMMAND_GET_FOX_NUMBER)
        allstr = fox_serial.ReadToPrompt(con, False)

        ret = TestResponse(allstr, with_error)

    fox_serial.Close(con)

    return ret
Exemplo n.º 2
0
def ReadCrystalFrequency(port, with_error=True):
    con = fox_serial.Open(port, with_error=False)
    if con == None:
        return [False, 0]
    fox_serial.Writeln(con, settings.COMMAND_GET_CRYSTAL_FREQUENCY)
    allstr = fox_serial.ReadToPrompt(con)
    fox_serial.Close(con)
    if CheckRespond(allstr, with_error) != True:
        return [False, 0]
    crystal_frequency = allstr[0]
    try:
        int_crystal_frequency = int(crystal_frequency)
    except ValueError:
        if with_error:
            utils.MessageBox("Fox returned wrong crystal frequency: \"" + crystal_frequency) 
        return [False, 0]
    return [True, int_crystal_frequency]
Exemplo n.º 3
0
 def SetIdTimer(self, event):
     self.timer_set_id.Stop()
     retstr = fox_serial.Readln(self.con_set_id, False)
     ret = self.progress_dialog_set_id.Update(0) 
     if ret[0] == False:
         # user cancelled 
         self.progress_dialog_set_id.Destroy()
         self.timer_set_id.Stop()
         fox_serial.Writeln(self.con_set_id, "exit")
         fox_serial.Close(self.con_set_id)
         return
     if retstr.find("tag id " + str(self.tag_id_set_id) + " written!") >= 0:
         self.frame.Status("Tag " + str(self.tag_id_set_id) + " successfully written!")
         self.checkbox_created[self.index_set_id].SetValue(True)
         self.progress_dialog_set_id.Destroy()
         self.timer_set_id.Stop()
         fox_serial.Close(self.con_set_id)
         return
     self.timer_set_id.Start(1500)
Exemplo n.º 4
0
    def ProgramFoxNumber(self, number):
        # number is from ARRAY_FOX_NUMBER!

        j = -1  # just a value that is not between FOX_NUMBER_MIN and FOX_NUMBER_MAX

        if number == settings.ARRAY_FOX_NUMBER_DEMO:
            transmit_minute = "0"
            secret = "1"
            repetition = "1"
            try:
                frequency = str(
                    int(
                        float(self.text_demo_frequency_freq.GetValue()) *
                        1000000))
            except ValueError:
                utils.MessageBox(
                    "Frequency does not seem to be a float-number (e.g. 3.5)")
                return False
            try:
                amplitude_int = int(self.text_amplitude.GetValue())
                amplitude = str(amplitude_int)
                if amplitude_int < 0 or amplitude_int > 100:
                    utils.MessageBox("Amplitude must be between 0 and 100")
            except ValueError:
                utils.MessageBox("Amplitude does not seem to be an integer")
                return False
            try:
                morse_int = int(self.text_morse_speed.GetValue())
                morse = str(morse_int)
            except ValueError:
                utils.MessageBox("Morse-speed does not seem to be an integer")
                return False
        else:
            transmit_minute = self.combobox_minute[number].GetValue()
            secret = str(self.fox_secret[number])
            repetition = self.combobox_repetition.GetValue()
            try:
                frequency = str(
                    int(float(self.text_frequency.GetValue()) * 1000000))
            except ValueError:
                utils.MessageBox(
                    "Frequency does not seem to be a float-number (e.g. 3.5)")
                return False

        if number == settings.ARRAY_FOX_NUMBER_DEMO:
            number = settings.FOX_NUMBER_DEMO
        else:
            number = number + 1

        fox_name = str(number)
        if number == settings.FOX_NUMBER_DEMO:
            fox_name = "Demo"

        if self.com[number] != "":
            ret = fox.ReadNumber(self.com[number])
            if ret[0] == True:
                j = ret[1]

        progress_dialog = wx.ProgressDialog("Program Fox",
                                            "Check fox number",
                                            maximum=31,
                                            parent=None,
                                            style=wx.PD_APP_MODAL)
        progress_dialog.SetInitialSize()
        self.frame.Status("Program Fox " + str(number) + ": Check fox number")
        progress_dialog.Update(
            0, "Program Fox " + str(number) + ": Check fox number")

        if j != number:
            self.TestFoxes(None)
            if self.com[number] != "":
                temp = fox.ReadNumber(self.com[number])
                if temp[0] == True:
                    j = temp[1]
            if j != number or self.com[number] == "":
                progress_dialog.Destroy()
                self.frame.Status("Program Fox " + str(number) + ": Failed")
                if number != settings.FOX_NUMBER_DEMO:
                    utils.MessageBox("Fox " + str(number) +
                                     " is not connected")
                else:
                    utils.MessageBox("Demo-Fox is not connected")
                return False

        con = fox_serial.Open(self.com[number])
        if con == None:
            progress_dialog.Destroy()
            return False

        if self.checkbox_modulation.GetValue():
            modulation_string = settings.STRING_ON
        else:
            modulation_string = settings.STRING_OFF

        commands = [
            settings.COMMAND_SET_RELOAD, settings.COMMAND_SET_CALL_SIGN,
            settings.COMMAND_SET_FOX_MAX, settings.COMMAND_SET_TRANSMIT_MINUTE,
            settings.COMMAND_SET_FREQUENCY, settings.COMMAND_SET_START_DATE,
            settings.COMMAND_SET_START_TIME, settings.COMMAND_SET_STOP_DATE,
            settings.COMMAND_SET_STOP_TIME, settings.COMMAND_SET_WPM,
            settings.COMMAND_SET_MODULATION, settings.COMMAND_SET_MORSING,
            settings.COMMAND_SET_AMPLITUDE, settings.COMMAND_RESET_HISTORY,
            settings.COMMAND_SET_SECRET
        ]

        parameters = [
            settings.STRING_OFF,
            self.combobox_call[number].GetValue()
            [:self.combobox_call[number].GetValue().find(" "
                                                         )],  # SET_CALL_SIGN
            repetition,  # SET_FOX_MAX
            transmit_minute,  # SET_TRANSMIT_MINUTE
            frequency,  # SET_FREQUENCY
            self.start_date_picker.GetValue().FormatISODate(
            ),  # SET_START_DATE
            self.start_time_picker.GetValue(
                as_wxDateTime=True).FormatISOTime(),  # SET_START_TIME
            self.stop_date_picker.GetValue().FormatISODate(),  # SET_STOP_DATE
            self.stop_time_picker.GetValue(
                as_wxDateTime=True).FormatISOTime(),  # SET_STOP_TIME
            self.text_morse_speed.GetValue(),  # SET_WPM
            modulation_string,  # SET_MODULATION
            settings.STRING_ON,  # SET_MORSING
            self.text_amplitude.GetValue(),  # SET_AMPLITUDE
            "",  # RESET HISTORY
            secret
        ]

        self.frame.Status("Program Fox " + str(number) + ": Write commands")
        progress_dialog.Update(
            10, "Program Fox " + str(number) + ": Write commands")

        fox_serial.ReadAll(con)

        # continue here -> others with commands and parameters, oscillator frequency in fox-panel
        for i in range(0, len(commands)):
            fox.SendCommand(con, commands[i], parameters[i], with_error=False)

        suc = True
        for i in range(0, len(commands)):
            allstr = fox_serial.ReadToPrompt(con)
            if fox.CheckRespond(allstr, False) == False:
                utils.MessageBox(i)
                suc = False
                break

        if suc == False:
            progress_dialog.Destroy()
            utils.MessageBox("Fox does not respond correctly")
            self.frame.Status("Program Fox " + str(number) + ": Failed")
            fox_serial.Close(con)
            return False

        self.frame.Status("Program Fox " + str(number) + ": Synchronise time")
        progress_dialog.Update(
            20, "Program Fox " + str(number) + ": Synchronise time")
        if fox.SyncTime(con, with_error=False) == False:
            utils.MessageBox("Fox " + str(number) +
                             " does not respond correctly")
            self.frame.Status("Program Fox " + str(number) + ": Failed")
            progress_dialog.Destroy()
            fox_serial.Writeln(
                con, settings.COMMAND_SET_RELOAD + settings.STRING_ON)
            fox_serial.ReadToPrompt()
            fox_serial.Close(con)
            return False
        progress_dialog.Update(30)

        fox_serial.Writeln(con,
                           settings.COMMAND_SET_RELOAD + settings.STRING_ON)
        allstr = fox_serial.ReadToPrompt(con)
        if fox.CheckRespond(allstr, False) == False:
            utils.MessageBox("Fox does not respond correctly")
            self.frame.Status("Program Fox " + str(number) + ": Failed")
            fox_serial.Close(con)
            return False

        self.frame.Status("Fox " + str(number) + " programmed successfully")

        fox_serial.Close(con)
        progress_dialog.Destroy()
        return True
Exemplo n.º 5
0
def SendCommand(con, command, parameter, with_error=True):
    # update changes here also to SyncTime
    fox_serial.Writeln(con, command + parameter)
    return True