• Order of the Butterfly
    Order of the Butterfly
    asrael22
    Posts: 404 from 2014/6/11
    From: Germany
    Right. So here is the event loop:
    Code:

    appMainLoop: procedure expose serial. eta.
    ctrl_c = 2**12
    waitSignal = serial.Signal

    logDebug("Forever loop")
    do forever

    call Handle("app", "h", waitSignal)
    do i = 0 to h.Num-1
    logDebug("Signal: " h.i)
    if h.i = "QUIT" then call halt()
    if h.i = "INIT_SERIAL" then call serialInit()
    if h.i = "CLOSE_SERIAL" then call serialClose()
    if h.i = "SEND_SERIAL_HELLO" then do
    call logDebug('Sending "Hello World"')
    call logGUI('Sending "Hello World"')
    serialWrite("Hello World")
    end
    /* etc */
    end

    waitSignal = Wait(or(serial.Signal, h.Signals, ctrl_c))

    if and(waitSignal, ctrl_c) ~= 0 then do
    logDebug("Handling CTRL-C")
    call halt()
    end

    if and(waitSignal, serial.Signal) > 0 then do
    logDebug("Handling serial...")
    r = serialRead()
    if r ~= '' then do
    logDebug('Received (hex): 'string2HexString(r))
    call processEtaPackage(r)
    end
    end
    end

    return

    Where processEtaPackage(r) just processes/parses the data read from serialRead(). No further reading from serial there.

    Here the code in serialRead(). Pretty much the same as in the RxSerial example:
    Code:

    serialRead: procedure expose serial.
    if serial.Id = 0 then do
    msg = "ERROR: Serial not initialized!"
    logDebug(msg)
    return
    end

    /* isn't it the first time we are here ... */
    if serial.Post then do

    /* ... there is something on the air */
    call SERWaitIO(serial.Id, "b1")

    /* let's see if something else is available */
    call SERQuery(serial.Id, "q")
    if q.BreakReceived then exit
    if q.Actual > 0 then do
    call SERRead(serial.Id, q.Actual)
    call SERWaitIO(serial.Id, "b2")
    end
    else b2 = ""

    /* restart a read request */
    call SERRead(serial.Id, 1)

    return b1 || b2
    end
    else do
    serial.Post=1
    call SERRead(serial.Id, 1)
    return ""
    end


    And, for completness serialWrite():
    Code:

    serialWrite: procedure expose serial.
    parse arg data

    if serial.Id = 0 then do
    msg = "ERROR: Serial not initialized!"
    logDebug(msg)
    return
    end

    res = SERWrite(serial.Id, data)

    if res > 0 then say "Error on send"; return 1
    else return 0


    The Wait() call doesn't seem to block. This "do forever" loop really loops all the time where on each iteration the signals are checked.
    So I don't really know where the hangs are coming from.
    Interesstingly, when upon a MUI button click something is sent via serial the serial.Signal is raised so that on the next iteration the serial handler is called.
    So I'm a little bit lost where those hangs are coming from that either a MUI button does nothing or nothing is received or sent by serial.

    Manfred
  • »05.01.17 - 18:14
    Profile