public async Task <byte> Dispense(object param) { var billsInfo = CommonFunctions.ObjectToByteArray(param); recievedData.Clear(); dataBuf.Clear(); dataBuf.Add(0xFC); dataBuf.Add(CommonFunctions.StringToByteArray((billsInfo.Length + 7).ToString())[0]); dataBuf.Add(0xF0); dataBuf.Add(0x20); dataBuf.Add(0x4A); foreach (var val in billsInfo) { dataBuf.Add(val); } byte[] crcBuffer = Crc16CcittKermit.ComputeChecksumBytes(dataBuf.ToArray()); dataBuf.Add(crcBuffer[0]); dataBuf.Add(crcBuffer[1]); ResponseLength = 5; //Response lenght Port.Write(dataBuf.ToArray(), 0, dataBuf.Count); await Task.Delay(DelayTymeout); byte[] reciveBuf = recievedData.ToArray(); if (CheckCrc(reciveBuf)) { return(reciveBuf[2]); } else { return(0); } }
private async Task <byte> SetSequrity(object param) { recievedData.Clear(); dataBuf.Clear(); dataBuf.Add(0xFC); dataBuf.Add(0x07); dataBuf.Add(0xC1); dataBuf.Add(0x00); dataBuf.Add(0x00); byte[] crcBuffer = Crc16CcittKermit.ComputeChecksumBytes(dataBuf.ToArray()); dataBuf.Add(crcBuffer[0]); dataBuf.Add(crcBuffer[1]); ResponseLength = 5; //Response lenght Port.Write(dataBuf.ToArray(), 0, dataBuf.Count); await Task.Delay(DelayTymeout); byte[] reciveBuf = recievedData.ToArray(); if (CheckCrc(reciveBuf)) { return(reciveBuf[2]); } else { return(0); } }
private async Task <byte> OptionalFunction(object param) { var enable = Convert.ToBoolean(param); recievedData.Clear(); dataBuf.Clear(); dataBuf.Add(0xFC); dataBuf.Add(0x07); dataBuf.Add(0xC5); dataBuf.Add(0x03); if (enable) { dataBuf.Add(0x00); } else { dataBuf.Add(0x01); } byte[] crcBuffer = Crc16CcittKermit.ComputeChecksumBytes(dataBuf.ToArray()); dataBuf.Add(crcBuffer[0]); dataBuf.Add(crcBuffer[1]); ResponseLength = 7; //Response lenght Port.Write(dataBuf.ToArray(), 0, dataBuf.Count); await Task.Delay(DelayTymeout); byte[] reciveBuf = recievedData.ToArray(); if (CheckCrc(reciveBuf)) { return(reciveBuf[2]); } else { return(0); } }
private async Task <byte> Currrency(object param) { recievedData.Clear(); dataBuf.Clear(); dataBuf.Add(0xFC); dataBuf.Add(0x05); dataBuf.Add(0x8A); byte[] crcBuffer = Crc16CcittKermit.ComputeChecksumBytes(dataBuf.ToArray()); dataBuf.Add(crcBuffer[0]); dataBuf.Add(crcBuffer[1]); ResponseLength = 50; //Response lenght Port.Write(dataBuf.ToArray(), 0, dataBuf.Count); await Task.Delay(DelayTymeout); byte[] reciveBuf = recievedData.ToArray(); if (CheckCrc(reciveBuf)) { denomination.Clear(); int i = 1; var tmpBuf = reciveBuf.Skip(3).ToArray(); while (3 + (4 * i) < reciveBuf.Length) { denomination.Add(tmpBuf[0], new Tuple <byte, byte>(tmpBuf[2], tmpBuf[3])); tmpBuf = reciveBuf.Skip(3 + (4 * i)).ToArray(); i++; } return(reciveBuf[2]); } else { return(0); } }
private async Task <byte> PayOutAsync(object param) { recievedData.Clear(); dataBuf.Clear(); dataBuf.Add(0xFC); dataBuf.Add(0x08); dataBuf.Add(0xF0); dataBuf.Add(0x20); dataBuf.Add(0x4A); try { dataBuf.Add(Convert.ToByte(param)); } catch (Exception) { dataBuf.Add(0X00); } byte[] crcBuffer = Crc16CcittKermit.ComputeChecksumBytes(dataBuf.ToArray()); dataBuf.Add(crcBuffer[0]); dataBuf.Add(crcBuffer[1]); ResponseLength = 5; //Response lenght? Port.Write(dataBuf.ToArray(), 0, dataBuf.Count); await Task.Delay(DelayTymeout); byte[] reciveBuf = recievedData.ToArray(); if (CheckCrc(reciveBuf)) { return(reciveBuf[2]); } else { return(0); } }
protected bool CheckCrc(byte[] data) { if (data.Length > 2) { byte[] buf = new byte[data.Length - 2]; Array.Copy(data, 0, buf, 0, data.Length - 2); byte[] crcBuffer = Crc16CcittKermit.ComputeChecksumBytes(buf); return(crcBuffer[0] == data[data.Length - 2] && crcBuffer[1] == data[data.Length - 1] ? true : false); } else { return(false); } }