| 46 | } |
| 47 | |
| 48 | func (r *SerialRead) Execute(ctx context.Context, scope *engine.Scope) (string, error) { |
| 49 | if err := r.uart.Flush(); err != nil { |
| 50 | return "", fmt.Errorf("serialRead %s: flushing input: %w", r.ID(), err) |
| 51 | } |
| 52 | if r.prompt != "" { |
| 53 | if err := r.uart.Write(r.prompt); err != nil { |
| 54 | return "", fmt.Errorf("serialRead %s: writing prompt: %w", r.ID(), err) |
| 55 | } |
| 56 | } |
| 57 | line, err := r.uart.Read(ctx) |
| 58 | if err != nil { |
| 59 | return "", fmt.Errorf("serialRead %s: %w", r.ID(), err) |
| 60 | } |
| 61 | if err := engine.ApplyOutput(scope, r.ID(), serialReadOutID, r.binding, expr.StringVal(line)); err != nil { |
| 62 | return "", fmt.Errorf("serialRead %s: applying output: %w", r.ID(), err) |
| 63 | } |
| 64 | return r.Next(engine.PortCtrl, scope) |
| 65 | } |
| 66 | |
| 67 | // Outputs declares the single "output" slot — a string line. Returns it only |
| 68 | // if the binding is emit-mode (assign/discard don't materialize a variable). |