From TechnoDocs
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.
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.
Things to keep in mind:
- When reading and writing files, make sure you're always reading the most recent line, or when writing, empty the file first.
- Be sure to create a parser in both programs to handle all possible commands
'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