byte-motion / RNL_RAPIDLibrary

A standard library of functionality for the RAPID programming language
MIT License
0 stars 1 forks source link

Asynchronous messaging over IO buss #51

Open TheHarvard opened 3 years ago

TheHarvard commented 3 years ago

Possible implementation:

(Seems to be only implemented for device net?)

image

image


PROC set_filter_value()  VAR iodev dev;
 VAR rawbytes rawdata_out;
 VAR rawbytes rawdata_in;
 VAR num input_int;
 VAR byte return_status;
 VAR byte return_info;
 VAR byte return_errcode;
 VAR byte return_errcode2;
  ! Empty contents of rawdata_out and  rawdata_in ClearRawBytes rawdata_out; ClearRawBytes rawdata_in;
  ! Add DeviceNet header to rawdata_out  with service 
! "SET_ATTRIBUTE_SINGLE" and path to  filter attribute on 
! DeviceNet I/O device 
PackDNHeader "10", "6,20 1D 24 01 30  64,8,1", rawdata_out;  
! Add filter value to send to DeviceNet  I/O device 
input_int:= 5; PackRawBytes input_int,  rawdata_out,(RawBytesLen(rawdata_out) + 1) \IntX := USINT;  
! Open I/O device 
Open "/FCI1:" \File:="board328", dev  \Bin;  
! Write the contents of rawdata_out to  the I/O device 
WriteRawBytes dev, rawdata_out  \NoOfBytes := RawBytesLen(rawdata_out);  
! Read the answer from the I/O  device 
ReadRawBytes dev, rawdata_in;  
! Close the I/O device 
Close dev;  
! Unpack rawdata_in to the variable  return_status 
UnpackRawBytes rawdata_in, 1,  return_status \Hex1;
   IF return_status = 144 THEN  TPWrite "Status OK from device. Status  code:
 "\Num:=return_status; ELSE  
! Unpack error codes from device  answer UnpackRawBytes rawdata_in, 2,  return_errcode \Hex1; UnpackRawBytes rawdata_in, 3,  return_errcode2 \Hex1; 
TPWrite "Error code from device: "  \Num:=return_errcode; 
TPWrite "Additional error code from  device: " \Num:=return_errcode2; 
ENDIF ENDPROC
--
SThoBergtun commented 3 years ago

I think that I found this proc when I was setting up the Balluff light on DeviceNet and tried it, but I couldn't get it to work...

And for it to work on DeviceNet is better than not working on any bus-network.

RobotTore commented 3 years ago

This is a code for setting up DeviceNet, and will not work with other kind of fieldbus,