// File: Eba-M[P]E3DC-Control/RscpExampleMain.cpp
// Function: iModbusTCP_Get(int, int, int)
long iModbusTCP_Get(int reg,int val,int tac) //val anzahl register lesen
{
    send.resize(12);
    receive.resize(2048);

    Modbus_send Msend;
    Modbus_receive Mreceive;

    Msend.Tid = (tn*256+tac);
    tn++;
    Msend.Pid = 0;
    Msend.Mlen = 6*256;
    Msend.Dev = 1;  // Devadr. 1 oder 255
    Msend.Fcd = 3; // Funktioncode
    //            Msend.Fcd = 6; // Funktioncode
    Msend.Reg = reg*256;  // Adresse Register // Aussentemperatur
    Msend.Count = (val%256)*256; // Inhalt    int size = send.size();
    Msend.Count = Msend.Count + val/256; // Inhalt    int size = send.size();

    memcpy(&send[0],&Msend,send.size());
    if (e3dc_config.debug)
        printf("BRQ");
    printf(" Get %i %i ",reg, val);

/*
    if (isocket > 0)
    {
        iLength = SocketRecvData(isocket,&receive[0],receive.size());
        if (iLength < 0)
        {
            SocketClose(isocket);
            isocket = -1;
        }
    }

    if (isocket<0)
    {
        sprintf(server_ip,e3dc_config.heizung_ip);
        if (e3dc_config.debug)
            printf("BSC");

        isocket = SocketConnect(server_ip, 502);
        if (e3dc_config.debug)
            printf("ASC");

    }
*/
    if (brequest) 
    {
        printf(" len %i ",iLength);
        return iLength;
    }
if (isocket > 0)
 {
     iLength = SocketSendData(isocket,&send[0],send.size());
     if (e3dc_config.debug)
         printf("BRCV");
     iLength = SocketRecvData(isocket,&receive[0],receive.size());
         brequest = true;
 }
        if (e3dc_config.debug)
        printf("ARCV");
    printf(" len %i ",iLength);
    return iLength;
}

// Assembly:
subq $0x1e8, %rsp            # imm = 0x1E8
movl %edi, 0x1dc(%rsp)
movl %esi, 0x1d8(%rsp)
movl %edx, 0x1d4(%rsp)
leaq 0x69ecd(%rip), %rdi     # 0x6fc80
movl $0xc, %esi
callq 0x1cb60
leaq 0x69ed4(%rip), %rdi     # 0x6fc98
movl $0x800, %esi            # imm = 0x800
callq 0x1cb60
movzbl 0x6854f(%rip), %eax     # 0x6e324
shll $0x8, %eax
addl 0x1d4(%rsp), %eax
movw %ax, 0x102(%rsp)
movb 0x68537(%rip), %al      # 0x6e324
addb $0x1, %al
movb %al, 0x6852f(%rip)      # 0x6e324
movw $0x0, 0x104(%rsp)
movw $0x600, 0x106(%rsp)     # imm = 0x600
movb $0x1, 0x108(%rsp)
movb $0x3, 0x109(%rsp)
movl 0x1dc(%rsp), %eax
shll $0x8, %eax
movw %ax, 0x10a(%rsp)
movl 0x1d8(%rsp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
shll $0x8, %edx
movw %dx, %ax
movw %ax, 0x10c(%rsp)
movzwl 0x10c(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x1d8(%rsp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %eax, %ecx
movl 0x24(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x10c(%rsp)
leaq 0x69e06(%rip), %rdi     # 0x6fc80
xorl %eax, %eax
movl %eax, %esi
callq 0x1cc00
movq %rax, 0x28(%rsp)
leaq 0x69df1(%rip), %rdi     # 0x6fc80
callq 0x1cc20
movq 0x28(%rsp), %rdi
movq %rax, %rdx
leaq 0x102(%rsp), %rsi
callq 0x2220
testb $0x1, 0x68fb1(%rip)     # 0x6ee61
je 0x5ec0
leaq 0x5aa0c(%rip), %rdi     # 0x608c5
movb $0x0, %al
callq 0x2040
movl 0x1dc(%rsp), %esi
movl 0x1d8(%rsp), %edx
leaq 0x5a9f4(%rip), %rdi     # 0x608c9
movb $0x0, %al
callq 0x2040
testb $0x1, 0x69ea9(%rip)     # 0x6fd8c
je 0x5f0e
movq 0x69d74(%rip), %rsi     # 0x6fc60
leaq 0x5a9c9(%rip), %rdi     # 0x608bc
movb $0x0, %al
callq 0x2040
movq 0x69d5f(%rip), %rax     # 0x6fc60
movq %rax, 0x1e0(%rsp)
jmp 0x5ffc
cmpl $0x0, 0x69e73(%rip)     # 0x6fd88
jle 0x5fc1
movl 0x69e67(%rip), %eax     # 0x6fd88
movl %eax, 0x14(%rsp)
leaq 0x69d54(%rip), %rdi     # 0x6fc80
xorl %eax, %eax
movl %eax, %esi
callq 0x1cc00
movq %rax, 0x18(%rsp)
leaq 0x69d3f(%rip), %rdi     # 0x6fc80
callq 0x1cc20
movl 0x14(%rsp), %edi
movq 0x18(%rsp), %rsi
movl %eax, %edx
callq 0x364e0
cltq
movq %rax, 0x69d01(%rip)     # 0x6fc60
testb $0x1, 0x68efb(%rip)     # 0x6ee61
je 0x5f76
leaq 0x5a966(%rip), %rdi     # 0x608d5
movb $0x0, %al
callq 0x2040
movl 0x69e0c(%rip), %eax     # 0x6fd88
movl %eax, 0x4(%rsp)
leaq 0x69d11(%rip), %rdi     # 0x6fc98
xorl %eax, %eax
movl %eax, %esi
callq 0x1cc00
movq %rax, 0x8(%rsp)
leaq 0x69cfc(%rip), %rdi     # 0x6fc98
callq 0x1cc20
movl 0x4(%rsp), %edi
movq 0x8(%rsp), %rsi
movl %eax, %edx
callq 0x36590
cltq
movq %rax, 0x69ca6(%rip)     # 0x6fc60
movb $0x1, 0x69dcb(%rip)     # 0x6fd8c
testb $0x1, 0x68e99(%rip)     # 0x6ee61
je 0x5fd8
leaq 0x5a909(%rip), %rdi     # 0x608da
movb $0x0, %al
callq 0x2040
movq 0x69c81(%rip), %rsi     # 0x6fc60
leaq 0x5a8d6(%rip), %rdi     # 0x608bc
movb $0x0, %al
callq 0x2040
movq 0x69c6c(%rip), %rax     # 0x6fc60
movq %rax, 0x1e0(%rsp)
movq 0x1e0(%rsp), %rax
addq $0x1e8, %rsp            # imm = 0x1E8
retq
nopl (%rax)