Using socketdev as INOUT parameter.

Hello,

I have to discuss between one robot and two computers using socket.
To get a generic module, I create a StartConnect function. Who call SocketCreate and SocketConnect and manage error.
Then I use other function to send and receive data.
So I imagine using a record for each computer with address, port socketdev and other things.
I put the record as function parameter like this:

  RECORD Cir_Param
    string sAdrServer;
    num nPortServer;
    socketdev sdSocketServer;
    num nMaxTimeSocket;
    num nMAXTRY;
    string sReceivedString;
  ENDRECORD
  LOCAL FUNC bool StartClient(INOUT Cir_Param pcirParam)
    SocketCreate pcirParam.sdSocketServer;
    SocketConnect pcirParam.sdSocketServer,pcirParam.sAdrServer,pcirParam.nPortServer\Time:=pcirParam.nMaxTimeSocket;
  ENDFUNC

But when I check program, I’ve got :

Type error(83): Cir_Param not value type.
This is due to socketdev in RECORD. When I remove it and comment lines using it. No error is reported.
So, how can I passe socketdev as parameter?
As each computer must have own socketdev.
And I don’t want to make a function for each.

Best regards

First, why a function with the return type bool? I don’t see that in there to return a true or false. Why not a proc? Second, why inout parameter? That is why you cannot have a non-value parameter. leave that off and you can use non-value parameter.

Sorry, wrong about the non-value parameter. Trying to make a workaround.

Maybe this will work. Good luck.

MODULE moduletest
ALIAS socketdev sdSocketServer;

RECORD Cir_Param
string sAdrServer;
num nPortServer;
num nMaxTimeSocket;
num nMAXTRY;
string sReceivedString;
ENDRECORD

CONST Cir_Param pcirParam := [" “,192,5,2,” "];

PROC StartClient(Cir_Param tempParam,
string stSocketServer)

SocketCreate ArgName(stSocketServer);
SocketConnect ArgName(stSocketServer),tempParam.sAdrServer,tempParam.nPortServer\Time:=tempParam.nMaxTimeSocket;
ENDPROC

PROC first()
StartClient pcirParam, “firstcomputer”;
ENDPROC

PROC second()
StartClient pcirParam, “secondcomputer”;
ENDPROC
ENDMODULE

Hello,
This is an example without all code…
Thanks, with your example I can get this code running.

MODULE MainModule
  RECORD Cir_Param
    string sAdrServer;
    num nPortServer;
    string sdSocketServerName;!!socketdev non value data.
    num nMaxTimeSocket;
    string sReceivedString;
  ENDRECORD

  VAR socketdev sdC1;
  VAR socketdev sdC2;
  PERS Cir_Param cirParamC1:=["192.168.1.12",20001,"sdC1",60,2,"Test OK"];
  PERS Cir_Param cirParamC2:=["192.168.1.13",20001,"sdC2",60,2,"Test OK"];

  PROC main()
    IF SendReceive("Test",cirParamC1) THEN
      TPWrite cirParamC1.sReceivedString;
    ENDIF
    IF SendReceive("Test",cirParamC2) THEN
      TPWrite cirParamC2.sReceivedString;
    ENDIF
  ENDPROC

  FUNC bool StartClient(INOUT Cir_Param pcirParam)
    !
    VAR socketstatus vssStatus;
    VAR socketdev sdSocket;
    !
    GetDataVal pcirParam.sdSocketServerName,sdSocket;
    vssStatus:=SocketGetStatus(sdSocket);
    IF vssStatus<>SOCKET_CLOSED THEN
      SocketClose sdSocket;
    ENDIF
    !
    SocketCreate sdSocket;
    SocketConnect sdSocket,pcirParam.sAdrServer,pcirParam.nPortServer\Time:=pcirParam.nMaxTimeSocket;
    SetDataVal pcirParam.sdSocketServerName,sdSocket;
    !
    RETURN TRUE;
  ERROR
    Stop;
    RETURN FALSE;
  ENDFUNC

  FUNC bool SendReceive(string psToSend,INOUT Cir_Param pcirParam)
    !
    VAR socketdev sdSocket;
    VAR string vsReceived;! Can't use pcirParam.sReceivedString directly in SocketReceive (40156 Argument error)
    !
    IF NOT StartClient(pcirParam) RETURN FALSE;
    GetDataVal pcirParam.sdSocketServerName,sdSocket;
    SocketSend sdSocket\Str:=psToSend;
    SocketReceive sdSocket\Str:=vsReceived\Time:=pcirParam.nMaxTimeSocket;
    pcirParam.sReceivedString:=vsReceived;
    SocketClose sdSocket;
    SetDataVal pcirParam.sdSocketServerName,sdSocket;
    !
    RETURN TRUE;
  ERROR
    Stop;
    SocketClose sdSocket;
    RETURN FALSE;
  ENDFUNC
ENDMODULE

Great!