internal override uint WriteBlock(ushort[] buffer, ushort receiveTransmitCode) { try { if (this.state == DeviceState.Open) { W32_TMK.tmkdefevent(this.hTmkEvent, true); this.LastError = (uint)W32_TMK.bcdefbase(Convert.ToUInt16((this.options as IMKOPortOptions).Address)); IntPtr pcBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); W32_TMK.bcputblk(0, pcBuffer, (ushort)buffer.Length); this.LastError = (uint)W32_TMK.bcstart(Convert.ToUInt16((this.options as IMKOPortOptions).Address), receiveTransmitCode); if (this.LastError != 0) { return(this.LastError); } return(0); } return(1); } catch (Exception exception) { throw CreateThrowUpException(exception); } }
public override uint Select() { try { uint result = 0; this.LastError = (uint)W32_TMK.tmkselect_usb((this.options as IMKOPortOptions).ID); return(result); } catch (Exception exception) { throw CreateThrowUpException(exception); } }
internal override uint DefineBus(ushort bus) { try { if (this.state == DeviceState.Open) { this.LastError = (uint)W32_TMK.bcdefbus(bus); } return(0); } catch (Exception exception) { throw CreateThrowUpException(exception); } }
internal override ushort[] ReadBlock() { try { ushort[] outBuffer = new ushort[0x40]; if (this.state == DeviceState.Open) { W32_TMK.bcgetblk(0, Marshal.UnsafeAddrOfPinnedArrayElement(outBuffer, 0), (ushort)outBuffer.Length); } return(outBuffer); } catch (Exception exception) { throw CreateThrowUpException(exception); } }
internal override uint Connect() { try { if (state != DeviceState.Open) { this.hTmkEvent = W32_TMK.CreateEvent(IntPtr.Zero, true, false, string.Format("Event_MKO_TEST{0}", (this.options as IMKOPortOptions).ID)); } this.LastError = W32_TMK.GetLastError(); if (this.LastError == 0xb7) { //"_stat_ МКО ОУ: открыто подключение устройства к внешнему процессу! (тест МКО)"; return(1); } else { W32_TMK.CloseHandle(this.hTmkEvent); this.hTmkEvent = W32_TMK.CreateEvent(IntPtr.Zero, true, false, string.Format("Event_MKO_BC_{0}", (this.options as IMKOPortOptions).ID)); this.LastError = (uint)W32_TMK.tmkconfig((this.options as IMKOPortOptions).ID); //"_stat_ МКО КК: сконфигурировано и подключено устройство с ID = " + this.Dev_ID.ToString())); Select(); W32_TMK.tmkdefevent(this.hTmkEvent, true); this.LastError = (uint)W32_TMK.bcreset(); this.state = DeviceState.Open; this.Bus = this.Bus; if (this.LastError != 0) { return(1); } return(0); } } catch (Exception exception) { throw CreateThrowUpException(exception); } }
internal override uint Disconnect() { try { if (state == DeviceState.Open) { W32_TMK.tmkdefevent(IntPtr.Zero, true); this.LastError = (uint)W32_TMK.tmkdone((this.options as IMKOPortOptions).ID); W32_TMK.CloseHandle(this.hTmkEvent); this.state = DeviceState.Close; if (this.LastError != 0) { return(this.LastError); } return(0); } return(1); } catch (Exception exception) { throw CreateThrowUpException(exception); } }