/// <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); }
/// <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); } }