Techno CNC Systems
 

Systems Integrators and other power users sometimes need to implement communication between the Techno CNC Controller and other custom software. This is sometimes done via a DLL (Dynamic Link Library).

Given the rare and complex nature of these tasks, Techno has decided to implement a different methodology to enable this behavior. This new methodology removes the issues frequently found when using various compilers and OSes. This method is even able to work across a network and with different operating systems (linux, mac, etc)

Instead of writing code around the Techno DLL which can be difficult and time consuming, users are now advised to write a SAC script in the techno cnc interface with the ability to communicate with external software via two files dynamically stored on the hard disk. This allows for extreme flexibility, robustness and ease of programming.

One file is used to send commands and data from the custom software to the SAC portion of the CNC interface, and another file is used to send commands and data from SAC to the custom software. While this could be done with only one file, it is far simper to use two files.

In most local software cases, SAC can be used to launch the custom software and initiate the process.

Some example code for reading and writing the communication files from SAC is below.

Things to keep in mind:

  1. When reading and writing files, make sure you're always reading the most recent line, or when writing, empty the file first.
  2. Be sure to create a parser in both programs to handle all possible commands
  3. If you will be using SAC to run G-code, you will likely want to implement the features in the SAC writup called get_sac_reset and sac_focus_loss.
'Example of executing a program...
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run ("%windir%\notepad")


'EXAMPLE OF READING AND WRITING TO SEPARATE FILES FOR COMMUNICATION PURPOSES 
'file reading/writing stuff:
'http://msdn.microsoft.com/en-us/library/czxefwt8%28v=vs.85%29.aspx

DIM SERIAL_NUMBER
DIM TEXT_FROM_FILE
SERIAL_NUMBER=1

SENDTEXT ("COMMUNICATION")
READTEXT ()
MSGBOX("File contents = "& TEXT_FROM_FILE )

MSGBOX("Operations Complete!")


PUBLIC FUNCTION SENDTEXT (TEXT_TO_SEND)
DIM FSO, FILEOBJECT
   Set FSO = CreateObject("Scripting.FileSystemObject")
   If FSO.FileExists("C:\SAC_TO_INTERFACE.TXT") Then 
      'SOMETHING HERE IF YOU DIDN'T KNOW THE FILE EXISTED
   Else
      'SOMETHING HERE IF YOU EXPECTED IT TO EXIST AND IT DOESN'T
   End If
   'CREATE OR REPLACE THE EXISTING FILE
   Set FileObject = FSO.CreateTextFile ("C:\SAC_TO_INTERFACE.TXT")
   FileObject.WriteLine TEXT_TO_SEND & "|| " & SERIAL_NUMBER & " ||" & Now()
   SERIAL_NUMBER = SERIAL_NUMBER +1
   FileObject.Close()
END FUNCTION


PUBLIC FUNCTION READTEXT ()
DIM FSO, FILEOBJECT

   Set FSO = CreateObject("Scripting.FileSystemObject")
   If FSO.FileExists("C:\INTERFACE_TO_SAC.TXT") Then 
      'GOOD, IT SHOULD. 
   Else
      MSGBOX("FILE IS NOT PRESENT! IF YOU ARE TESTING, MAKE A FILE WITH SOME STUFF IN IT.")
      'ERROR HANDLING
      EXIT FUNCTION
   End If
   
   'OPEN THE EXISTING FILE
   Set FILEOBJECT = FSO.OpenTextFile("C:\INTERFACE_TO_SAC.TXT", 1)
   TEXT_FROM_FILE = FILEOBJECT.ReadLine
   FILEOBJECT.Close
   'Delete the line from the other software after you're sure it has been read here
   'Otherwise, be sure to read the last line of the file when you read.
   'Send TEXT_FROM_FILE to your parser
END FUNCTION
 
Copyright ©  Techno CNC Systems, LLC. All rights reserved.