WriteImage

Use the WriteImage function Functions are tools that are available in Spreadsheet for processing and analyzing acquisitions or other results. You can add functions to your Spreadsheet job to create tool chains and produce results for specific applications. to save the current image to a local device or an FTP, SFTP, or TCP server. Optionally, you can create an SVG file, which includes the overlay graphics on top of the image.

Note:

Format the File Name Parameter

You can format the File Name parameter so that the names are aligned, by using the '|' character. If a '|' is used, the value is either zero, or blank-filled. If the character immediately following a '|' is 0, the format is zero-filled; otherwise, it is blank-filled. The next character(s) indicate how many 0 or ' ' to insert. If the filename contains multiple ‘|’ characters, the last one is used as the format indicator. If the ‘|’ character is not followed by a digit, then the ‘|’ is used as part of the name, following the restrictions of any operating system.

If File Name is set to MyImage, the saved file names are the following:

If File Name is set to MyImage|03, the saved file names are the following:

If File Name is set to MyImage|3, the saved file names are the following:

If the '|' is in the middle of the file name, the Append Value is inserted inline. For example, if File Name is set to Fail_Image|03JobX, the saved file names are the following:

TCP Message Format

The TCP message format contains a fixed header containing the image size, image type and file name. The header is followed by the image data described by the header.

Section Contents Size
Header Image Size 4 bytes
Image Type

4 bytes

Valid values:

0 BMP
1 PNG
2 JPG
9 SVG
Image File Name

128 bytes

Body Image Data Variable
Note: If the file name exceeds the fixed length when you selected TCP Server for Storage, the function returns #ERR.

The TCP server has to use the provided filename when saving image data to file when the SVG Graphics parameter is set to SVG Overlay. The metadata in the SVG requires the filename of the image for the SVG overlay to work correctly.

Sample TCP Server

Copy
""" 
This code is provided as an example and is not guaranteed to be perfect. It is not intended for use in a production environment 
without further testing and validation. The author and the organization they represent are not responsible for any issues  
that may arise from using this code. 
""" 

import socket 
import struct 

# host machine IP address and port 
server_ip = "<insert host ip>" 
server_port = 4444 

# Create a socket object 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 

# Bind the socket to a specific address and port 
s.bind((server_ip, server_port)) 

# Start listening for incoming connections 
s.listen(1

print("Server is listening on port", server_port) 

filesRecieved = 0 

try
    # Receive data from the client 
    while True
        # Accept a connection 
        print("Waiting on connection..."
        c, addr = s.accept() 
        print("Got connection from", addr) 

        data = "" 

        while True
            # Read header 
            data = c.recv(8 + 128
            print("Recieved header length", len(data)) 
            if not data: 
                print("Header not recieved, aborting read"
                break 

            fileSize = 0 
            fileSizeBuffer = data[:4
            fileSize = struct.unpack("<I", fileSizeBuffer)[0
            print("FileSize", fileSize) 
            fileTypeBuffer = data[4:8
            fileType = struct.unpack("<I", fileTypeBuffer)[0
            print("FileType", fileType) 
            fileNameBuffer = data[8:] 
            fileName = struct.unpack("128s", fileNameBuffer)[0
            print("FileName", fileName.decode()) 

            # Read data in 1024 packets 

            recieved = 0 
            while recieved < fileSize: 
                readPacketSize = 1024 
                if fileSize - recieved < 1024
                    readPacketSize = fileSize - recieved 
                data = c.recv(readPacketSize) 
                recieved += len(data) 

                if not data: 
                    print("Got bad data packet aborting file read"
                    break 

            # Save the file 
            filesRecieved += 1 
            print("Files Recieved", filesRecieved, "Last file size:", fileSize) 
            print(""

except KeyboardInterrupt: 
    print("\nExiting"