Skip to main content

10.5.9.5. Example 2 – Binary communication

10.5.9.5. Example 2 – Binary communication

 

This work program receives 10 shift data in binary format from a remote PC and transmits the result data in binary format.

 

DIM liR,liB AS Integer

     _TEINPUT=-(4*6*10) “Count of bytes to be received: 4-byte integer*6 elements * 10

     '

     'Ethernet setting -----------

     ENET1.IP="192.168.1.172"

     ENET1.LPORT=500

     ENET1.RPORT=7000

     ENET1.OPEN 1

     CLR_RBUF ENET1

     '

     'Shift data transfer request

     PRINT ENET1,"REQ_SHIFT" 'Shift data request

     '

     'Wait for result response

     INPUT ENET1,BUFV[0],8,*NO_RESP

     '

     'Interpretation of the result (signed integer, little endian, 4byte, x1000 normalization)

     'R101~R110  <=  BUFV[0~239]

     R1=(0,0,0,0,0,0)

     FOR liR=101 TO 110

       R1.X=BUFV[liB+0].s4/1000.

       R1.Y=BUFV[liB+4].s4/1000.

       R1.Z=BUFV[liB+8].s4/1000.

       R1.RX=BUFV[liB+12].s4/1000.

       R1.RY=BUFV[liB+16].s4/1000.

       R1.RZ=BUFV[liB+20].s4/1000.

       R[liR]=R1

       liB=liB+4*6

     NEXT

     '

     'Transmission of the result

     BUFV[500].s4=1 'ACK

     ENET1.SEND BUFV[500],4

     ENET1.OPEN 0

     END

     '

     'Handling as an exception  -----------

     *NO_RESP

     PRINT #0,"There is no response to the shift data request."

     END