Browse Source

er faehrt!

Martin Kunz 3 years ago
parent
commit
295d313b03

+ 42 - 29
src/main/java/at/acdp/urweb/fhpp/FHMaster.java

@@ -66,58 +66,71 @@ public class FHMaster {
             }, Modbus.sharedExecutor());
         }
     }
+    public void prepare() {
+        byte[] sb=new byte[8];
+        sb[0]=0x00;
+        sb[1]=0x00;
+        send(sb, 4);
+    }
+
+    private void send(byte[] bytes, int quantity) {
+        CompletableFuture<ReadHoldingRegistersResponse> f =
+                master.sendRequest(new WriteMultipleRegistersRequest(0, quantity, bytes), 0);
+        f.join();
+    }
 
-    void direktAuftrag(ModbusTcpMaster master, int pos) {
+    public void direktAuftrag(int pos, int start) {
         byte ccon=0x0;
-        ccon|=(1<<0); //Enable drive
-        ccon|=(0<<1); //Stop
-        ccon|=(1<<2); //Release Brake
+        ccon|=(1<<0); // Enable drive
+        ccon|=(1<<1); // !Stop
+        ccon|=(1<<2); // Release Brake
         ccon|=(0<<3); //Reset fault
         ccon|=(0<<4); //Reserved
         ccon|=(0<<5); //lock software
-        ccon|=(0<<6 | 1 <<7); //lock software
+        ccon|=(1<<6 |0 <<7); //lock software
                             // 0,0 Satzselektion
                             // 1,0 Direktauftrag
                             // 0,1 Reserviert
                             // 1,1 Reserviert
 
         byte cpos=0x0;
-        ccon|=(1<<0); // !Halt
-        ccon|=(1<<1); // start fahrauftrag
-        ccon|=(0<<2); // start homing
-        ccon|=(0<<3); // jog pos
-        ccon|=(0<<4); // jog neg
-        ccon|=(0<<5); //  teach value
-        ccon|=(0<<6); //  clear remaining pos.
-        ccon|=(0<<7); //  Reserved
+        cpos|=(1<<0); // !Halt
+        cpos|=(start<<1); // start fahrauftrag
+        cpos|=(0<<2); // start homing
+        cpos|=(0<<3); // jog pos
+        cpos|=(0<<4); // jog neg
+        cpos|=(0<<5); //  teach value
+        cpos|=(0<<6); //  clear remaining pos.
+        cpos|=(0<<7); //  Reserved
 
         byte cdir=0x0;
-        cdir|=(1<<0); //absolute/relative
-        cdir|= (1<<1| 1<<2); //absolute/relative
+        cdir|=(0<<0); //  relative(0), absolute(1)
+        cdir|= (0<<1| 0<<2); //absolute/relative
                                 // 0,0 Positionsregelung
                                 // 0,1 Kraftbetrieb
                                 // 1,0 Geschwindigkeitsregelung
                                 // 1,1 Reserviert
-        cdir|=(1<<3);   // Function Number Kurvenscheibenfunktion (0=nein)
-        cdir|=(1<<5);   // Function Group Kurvenscheibenfunktion (0=nein)
-        cdir|=(1<<7);   // 0 = normal; 1=kurvenscheibenfunktion
-
-        byte sbyte4=100; // Geschw, in % vom Basiswert (PNU540
-        byte sbyte5= (byte)(pos& 0xff);
-        byte sbyte6= (byte)(pos>>8 & 0xff);
-        byte sbyte7= (byte)(pos>>16 & 0xff);
-        byte sbyte8= (byte)(pos>>24 & 0xff);
-
-        CompletableFuture<ReadHoldingRegistersResponse> f =
-                master.sendRequest(new WriteMultipleRegistersRequest(0,4, new byte[]{
-                        ccon,
+        cdir|=(0<<3);   // Function Number Kurvenscheibenfunktion (0=nein)
+        cdir|=(0<<4);   // Function Number Kurvenscheibenfunktion (0=nein)
+        cdir|=(0<<5);   // Function Group Kurvenscheibenfunktion (0=nein)
+        cdir|=(0<<6);   // Function Group Kurvenscheibenfunktion (0=nein)
+        cdir|=(0<<7);   // 0 = normal; 1=kurvenscheibenfunktion
+
+        byte sbyte4=5; // Geschw, in % vom Basiswert (PNU540
+        byte sbyte8= (byte)(pos& 0xff);
+        byte sbyte7= (byte)(pos>>8 & 0xff);
+        byte sbyte6= (byte)(pos>>16 & 0xff);
+        byte sbyte5= (byte)(pos>>24 & 0xff);
+
+        send(new byte[]{ccon,
                         cpos,
                         cdir,
                         sbyte4,
                         sbyte5,
                         sbyte6,
                         sbyte7,
-                        sbyte8}), 0);
+                        sbyte8,
+                },4);
     }
 
     public CompletableFuture<Status> readStatus() {

+ 93 - 0
src/main/java/at/acdp/urweb/fhpp/Status.java

@@ -0,0 +1,93 @@
+package at.acdp.urweb.fhpp;
+
+import java.util.StringJoiner;
+
+public class Status {
+    //SCON
+    public int opm;
+    public boolean fct;
+    public boolean rdyen;
+    public boolean fault;
+    public boolean warn;
+    public boolean open;
+    public boolean enabled;
+
+    //SPOS
+    public boolean ref; /** antrieb referenzieren */
+    public boolean still; /** stillstandsüberwachung */
+    public boolean dev; /** schleppfehler */
+    public boolean mov; /** achse bewegt sich */
+    public boolean teach; /** Quittung teachen */
+    public boolean mc; /** motion complete*/
+    public boolean ack; /** quittung start*/
+    public boolean halt; /** halt*/
+
+    //SDIR
+    public boolean func; /** funktion wird ausgeführt */
+    public int fgrp; /** rückmeldung funktionsgruppe */
+    public int fnum; /** rückmeldung funktionsmodus */
+    public int com; /** rückmeldung regelmodus */
+    public boolean abs;
+
+    @Override
+    public String toString() {
+        return new StringJoiner("<br>", Status.class.getSimpleName() + "[", "]")
+                .add("opm=" + opm)
+                .add("fct=" + fct)
+                .add("rdyen=" + rdyen)
+                .add("fault=" + fault)
+                .add("warn=" + warn)
+                .add("open=" + open)
+                .add("enabled=" + enabled)
+                .add("ref=" + ref)
+                .add("still=" + still)
+                .add("dev=" + dev)
+                .add("mov=" + mov)
+                .add("teach=" + teach)
+                .add("mc=" + mc)
+                .add("ack=" + ack)
+                .add("halt=" + halt)
+                .add("func=" + func)
+                .add("fgrp=" + fgrp)
+                .add("fnum=" + fnum)
+                .add("com=" + com)
+                .add("abs=" + abs)
+                .toString();
+    }
+
+    public static String byteArrayToHex(byte[] a) {
+        StringBuilder sb = new StringBuilder(a.length * 2);
+        for(byte b: a)
+            sb.append(String.format("%02x", b));
+        return sb.toString();
+    }
+
+
+    public void read(byte[] status) {
+        byte scon=status[0];
+        opm =  (scon & (1 <<7)  | scon & (1 <<6));
+        fct = (scon & (1 << 5))>0;
+        rdyen = (scon & (1 << 4))>0;
+        fault = (scon & (1 << 3))>0;
+        warn = (scon & (1 << 2))>0;
+        open = (scon & (1 << 1))>0;
+        enabled = (scon & (1 << 0))>0;
+
+        byte spos=status[1];
+        ref = (spos & (1 << 7)) > 0;
+        still = (spos & (1 << 6)) > 0;
+        dev = (spos & (1 << 5)) > 0;
+        mov = (spos & (1 << 4)) > 0;
+        teach = (spos & (1 << 3)) > 0;
+        mc = (spos & (1 << 2)) > 0;
+        ack = (spos & (1 << 1)) > 0;
+        halt = (spos & (1 << 0)) > 0;
+
+        byte sdir=status[2];
+        func = (sdir & (1 << 7)) > 0;
+        fgrp = (sdir >> 5) & 0x3;
+        fnum = (sdir >> 3) & 0x3;
+        com = (sdir >> 1) & 0x3;
+        abs = (sdir & (1 << 0)) > 0;
+    }
+}

+ 7 - 0
src/main/java/at/acdp/urweb/web/XRServer.java

@@ -17,6 +17,13 @@ public class XRServer {
         return "ref";
     }
 
+    @XRMethod(value = "pos", help = "pos")
+    public static void pos(String pos) {
+       //Main.fhm.prepare();
+       Main.fhm.direktAuftrag(Integer.parseInt(pos),0);
+       Main.fhm.direktAuftrag(Integer.parseInt(pos),1);
+    }
+
     @XRMethod(value = "status", help = "Returns status")
     public static String status() {
         var x=Main.fhm.readStatus();