'use client'; import {useRef,useState} from 'react'; import {Button} from '@/components/ui/button'; import {api_motorCommand} from '@/actions/sensoren/api-motor-opc'; import type {MotorLiveRow} from '@/types/motor-opc'; const commands=[['Taster_1','Start rechts'],['Taster_2','Stopp'],['Taster_3','Start links'],['UmschaltungAutomatik','Automatik'],['UmschaltungHand','Handbetrieb'],['UmschaltungRevision','Revision']] as const; export default function MotorControl({motor,anlageId,online}:{motor:MotorLiveRow;anlageId:string;online:boolean}){ const pending=useRef(false),[busy,setBusy]=useState(false),[message,setMessage]=useState(''),[error,setError]=useState(''); async function send(command:string){ if(pending.current||!online||!motor.control)return; pending.current=true;setBusy(true);setMessage('');setError(''); try{const result=await api_motorCommand(motor.componentId,{anlageId,revision:motor.revision??0,controlId:motor.control.id,command}); const answer=result.results.find(r=>r.field===command);if(!answer?.good)throw new Error('Befehl nicht bestätigt: '+(answer?.status??'Ergebnis unbekannt')); setMessage('Schreibzugriff bestätigt. Die CPU setzt das Befehlsbit zurück; die Ausführung zeigt die Statusrückmeldung.'); }catch(cause){setError(cause instanceof Error?cause.message:'Schreibergebnis unbekannt. CPU-Rückmeldung prüfen.');} finally{pending.current=false;setBusy(false);} } if(!motor.control)return
Keine Steuerstruktur zugeordnet.
; returnMotorbedienung · {motor.control.name}
Steuert beide Motoren gemeinsam, falls vorhanden. Jeder Klick schreibt einmal true; die CPU setzt das Bit zurück.
{!online&&Bedienung bei fehlender Live-Verbindung gesperrt.
}{message&&{message}
}{error&&{error}
}