public bool Connect() { try { if (session != null) { Dispose(); } session = Tuxeip_Class.OpenSession(_ip); byte[] path = new byte[] { _rack, _slot }; if (session != null) { int res = Tuxeip_Class._RegisterSession(session); connection = Tuxeip_Class.ConnectPLCOverCNET(session, Plc_Type.LGX, path); } return(session != null && connection != null); } catch (Exception error) { if (OnError != null) { OnError(this, new IOErrorEventArgs(error.Message)); } return(false); } }
public int WriteUInt16(DeviceAddress address, ushort value) { if (IsClosed) { return(-1); } return(Tuxeip_Class._WriteLgxData(session, connection, GetAddress(address), LGX_Data_Type.LGX_INT, &value, 1)); }
public int WriteFloat(DeviceAddress address, float value) { if (IsClosed) { return(-1); } return(Tuxeip_Class._WriteLgxData(session, connection, GetAddress(address), LGX_Data_Type.LGX_REAL, &value, 1)); }
public int WriteBits(DeviceAddress address, byte bits) { if (IsClosed) { return(-1); } return(Tuxeip_Class._WriteLgxData(session, connection, GetAddress(address), LGX_Data_Type.LGX_SINT, &bits, 1)); }
public int WriteBit(DeviceAddress address, bool bit) { if (IsClosed) { return(-1); } return(Tuxeip_Class._WriteLgxData(session, connection, GetAddress(address), LGX_Data_Type.LGX_BOOL, &bit, 1)); }
public unsafe int WriteBytes(DeviceAddress address, byte[] bit) { if (IsClosed) { return(-1); fixed(void *b = bit) { return(Tuxeip_Class._WriteLgxData(session, connection, GetAddress(address), LGX_Data_Type.LGX_BITARRAY, b, 1)); } }
public ItemData <ushort> ReadUInt16(DeviceAddress address) { if (IsClosed) { return(new ItemData <ushort>(0, 0, QUALITIES.QUALITY_NOT_CONNECTED)); } else { LGX_Read *data = Tuxeip_Class._ReadLgxData(session, connection, GetAddress(address), 1); return(new ItemData <ushort>((ushort)Tuxeip_Class._GetLGXValueAsInteger(data, 0), 0, QUALITIES.QUALITY_GOOD)); } }
public ItemData <bool> ReadBit(DeviceAddress address) { if (IsClosed) { return(new ItemData <bool>(false, 0, QUALITIES.QUALITY_NOT_CONNECTED)); } else { LGX_Read *data = Tuxeip_Class._ReadLgxData(session, connection, GetAddress(address), 1); return(new ItemData <bool>(Tuxeip_Class._GetLGXValueAsInteger(data, 0) > 0, 0, QUALITIES.QUALITY_GOOD)); } }
public void Dispose() { if (connection != null) { Tuxeip_Class._Forward_Close(connection); } if (session != null) { Tuxeip_Class._UnRegisterSession(session); } Tuxeip_Class.CloseSession(session); Marshal.FreeCoTaskMem((IntPtr)connection); Marshal.FreeCoTaskMem((IntPtr)session); connection = null; session = null; }
public float[] ReadFloatArray(DeviceAddress address, ushort size) { if (IsClosed) { return(null); } else { float[] buffer = new float[size]; address.VarType = DataType.FLOAT; var addr = GetAddress(address); LGX_Read *data = Tuxeip_Class._ReadLgxData(session, connection, addr, size); if (data != null && data->Varcount > 0) { for (int i = 0; i < data->Varcount; i++) { buffer[i] = Tuxeip_Class._GetLGXValueAsFloat(data, i); } data = null; return(buffer); } connection = null; return(null); } }