using System; using System.Runtime.InteropServices; namespace FalitPrint { public class LNCAPI { [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct ERROR_MSG { public byte Type; public byte Cmd; public byte Error; public byte Reserve; public int addr; public int num; } [StructLayout(LayoutKind.Explicit, Pack = 1)] public struct SC_DATA { [FieldOffset(0)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1440)] public byte[] Bytes; [FieldOffset(0)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 720)] public ushort[] Words; [FieldOffset(0)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 360)] public uint[] Ints; [FieldOffset(0)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 180)] public double[] Fixs; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct LOCAL_CONTROLLER_INFO { public uint IPLong; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] IP; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] Name; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct FTP_FILE { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] filename; public uint filesize; public ushort year; public byte month; public byte day; public byte hour; public byte minute; public byte second; public byte Reserve; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct FTP_TRANFER_FILE { public byte Folder; public string SubFolder; public string Filename; public string LocalFilename; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct FUNCTION_SETTING { public uint MakerID; public uint MakerPwd; public uint MediaIPLong1; public uint MediaIPLong2; public byte HaveMediaFunction; } public struct DLL_USE_SETTING { public uint TalkInfoNum; public uint SoftwareType; public uint MemSizeI; public uint MemSizeO; public uint MemSizeC; public uint MemSizeS; public uint MemSizeA; public uint MemSizeR; public uint MemSizeF; public uint MemSizeTimer; public uint MemSizeCounter; } private const string ReCON_DLL_NAME = "libs\\scif2_bcb.dll"; public const uint MAX_SYNC_COUNT = 10u; public const uint MAX_CONTROLLER_NUM_PER_MAKER = 300u; public const uint BIT_CB_SIZE = 4096u; public const uint INT_CB_SIZE = 20000u; public const uint FIX_CB_SIZE = 4096u; public const uint MAX_LOOP_SIZE = 64u; public const uint MAX_DIRECT_SIZE = 64u; public const uint DIRECT_ADDR_MASK = 63u; public const uint MAX_DATA_BYTES = 1440u; public const uint MAX_BIT_NUM = 1440u; public const uint MAX_WORD_NUM = 720u; public const uint MAX_INT_NUM = 360u; public const uint MAX_FIX_NUM = 180u; public const uint MAX_PTR_NUM = 180u; public const uint MAX_CB_NUM = 288u; public const uint MAX_CB_BIT_NUM = 288u; public const uint MAX_CB_WORD_NUM = 240u; public const uint MAX_CB_INT_NUM = 180u; public const uint MAX_CB_FIX_NUM = 120u; public const uint MAX_CB_PTR_NUM = 120u; public const uint I_OFFSET = 0u; public const uint O_OFFSET = 5120u; public const uint C_OFFSET = 10240u; public const uint S_OFFSET = 15360u; public const uint A_OFFSET = 20480u; public const uint TT_OFFSET = 25600u; public const uint CT_OFFSET = 30720u; public const uint RBIT_OFFSET = 100000u; public const uint R_OFFSET = 0u; public const uint RI_OFFSET = 8000000u; public const uint RO_OFFSET = 8100000u; public const uint RC_OFFSET = 8200000u; public const uint RS_OFFSET = 8300000u; public const uint RA_OFFSET = 8400000u; public const uint RTT_OFFSET = 8500000u; public const uint RCT_OFFSET = 8600000u; public const uint TV_OFFSET = 10000000u; public const uint TS_OFFSET = 10500000u; public const uint CV_OFFSET = 11000000u; public const uint CS_OFFSET = 11500000u; public const uint F_OFFSET = 10000000u; public const uint I_NUM = 4096u; public const uint O_NUM = 4096u; public const uint C_NUM = 4096u; public const uint S_NUM = 4096u; public const uint A_NUM = 4096u; public const uint R_NUM = 6000000u; public const uint F_NUM = 100000u; public const uint TIMER_NUM = 256u; public const uint COUNTER_NUM = 256u; public const uint PAC_STRING_SIZE = 20u; public const uint PAC_STRING_NUM = 21u; public const uint PAC_PATH_SIZE = 5000u; public const uint R_PATH_PAC_STRING = 3021500u; public const uint BLOCK_PATH_SIZE = 2000u; public const uint R_PATH_BLOCK_CURRENT = 3006072u; public const uint ALM_COUNT = 1790000u; public const uint WARN_COUNT = 1790500u; public const uint ALM_STRING = 1790010u; public const uint ALM_STRING_SIZR = 40u; public const uint WARN_STRING = 1790510u; public const uint WARN_STRING_SIZR = 40u; public const byte SCIF_PROC_COUNTER = 1; public const byte SCIF_MEDIA_STEP = 5; public const byte SCIF_MEDIA_STATE = 6; public const byte SCIF_MAKER_ID = 7; public const byte SCIF_FTP_STATE = 11; public const byte SCIF_FTP_RESULT = 12; public const byte SCIF_FTP_STEP = 13; public const byte SCIF_FTP_TOTAL_PACKAGE = 21; public const byte SCIF_FTP_CURRENT_PACKAGE = 22; public const byte SCIF_FTP_TOTAL_FILE = 31; public const byte SCIF_FTP_CURRENT_FILE = 32; public const uint SCIF_MEM_SIZE_I = 40u; public const uint SCIF_MEM_SIZE_O = 41u; public const uint SCIF_MEM_SIZE_C = 42u; public const uint SCIF_MEM_SIZE_S = 43u; public const uint SCIF_MEM_SIZE_A = 44u; public const uint SCIF_MEM_SIZE_R = 47u; public const uint SCIF_MEM_SIZE_F = 52u; public const uint SCIF_MEM_SIZE_TIMER = 45u; public const uint SCIF_MEM_SIZE_COUNTER = 46u; public const sbyte SCIF_CONNECT_STATE = 2; public const sbyte SCIF_REMOTE_IPLONG = 3; public const sbyte SCIF_CONNECT_STEP = 4; public const sbyte SCIF_CONNECT_RESPONSE = 5; public const sbyte SCIF_TALK_STATE = 6; public const sbyte SCIF_RESPONSE_TIME = 11; public const sbyte SCIF_OK_COUNT = 12; public const sbyte SCIF_CRC_ERR_CNT = 13; public const sbyte SCIF_LOOP_QUEUE_PKG_COUNT = 21; public const sbyte SCIF_DIRECT_QUEUE_PKG_COUNT = 22; public const sbyte SCIF_LOOP_COUNT = 23; public const sbyte SCIF_TX_PKG_CNT = 24; public const sbyte SCIF_TX_PKG_RETRY_CNT = 25; public const sbyte SCIF_TX_CONNECT_CNT = 26; public const sbyte SCIF_RX_UNEXPECT_CNT = 27; public const sbyte SCIF_RX_ERR_FMT_CNT = 28; public const sbyte SCIF_RX_CONNECT_CNT = 29; public const int SC_CONN_STATE_DISCONNECT = 0; public const int SC_CONN_STATE_CONNECTING = 1; public const int SC_CONN_STATE_FAIL = 2; public const int SC_CONN_STATE_OK = 3; public const int SC_CONN_STATE_NORESPONSE = 4; public const int CONNECT_RESULT_NORESPONSE = 0; public const int CONNECT_RESULT_OLD_SOFTWARE_CLEAR = 1; public const int CONNECT_RESULT_INVALID_SOFTWARE = 11; public const int CONNECT_RESULT_DISABLE_SOFTWARE = 12; public const int CONNECT_RESULT_DISABLE_INTERNET = 13; public const int CONNECT_RESULT_CLOSED_SOFTWARE = 14; public const int CONNECT_RESULT_CLOSED_INTERNET = 15; public const int CONNECT_RESULT_INVALID_MAKERID = 16; public const int CONNECT_RESULT_WAIT_CONFIRM = 21; public const int CONNECT_RESULT_SOFTWARE_CONNECTED = 31; public const int CONNECT_RESULT_SOFTWARE_REJECTED = 32; public const int CONNECT_RESULT_SOFTWARE_INREQ = 41; public const int CONNECT_RESULT_PENDING = 50; public const byte FTP_FOLDER_RUN_NCFILES = 1; public const byte FTP_FOLDER_RUN_DXF = 2; public const byte FTP_FOLDER_TEACH_RUN = 3; public const byte FTP_FOLDER_RECIPE_RUN = 4; public const byte FTP_FOLDER_WORKDATA_RUN = 5; public const byte FTP_FOLDER_NCFILES = 10; public const byte FTP_FOLDER_MACRO = 21; public const byte FTP_FOLDER_MACRO_MAKER = 20; public const byte FTP_FOLDER_OPEN_HMI = 24; public const byte FTP_FOLDER_NCFILES_ROOT = 25; public const byte FTP_FOLDER_MACRO_MAKER_ROOT = 26; public const byte FTP_FOLDER_MACRO_ROOT = 27; public const byte FTP_FOLDER_DXF = 28; public const byte FTP_FOLDER_OPEN_HMI_BOTTOM = 29; public const byte FTP_FOLDER_TEACH = 15; public const byte FTP_FOLDER_RECIPE = 16; public const byte FTP_FOLDER_WORKDATA = 17; public const byte FTP_FOLDER_MACHINE = 30; public const byte FTP_FOLDER_SETUP = 40; public const byte FTP_FOLDER_SETUP_MACHINE = 41; public const byte FTP_FOLDER_BAK = 50; public const byte FTP_FOLDER_DATA = 51; public const byte FTP_FOLDER_LANGUAGE = 52; public const byte FTP_FOLDER_LANGUAGE_DEF = 53; public const byte FTP_FOLDER_LOG = 54; public const byte FTP_FOLDER_RECORD = 55; public const byte FTP_STATE_IDLE = 0; public const byte FTP_STATE_UPLOAD = 1; public const byte FTP_STATE_DOWNLOAD = 2; public const byte FTP_STATE_DELETE = 3; public const byte FTP_STATE_LIST = 11; public const byte FTP_STATE_UPLOAD_MANY = 21; public const byte FTP_STATE_DOWNLOAD_MANY = 22; public const byte FTP_STATE_DELETE_MANY = 23; public const byte FTP_STATE_MAKE_DIR = 30; public const byte FTP_STATE_PENDING = 99; public const uint FTP_RESULT_IDLE = 0u; public const byte FTP_RESULT_PROCESSING = 1; public const byte FTP_RESULT_SUCCESS = 2; public const byte FTP_RESULT_FAIL_TO_READ_LOCAL_FILE = 11; public const byte FTP_RESULT_FAIL_TO_WRITE_LOCAL_FILE = 12; public const byte FTP_RESULT_FAIL_TO_READ_REMOTE_FILE = 13; public const byte FTP_RESULT_FAIL_TO_WRITE_REMOTE_FILE = 14; public const byte FTP_RESULT_FAIL_TO_SET_COMMAND = 15; public const byte FTP_RESULT_FAIL_TO_COMMUNICATION = 16; public const byte FTP_RESULT_FILE_MISMATCH = 17; public const uint TALK_STATE_NORMAL = 0u; public const uint TALK_STATE_ERROR = 1u; public const uint TALK_STATE_OVER_RETRY = 2u; public const sbyte SC_TRANSACTION_PENDING = 0; public const sbyte SC_TRANSACTION_PORCESSING = 1; public const sbyte SC_TRANSACTION_FINISH = 2; public const sbyte SC_TRANSACTION_INVALID = 3; public const uint SCIF_ERROR_INVALID_PACKET_SET = 255u; public const uint FILENAME_LENGTH = 32u; public const uint MAX_FILE_LIST_NUM = 240u; public const uint MAX_TRANSFER_FILE_COUNT = 128u; public const uint MAX_SOFTWARE_COUNT = 5u; public const uint ERROR_TYPE_NONE = 0u; public const uint ERROR_TYPE_POLLING = 1u; public const uint ERROR_TYPE_DIRECT = 2u; public const uint R_PATH_W_UPDATE = 17020u; public const uint R_PATH_R_START_LINE = 17021u; public const uint R_PATH_W_FILENAME = 17022u; public const sbyte SC_LOOP = 1; public const sbyte SC_DIRECT = 1; [DllImport(ReCON_DLL_NAME)] public static extern int MainProcess(); [DllImport(ReCON_DLL_NAME)] public static extern int LibraryInitial(ref DLL_USE_SETTING pUseSetting, int MakerID, string EncString); [DllImport(ReCON_DLL_NAME)] public static extern void LibraryDestroy(); [DllImport(ReCON_DLL_NAME)] public static extern void LibrarySetDebug(int level); [DllImport(ReCON_DLL_NAME)] public static extern int GetLibraryMsg(int id); [DllImport(ReCON_DLL_NAME)] public static extern int GetConnectionMsg(int TgrConn, int MsgID); [DllImport(ReCON_DLL_NAME)] public static extern void GetConnectionError(int TgrConn, ref ERROR_MSG Msg); [DllImport(ReCON_DLL_NAME)] public static extern int LocalDetectControllers(); [DllImport(ReCON_DLL_NAME)] public static extern int LocalReadControllerCount(); [DllImport(ReCON_DLL_NAME)] public static extern int LocalReadController(int Index, ref LOCAL_CONTROLLER_INFO Info); [DllImport(ReCON_DLL_NAME)] public static extern int ConnectSetPwd(int TgrConn, string Pwd); [DllImport(ReCON_DLL_NAME)] public static extern int ConnectLocalList(int TgrConn, int Index); [DllImport(ReCON_DLL_NAME)] public static extern int ConnectLocalIP(int TgrConn, string IP); [DllImport(ReCON_DLL_NAME)] public static extern int Disconnect(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern int FtpSetConnection(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern int FtpGetFileList(int Folder, string SubFolder, string HeadFilter, string TailFilter); [DllImport(ReCON_DLL_NAME)] public static extern int FtpReadFileCount(); [DllImport(ReCON_DLL_NAME)] public static extern int FtpReadFile(int Index, ref FTP_FILE file); [DllImport(ReCON_DLL_NAME)] public static extern int FtpMakeDir(int Folder, string DirName); [DllImport(ReCON_DLL_NAME)] public static extern int FtpUploadFile(int Folder, string SubFolder, string Filename, string LocalFilename); [DllImport(ReCON_DLL_NAME)] public static extern int FtpDownloadFile(int Folder, string SubFolder, string Filename, string LocalFilename); [DllImport(ReCON_DLL_NAME)] public static extern int FtpDeleteFile(int Folder, string SubFolder, string Filename); [DllImport(ReCON_DLL_NAME)] public static extern int FtpTransferFileReset(); [DllImport(ReCON_DLL_NAME)] public static extern int FtpTransferFileAdd(int Folder, string SubFolder, string Filename, string LocalFilename); [DllImport(ReCON_DLL_NAME)] public static extern int FtpUploadFiles(); [DllImport(ReCON_DLL_NAME)] public static extern int FtpDownloadFiles(); [DllImport(ReCON_DLL_NAME)] public static extern int FtpDeleteFiles2(); [DllImport(ReCON_DLL_NAME)] public static extern int FtpCheckDone(); [DllImport(ReCON_DLL_NAME)] public static extern int FtpWaitDone(int MaxWaitTime); [DllImport(ReCON_DLL_NAME)] public static extern int LocalGetFileList(string Path, string HeadFilter, string TailFilter); [DllImport(ReCON_DLL_NAME)] public static extern int LocalReadFileCount(); [DllImport(ReCON_DLL_NAME)] public static extern int LocalReadFile(int Index, ref FTP_FILE file); [DllImport(ReCON_DLL_NAME)] public static extern int LocalDeleteFile(int Index); [DllImport(ReCON_DLL_NAME)] public static extern int memI(int TgrConn, int addr); [DllImport(ReCON_DLL_NAME)] public static extern int memO(int TgrConn, int addr); [DllImport(ReCON_DLL_NAME)] public static extern int memC(int TgrConn, int addr); [DllImport(ReCON_DLL_NAME)] public static extern int memS(int TgrConn, int addr); [DllImport(ReCON_DLL_NAME)] public static extern int memA(int TgrConn, int addr); [DllImport(ReCON_DLL_NAME)] public static extern int memR(int TgrConn, int addr); [DllImport(ReCON_DLL_NAME)] public static extern int memRBit(int TgrConn, int addr, int BitIdx); [DllImport(ReCON_DLL_NAME)] public static extern int memRString(int TgrConn, int addr, int RSize, byte[] Buf); [DllImport(ReCON_DLL_NAME)] public static extern double memF(int TgrConn, int addr); [DllImport(ReCON_DLL_NAME)] public static extern int memSetO(int TgrConn, int addr, char val); [DllImport(ReCON_DLL_NAME)] public static extern int memSetC(int TgrConn, int addr, char val); [DllImport(ReCON_DLL_NAME)] public static extern int memSetS(int TgrConn, int addr, char val); [DllImport(ReCON_DLL_NAME)] public static extern int memSetA(int TgrConn, int addr, char val); [DllImport(ReCON_DLL_NAME)] public static extern int memSetR(int TgrConn, int addr, int val); [DllImport(ReCON_DLL_NAME)] public static extern int memSetRBit(int TgrConn, int addr, int BitIdx, int val); [DllImport(ReCON_DLL_NAME)] public static extern int memSetRString(int TgrConn, int addr, int RSize, string Buf); [DllImport(ReCON_DLL_NAME)] public static extern int memSetF(int TgrConn, int addr, double val); [DllImport(ReCON_DLL_NAME)] public static extern int GetTranState(int pTran); [DllImport(ReCON_DLL_NAME)] public static extern IntPtr GetDataPointer(int TranPointer); [DllImport(ReCON_DLL_NAME)] public static extern void LClearQueue(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern void LReadBegin(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern int LReadNI(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LReadNO(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LReadNC(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LReadNS(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LReadNA(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LReadNR(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LReadNF(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LReadEnd(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern void LWriteBegin(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern int LWriteNO(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LWriteNC(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LWriteNS(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LWriteNA(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LWriteNR(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LWriteNF(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int LWriteEnd(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern void DClearQueue(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern int DWaitDone(int TgrConn, int MaxWaitTime); [DllImport(ReCON_DLL_NAME)] public static extern void DReadBegin(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern int DReadNI(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int DReadNO(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int DReadNC(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int DReadNS(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int DReadNA(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int DReadNR(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int DReadNF(int TgrConn, int addr, int num); [DllImport(ReCON_DLL_NAME)] public static extern int DReadEnd(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern void DWriteBegin(int TgrConn); [DllImport(ReCON_DLL_NAME)] public static extern int DWrite1O(int TgrConn, int addr, int val); [DllImport(ReCON_DLL_NAME)] public static extern int DWrite1C(int TgrConn, int addr, int val); [DllImport(ReCON_DLL_NAME)] public static extern int DWrite1S(int TgrConn, int addr, int val); [DllImport(ReCON_DLL_NAME)] public static extern int DWrite1A(int TgrConn, int addr, int val); [DllImport(ReCON_DLL_NAME)] public static extern int DWrite1R(int TgrConn, int addr, int val); [DllImport(ReCON_DLL_NAME)] public static extern int DWrite1F(int TgrConn, int addr, double val); [DllImport(ReCON_DLL_NAME)] public static extern int DWrite1RBit(int TgrConn, int addr, int BitIdx, int BitValue); [DllImport(ReCON_DLL_NAME)] public static extern int DWriteRString(int TgrConn, int addr, int BufSize, string Buf); [DllImport(ReCON_DLL_NAME)] public static extern int DWriteNO(int TgrConn, int addr, int num, int[] data); [DllImport(ReCON_DLL_NAME)] public static extern int DWriteNC(int TgrConn, int addr, int num, int[] data); [DllImport(ReCON_DLL_NAME)] public static extern int DWriteNS(int TgrConn, int addr, int num, int[] data); [DllImport(ReCON_DLL_NAME)] public static extern int DWriteNA(int TgrConn, int addr, int num, int[] data); [DllImport(ReCON_DLL_NAME)] public static extern int DWriteNR(int TgrConn, int addr, int num, int[] data); [DllImport(ReCON_DLL_NAME)] public static extern int DWriteNF(int TgrConn, int addr, int num, double[] data); [DllImport(ReCON_DLL_NAME)] public static extern int DWriteEnd(int TgrConn); } }