public void OpenPort(string comPortName) { _serialPort = comPortName; handle = WBM5000.CommOpen(comPortName); byte error; WBM5000.WBM5000_CardMove(handle, MoveType.Front, out error); WBM5000.WBM5000_CardIN(handle, CardInType.OnlyMagnetic, 0x30, out error); }
private void PerformForwardEject() { byte error; int status; status = WBM5000.WBM5000_CardMove(handle, MoveType.Front, out error); while (status != 0 && status != -1) { status = WBM5000.WBM5000_CardMove(handle, MoveType.Front, out error); } WBM5000.WBM5000_SensorState(handle, sensorBytes, out error); }
private void RunReadThread() { byte[] cardData = new byte[100]; byte length; byte error; while (_keepAlive) { WBM5000.WBM5000_SensorState(handle, sensorBytes, out error); if (sensorBytes.Count(o => o == 0x31) >= 1 && !_hasCard) { _hasCard = true; WBM5000.WBM5000_MagCardReadData(handle, 0x30, 0x32, out length, cardData); string cardString = Encoding.ASCII.GetString(cardData, 0, length); cardString = cardString.Replace("O", "").Replace("?Y", ""); cardString = Regex.Replace(cardString, @"[^\u0020-\u007E]", string.Empty); // Console.WriteLine(); if (CardInserted != null) { _currentCard = new MagneticCard { Track2 = cardString }; CardInserted(this, new MagneticCardEventArgs(MagneticCardEvent.Insert, _currentCard)); } // WBM5000.WBM5000_SensorState(handle, sensorBytes, out error); PerformForwardEject(); } // we have no sensors active and we believe that we had a card send our card removed else if (sensorBytes.Count(o => o == 0x31) == 0 && _hasCard) { if (_hasCard) { if (CardRemoved != null) { CardRemoved(this, new MagneticCardEventArgs(MagneticCardEvent.Remove, _currentCard)); } _currentCard = null; _hasCard = false; } } Thread.Sleep(500); } }
public void ClosePort() { _keepAlive = false; _readerThread.Join(); WBM5000.CommClose(handle); }