scripting_for_plc_servers
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| scripting_for_plc_servers [2021/01/29 11:19] – wikiadmin | scripting_for_plc_servers [2021/09/10 17:09] (current) – wikiadmin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==== TransSECS Devices - Scripting for PLC Servers ==== | + | ===== TransSECS Devices - Scripting for PLC Servers |
| To write a value to a server in the devices the format is: | To write a value to a server in the devices the format is: | ||
| Line 30: | Line 30: | ||
| </ | </ | ||
| - | **Set a value to a field in a message and send the message** | + | ==== Set a value to a field in a message and send the message |
| Line 43: | Line 43: | ||
| </ | </ | ||
| - | Here's a more concreted | + | Here's a more concrete |
| <code javascript> | <code javascript> | ||
| Line 65: | Line 65: | ||
| </ | </ | ||
| - | **Register for Connection Status Notification in TransSECS Host Application** | + | ==== Register for Connection Status Notification in TransSECS Host Application |
| In a GEMHost application the TransSECS controller publishes the status of the connection. | In a GEMHost application the TransSECS controller publishes the status of the connection. | ||
| Line 98: | Line 98: | ||
| The details of the connection status are [[programmatic_host_connection_status|described here]] | The details of the connection status are [[programmatic_host_connection_status|described here]] | ||
| - | **Sending | + | ==== Writing |
| If a message is received from the host contains a list of variable length it's easy to split this list and place it in registers on the PLC. | If a message is received from the host contains a list of variable length it's easy to split this list and place it in registers on the PLC. | ||
| Line 134: | Line 134: | ||
| </ | </ | ||
| - | **Reading a Variable Length List from a PLC and updating a VID** | + | ==== Reading a Variable Length List from a PLC and updating a VID ==== |
| The most challenging part of reading the list from the PLC is managing the length of the list. | The most challenging part of reading the list from the PLC is managing the length of the list. | ||
| Line 199: | Line 199: | ||
| Discrete - SecsFormat11 | Discrete - SecsFormat11 | ||
| - | Note that the signed | + | For an S7 Array the conversions |
| + | |||
| + | For improved control over the conversion, the SecsFormat00 | ||
| In this example we create a SecsFormat00 containing signed integers | In this example we create a SecsFormat00 containing signed integers | ||
| Line 225: | Line 227: | ||
| } | } | ||
| new SecsFormatValueObject(listValue); | new SecsFormatValueObject(listValue); | ||
| + | </ | ||
| + | |||
| + | ==== Reading a File and Storing as Binary Data in the PLC ==== | ||
| + | |||
| + | This example uses the Melsec Binary (MelsecBinary) server. | ||
| + | |||
| + | |||
| + | < | ||
| + | var Deflater = Java.type(" | ||
| + | var Inflater = Java.type(" | ||
| + | var Files = Java.type(" | ||
| + | var BinaryValueObject = Java.type(" | ||
| + | var LongValueObject = Java.type(" | ||
| + | var arrayOfBytes = Java.type(" | ||
| + | |||
| + | recipe = Files.readAllBytes(java.nio.file.Paths.get(" | ||
| + | // Compress the bytes | ||
| + | output = new arrayOfBytes(2000); | ||
| + | compresser = new Deflater(); | ||
| + | compresser.setInput(recipe); | ||
| + | compresser.finish(); | ||
| + | compressedDataLength = compresser.deflate(output); | ||
| + | compresser.end(); | ||
| + | outArray = new arrayOfBytes(compressedDataLength); | ||
| + | java.lang.System.arraycopy(output, | ||
| + | |||
| + | // save the length of the compress recipe to the PLC using a server called " | ||
| + | CompressedRecipeLength-> | ||
| + | |||
| + | new BinaryValueObject(outArray); | ||
| + | </ | ||
| + | |||
| + | The inverse of the above code reads the bytes from the PLC and stores them to a file. | ||
| + | |||
| + | < | ||
| + | var Deflater = Java.type(" | ||
| + | var Inflater = Java.type(" | ||
| + | var Files = Java.type(" | ||
| + | var BinaryValueObject = Java.type(" | ||
| + | var StringValueObject = Java.type(" | ||
| + | var arrayOfBytes = Java.type(" | ||
| + | |||
| + | // read the length of the compress recipe from the PLC using a server called " | ||
| + | CompressedRecipeLength-> | ||
| + | compressedDataLength = CompressedRecipeLength-> | ||
| + | |||
| + | java.lang.System.out.println | ||
| + | // Compress the bytes | ||
| + | output = new arrayOfBytes(2000); | ||
| + | inflater = new Inflater(); | ||
| + | buf = incomingValue.getBinaryValue(); | ||
| + | |||
| + | inflater.setInput(buf, | ||
| + | |||
| + | resultLength = inflater.inflate(output); | ||
| + | inflater.end(); | ||
| + | |||
| + | // trim the array to the size of of the output | ||
| + | outArray = new arrayOfBytes(resultLength); | ||
| + | java.lang.System.arraycopy(output, | ||
| + | |||
| + | Files.write(java.nio.file.Paths.get(" | ||
| + | |||
| </ | </ | ||
scripting_for_plc_servers.1611937198.txt.gz · Last modified: by wikiadmin
