Using socketdev as INOUT parameter.
DenisFR
✭✭✭
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:
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
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<br> string sAdrServer;<br> num nPortServer;<br> socketdev sdSocketServer;<br> num nMaxTimeSocket;<br> num nMAXTRY;<br> string sReceivedString;<br> ENDRECORD<br> LOCAL FUNC bool StartClient(INOUT Cir_Param pcirParam)<br> SocketCreate pcirParam.sdSocketServer;<br> SocketConnect pcirParam.sdSocketServer,pcirParam.sAdrServer,pcirParam.nPortServer\Time:=pcirParam.nMaxTimeSocket;<br> ENDFUNC<br>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
Tagged:
0
Comments
-
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.Lee Justice0
-
Sorry, wrong about the non-value parameter. Trying to make a workaround.
Lee Justice0 -
Maybe this will work. Good luck.
MODULE moduletestALIAS socketdev sdSocketServer;RECORD Cir_Paramstring sAdrServer;num nPortServer;num nMaxTimeSocket;num nMAXTRY;string sReceivedString;ENDRECORDCONST 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;ENDPROCPROC first()StartClient pcirParam, "firstcomputer";ENDPROCPROC second()StartClient pcirParam, "secondcomputer";ENDPROCENDMODULELee Justice0 -
Hello,
This is an example without all code...
Thanks, with your example I can get this code running.<code>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
MODULE MainModule<br> RECORD Cir_Param<br> string sAdrServer;<br> num nPortServer;<br> string sdSocketServerName;!!socketdev non value data.<br> num nMaxTimeSocket;<br> string sReceivedString;<br> ENDRECORD<br><br> VAR socketdev sdC1;<br> VAR socketdev sdC2;<br> PERS Cir_Param cirParamC1:=["192.168.1.12",20001,"sdC1",60,2,"Test OK"];<br> PERS Cir_Param cirParamC2:=["192.168.1.13",20001,"sdC2",60,2,"0 -
Great!Lee Justice0
Categories
- All Categories
- 5.5K RobotStudio
- 394 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 309 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings