/// <summary> /// Set the ReadtimeOut to the Device /// </summary> /// <param name="readTimeout">timeout in ms</param> /// <returns>true on success</returns> public bool ReadTimeout(int readTimeout) { var result = IowKit.Timeout(_device.Handler, readTimeout); if (result) { return(true); } _device.AddDeviceError("Timeout konnte nicht gesetzt werden"); return(false); }
private void ReadDeviceProductId() { if (ProductId == null) { ProductId = IowKit.GetProductId(Handler); if (ProductId == null) { AddDeviceError("Fehler beim Lesen der Product die des Devices"); } } SetDeviceReportSize(); }
/// <summary> /// Port IO write /// </summary> /// <param name="ports"></param> /// <returns></returns> public bool Write(Dictionary <int, Port> ports) { if (run) { int portValue = 1; var data = new byte[_device.IoReportsSize]; int counter = 2; while (run) { data[1] = (byte)portValue; data[2] = (byte)portValue; var size = IowKit.Write(_device.Handler, 0, data, _device.IoReportsSize); System.Threading.Thread.Sleep(_timing); if (portValue == 1) { portValue = 2; } else { portValue = (int)Math.Pow(2, (double)counter); counter++; if (counter > 8) { counter = 2; portValue = 1; } } byte[] dataCopy = new byte[3]; dataCopy[0] = data[1]; dataCopy[1] = data[2]; _device.SetDataStateToPort(dataCopy); } return(true); } else { var data = new byte[_device.IoReportsSize]; data[0] = 0x00; foreach (var kvp in ports) { var p = kvp.Value; data[kvp.Key + Port.PortOffset] = p.GetBitStateAsByte(); } var size = IowKit.Write(_device.Handler, 0, data, _device.IoReportsSize); return(size != null && size == _device.IoReportsSize); } }
/// <summary> /// Write the Current out state of the ports to the Device /// </summary> /// <returns>true if all Bits write to the device</returns> public bool WritePortStateToDevice() { var data = new byte[IoReportsSize]; data[0] = 0x00; foreach (var kvp in Ports) { var p = kvp.Value; data[kvp.Key + Port.PortOffset] = p.GetBitStateAsByte(); } var size = IowKit.Write(Handler, 0, data, IoReportsSize); return(size != null && size == IoReportsSize); }
// writes Data from Ports to the LCD private bool WriteDataToLcd() { var data = new byte[_device.IoReportsSize]; data[0] = 0x00; foreach (var kvp in _device.Ports) { var p = kvp.Value; data[kvp.Key + Port.PortOffset] = p.GetBitStateAsByte(); } var size = IowKit.Write(_device.Handler, 0, data, _device.IoReportsSize); return(size != null && size == _device.IoReportsSize); }
/// <summary> /// Starten des Modus und setzt den IOW in den I2C Special Mode /// </summary> /// <returns></returns> public bool PortsInitialisation() { byte[] report = new byte[IowkitSpecialReportSize]; // I2C Mode report[0] = 0X01; // enable report[1] = 0X01; // flags report[2] = 0X00; // timeout report[3] = 0X00; IowKit.Timeout(_device.Handler, 1000); return(IowKit.Write(_device.Handler, IowPipeSpecialMode, report, IowkitSpecialReportSize) == IowkitSpecialReportSize); }
/// <summary> /// Initalisation of the Ports device. /// </summary> /// <returns></returns> public bool PortsInitialisation() { var write = new byte[_device.IoReportsSize]; write[0] = 0x00; write[1] = 0xff; write[2] = 0xff; var writebyts = IowKit.Write(_device.Handler, Defines.IowPipeIoPins, write, _device.IoReportsSize); if (writebyts == _device.IoReportsSize) { return(true); } writebyts = IowKit.Write(_device.Handler, Defines.IowPipeIoPins, write, _device.IoReportsSize); if (writebyts == _device.IoReportsSize) { return(true); } _device.AddDeviceError("Beim Device: " + _device.DeviceNumber + " konnten die I/O Ports nicht Initalisiert werden."); return(false); }
private byte[] ReadDeviceImmediate() { if (_writeLoopCounter >= 3) { _device.AddDeviceError("Der Versuch zu schreiben ist nach dem dritten versucht abgebrochen worden"); return(new byte[_device.IoReportsSize]); } _writeLoopCounter++; var data = new byte[_device.IoReportsSize]; var ok = IowKit.ReadImmediate(_device.Handler, data); if (!ok) { data = ReadDeviceImmediate(); } _writeLoopCounter = 0; if (data != null) { return(data); } _device.AddDeviceError("Device ist offenbar nicht mehr angeschlossen"); return(new byte[_device.IoReportsSize]); }
private bool WriteSingelRegister(byte adress, byte register, byte value) { byte[] report = new byte[IowkitSpecialReportSize]; // I2C Write report[0] = 0X02; // 3 Byte Start und Stop report[1] = 0XC3; report[2] = adress; report[3] = register; report[4] = value; IowKit.Write(_device.Handler, IowPipeSpecialMode, report, IowkitSpecialReportSize); IowKit.Read(_device.Handler, IowPipeSpecialMode, report, IowkitSpecialReportSize); // IowKit.ReadImmediate(_device.Handler, report); if (report[1] == 128) { return(false); } return(true); }
private void ReadSoftwareVersion() { SoftwareVersion = IowKit.GetProductSoftwareVersion(Handler); }
private void ReadDeviceSerial() { Serial = IowKit.GetProductSerial(Handler); }
/// <summary> /// Close this Device. Triggers the Devices close Event /// </summary> public void Close() { IowKit.CloseDevice(Handler); DeviceCloseEvent(); }