/// <summary> /// Read from the IO-Warrior device. /// </summary> /// <param name="id">The device number (indexed from 1).</param> /// <param name="channel">The channel to read (indexed from 0).</param> /// <param name="blocking">"True" (return after the state changes) or "False" (return with current state).</param> /// <param name="count">The number of bytes to read (if zero, then the ReportSize is used if channel is 0 or SpecialReportSize if channel is 1). /// See GetReportSize and GetSpecialReportSize.</param> /// <returns>An array of read bytes [0 to 255].</returns> public static Primitive Read(Primitive id, Primitive channel, Primitive blocking, Primitive count) { try { IOWDevice device = GetDevice((uint)id); if (null == device) { return(""); } uint length = (uint)count; if (length == 0) { length = (channel == 0) ? device.reportSize : device.specialReportSize; } byte[] buffer = new byte[length]; length = device.Read((uint)channel, buffer, blocking, length); string result = ""; for (int i = 0; i < length; i++) { result += (i + 1).ToString() + "=" + (int)buffer[i] + ";"; } return(Utilities.CreateArrayMap(result)); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return(""); }
private static string AddDevice(uint id) { IOWDevice device = new IOWDevice(id); IOWDevices.Add(device); return(device.name); }
private static void RemoveDevice(uint id) { IOWDevice device = GetDevice(id); if (null == device) { return; } Functions.IowKitCloseDevice(device.handle); IOWDevices.Remove(device); }
/// <summary> /// Get the device firmware version. /// </summary> /// <param name="id">The device number (indexed from 1).</param> /// <returns>The device firmware version or 0.</returns> public static Primitive GetVersion(Primitive id) { try { IOWDevice device = GetDevice((uint)id); if (null == device) { return(0); } return((int)device.version); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return(0); }
/// <summary> /// Get the device serial number. /// </summary> /// <param name="id">The device number (indexed from 1).</param> /// <returns>The device serial number or "".</returns> public static Primitive GetSerialNumber(Primitive id) { try { IOWDevice device = GetDevice((uint)id); if (null == device) { return(""); } return(device.sn.ToString()); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return(""); }
/// <summary> /// Get the device PID. /// </summary> /// <param name="id">The device number (indexed from 1).</param> /// <returns>The device PID (hex) or 0.</returns> public static Primitive GetPID(Primitive id) { try { IOWDevice device = GetDevice((uint)id); if (null == device) { return(0); } return(Convert.ToString(device.pid, 16)); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return(0); }
/// <summary> /// Get the device name. /// </summary> /// <param name="id">The device number (indexed from 1).</param> /// <returns>The device name or "".</returns> public static Primitive GetName(Primitive id) { try { IOWDevice device = GetDevice((uint)id); if (null == device) { return(""); } return(device.name); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return(""); }
/// <summary> /// Write to the IO-Warrior device. /// </summary> /// <param name="id">The device number (indexed from 1).</param> /// <param name="channel">The channel to write to (indexed from 0).</param> /// <param name="data">An array of bytes to send [0 to 255]. /// The array size should be ReportSize for channel 0 and SpecialReportSize for channel 1. /// See GetReportSize and GetSpecialReportSize.</param> /// <returns>The number of bytes successfully written.</returns> public static Primitive Write(Primitive id, Primitive channel, Primitive data) { try { IOWDevice device = GetDevice((uint)id); if (null == device) { return(0); } int length = SBArray.GetItemCount(data); byte[] buffer = new byte[length]; for (int i = 0; i < length; i++) { buffer[i] = (byte)data[i + 1]; } return((int)device.Write((uint)channel, buffer, (uint)length)); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return(0); }
private static string AddDevice(uint id) { IOWDevice device = new IOWDevice(id); IOWDevices.Add(device); return device.name; }
/// <summary> /// Write text to the LCD (untested). /// </summary> /// <param name="id">The device number (indexed from 1).</param> /// <param name="text">The text to write.</param> public static void LCDWrite(Primitive id, Primitive text) { try { IOWDevice device = GetDevice((uint)id); if (null == device) { return; } int length = GetSpecialReportSize(id); byte[] buffer = new byte[length]; for (int i = 0; i < length; i++) { buffer[i] = 0; } buffer[0] = 4; buffer[1] = 1; device.Write(1, buffer, (uint)length); buffer[0] = 5; buffer[1] = 3; buffer[2] = 40; buffer[3] = 1; buffer[4] = 15; device.Write(1, buffer, (uint)length); buffer[0] = 5; buffer[1] = 1; buffer[2] = 15; device.Write(1, buffer, (uint)length); buffer[0] = 5; buffer[1] = 1; buffer[2] = 6; device.Write(1, buffer, (uint)length); string txt = (string)text; int nChars = txt.Length; buffer[0] = 5; int nCurr = 0; int nNow; while (nCurr < nChars) { if (nCurr + 6 > nChars) { nNow = nChars - nCurr; } else { nNow = 6; } buffer[1] = (byte)(128 + nNow); for (int i = 0; i < nNow; i++) { buffer[2 + i] = (byte)(txt.ToCharArray()[i]); } device.Write(1, buffer, (uint)length); nCurr += 6; } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } }