1. 机器人侧有400个num型数据希望一次性通过Socket发送,如何处理?
2. 可以利用PackRawbyte\ float4指令将对应的数据进行打包,并存入rawbyte数据(单个rawbyte最大为1024个字节)
VAR socketdev temp_socket;
VAR socketdev client_socket;
VAR rawbytes rawbyte1{10};
VAR num senddata{400};
PROC main()
FOR i FROM 1 TO 10 DO
ClearRawBytes rawbyte1{i};
ENDFOR
FOR i FROM 1 TO 400 DO
senddata{i}:=i+0.2;
!对数据赋值
ENDFOR
!由于rawbyte最大为1024字节,4个字节组成一个float,所以循环256
FOR i FROM 1 TO 256 DO
PackRawBytes senddata{i},rawbyte1{1},(4*i-3)\Float4;
ENDFOR
FOR i FROM 257 TO 400 DO
PackRawBytes senddata{i},rawbyte1{2},(4*(i-256)-3)\Float4;
ENDFOR
!以上代码将400组num型数据连续存放入rawbyte1{1}中的1-1024字节和rawbyte1{2}中的1- 576字节
将400组num型数据打包好以后,可以通过以下指令来发送
SocketSend \RawData:=rawbyte1{1};
3. 完整通过socket发送400组num型数据代码如下
VAR socketdev temp_socket;
VAR socketdev client_socket;
VAR rawbytes rawbyte1{10};
VAR num senddata{400};
PROC main()
SocketClose client_socket;
SocketClose temp_socket;
SocketCreate temp_socket;
SocketBind temp_socket,"127.0.0.1",8001;
SocketListen temp_socket;
SocketAccept temp_socket,client_socket;
FOR i FROM 1 TO 10 DO
ClearRawBytes rawbyte1{i};
ENDFOR
FOR i FROM 1 TO 400 DO
senddata{i}:=i+0.2;
ENDFOR
FOR i FROM 1 TO 256 DO
PackRawBytes senddata{i},rawbyte1{1},(4*i-3)\Float4;
ENDFOR
FOR i FROM 257 TO 400 DO
PackRawBytes senddata{i},rawbyte1{2},(4*(i-256)-3)\Float4;
ENDFOR
SocketReceive client_socket\Str:=received_string;
SocketSend client_socket\RawData:=rawbyte1{1};
SocketSend client_socket\RawData:=rawbyte1{2};
ABB工业机器人socket发送400组num型数据就说到这里了,以上方法仅供大家参考,希望对你们有所帮助,如有不足之处,欢迎大家留言探讨,如果有需要软件安装包的朋友,可以加小编微信备注我要软件即可获取!小编在看到信息后第一时间给大家奉上!想看更多精彩的文章请持续关注哦。
—THE END—
点点在看给小编加个鸡腿
|