1674 lines
57 KiB
C#
1674 lines
57 KiB
C#
namespace DE70_CMDv2
|
|
{
|
|
using Serilog;
|
|
using SafeBagDE70;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.IO.Ports;
|
|
using System.Text;
|
|
using System.Linq;
|
|
|
|
public class CCmdRsp
|
|
{
|
|
public static CDenom[] mDenomTable = new CDenom[128];
|
|
public static int mDenominationCount;
|
|
public static string mSelectedCurrency;
|
|
public static int miSelectedCurrency;
|
|
private SerialPort serialPort = null;
|
|
private int m_all_sendsize;
|
|
private int m_all_recvsize;
|
|
private byte[] recv_buf = new byte[8192];
|
|
private byte[] m_send_buf = new byte[8192];
|
|
public RecvData recv_dat = new RecvData();
|
|
private SendDataStruct send_dat = new SendDataStruct();
|
|
private SendStatus cmd_result;
|
|
private LockParam lock_param = new LockParam();
|
|
private byte[] recv_serialset = new byte[256];
|
|
private Com232C m_ccom = null;
|
|
|
|
public CCmdRsp(SerialPort _serialPort)
|
|
{
|
|
serialPort = _serialPort;
|
|
m_ccom = new Com232C(_serialPort);
|
|
m_all_sendsize = 0;
|
|
m_all_recvsize = 0;
|
|
Array.Clear(recv_buf, 0, recv_buf.Length);
|
|
Array.Clear(m_send_buf, 0, m_send_buf.Length);
|
|
Array.Clear(recv_dat.dat, 0, recv_dat.dat.Length);
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
cmd_result = SendStatus.SEND_NON;
|
|
lock_param.Register = 1;
|
|
lock_param.ID = 1;
|
|
lock_param.TransactionNo = 1;
|
|
lock_param.mode = Mode.MODE_DEPOSIT;
|
|
lock_param.Currency = Currency.CURRENCY01; // first currency
|
|
lock_param.Gengai.amount = 0;
|
|
lock_param.Batch.Regi_num = 1;
|
|
Array.Clear(lock_param.Batch.batch_num, 0, lock_param.Batch.batch_num.Length);
|
|
Array.Clear(lock_param.Cassette.CassetteID, 0, lock_param.Cassette.CassetteID.Length);
|
|
Array.Clear(recv_serialset, 0, recv_serialset.Length);
|
|
}
|
|
|
|
public byte SendData()
|
|
{
|
|
byte ret = m_ccom.send_dat(m_send_buf, m_all_sendsize);
|
|
return ret;
|
|
}
|
|
|
|
public int SendSerialSense()
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_GDB_SENSE;
|
|
send_dat.leng = 1;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return (int)cmd_result;
|
|
|
|
return SendRecvData();
|
|
//return Constants.E_OK;
|
|
}
|
|
public static string ByteArrayToHexString(byte[] byteArray, int startIndex, int length, bool separateWithSpace = false)
|
|
{
|
|
if (startIndex < 0 || length < 0 || startIndex + length > byteArray.Length)
|
|
{
|
|
return "The specified range is out of bounds.";
|
|
}
|
|
|
|
var hexStringBuilder = new StringBuilder();
|
|
for (int i = startIndex; i < startIndex + length; i++)
|
|
{
|
|
hexStringBuilder.Append(byteArray[i].ToString("X2"));
|
|
if (separateWithSpace && i < startIndex + length - 1)
|
|
{
|
|
hexStringBuilder.Append(" ");
|
|
}
|
|
}
|
|
|
|
return hexStringBuilder.ToString();
|
|
}
|
|
|
|
|
|
private int SendRecvData()
|
|
{
|
|
SendDataSet();
|
|
send_dat.ret = SendData();
|
|
Log.Information("[CMD_SEND] " + GetSendDat(false));
|
|
|
|
if (send_dat.ret != Constants.E_OK)
|
|
{
|
|
cmd_result = SendStatus.SEND_ERR;
|
|
return Constants.E_NG_SEND;
|
|
}
|
|
|
|
recv_dat.ret = WaitRsp();
|
|
Log.Information("[CMD_RCV] " +GetRecvDat());
|
|
|
|
if (recv_dat.ret != Constants.E_OK)
|
|
{
|
|
cmd_result = SendStatus.RECV_ERR;
|
|
return Constants.E_NG_RECV;
|
|
}
|
|
cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return (int)cmd_result;
|
|
return Constants.E_OK;
|
|
}
|
|
|
|
public int SendSense()
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_SENSE;
|
|
send_dat.leng = 1;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
|
|
public int SendDeSense()
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_DE_SENSE;
|
|
send_dat.leng = 1;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
|
|
public int SendDeviceSettingDataReq()
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = 0x62;
|
|
send_dat.leng = 1;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
|
|
public int SendDenomiRead2()
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_GDB_BVDATA_READ;
|
|
send_dat.leng = 1;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
|
|
public int SendSerialSet(byte[] dat)
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_GDB_SETDATA;
|
|
send_dat.leng = 1 + 20;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
Array.Copy(dat, 0, send_dat.dat, 0, 20);
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
|
|
public int SendSetRJSerial()
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_GDB_SETRJSERIAL;
|
|
send_dat.leng = 24;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
|
|
send_dat.dat[0] = 0x01;
|
|
send_dat.dat[1] = (byte)'I';
|
|
send_dat.dat[2] = (byte)'N';
|
|
send_dat.dat[3] = (byte)'R';
|
|
send_dat.dat[4] = 0x00;
|
|
send_dat.dat[5] = 5;
|
|
send_dat.dat[6] = 8;
|
|
send_dat.dat[7] = (byte)'4';
|
|
send_dat.dat[8] = (byte)'K';
|
|
send_dat.dat[9] = (byte)'T';
|
|
send_dat.dat[10] = (byte)'4';
|
|
send_dat.dat[11] = (byte)'7';
|
|
send_dat.dat[12] = (byte)'6';
|
|
send_dat.dat[13] = (byte)'6';
|
|
send_dat.dat[14] = (byte)'1';
|
|
send_dat.dat[15] = (byte)'#';
|
|
send_dat.dat[16] = (byte)'#';
|
|
send_dat.dat[17] = (byte)'#';
|
|
send_dat.dat[18] = (byte)'#';
|
|
send_dat.dat[19] = (byte)'#';
|
|
send_dat.dat[20] = (byte)'#';
|
|
send_dat.dat[21] = (byte)'#';
|
|
send_dat.dat[22] = (byte)'#';
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
|
|
public int SendSerialSetRead()
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_GDB_SETDATAREAD;
|
|
send_dat.leng = 1;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
SendRecvData();
|
|
Array.Copy(recv_dat.dat, 13, recv_serialset, 0, recv_serialset.Length);
|
|
|
|
return Constants.E_OK;
|
|
}
|
|
|
|
public int SendGetSerial(ushort dat)
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_GDB_GETSERIAL;
|
|
send_dat.leng = 1 + 2;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
send_dat.dat[0] = (byte)((dat & 0xFF00) >> 8);
|
|
send_dat.dat[1] = (byte)(dat & 0x00FF);
|
|
return SendRecvData();
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
}
|
|
|
|
public int SendFreeDat()
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = 0x00;
|
|
send_dat.leng = 1 + 1;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
|
|
if (!File.Exists("send.bin"))
|
|
{
|
|
cmd_result = SendStatus.SEND_DAT_ERR;
|
|
return Constants.E_NG_FILE;
|
|
}
|
|
|
|
byte[] fileData = File.ReadAllBytes("send.bin");
|
|
send_dat.cmd = fileData[0];
|
|
Array.Copy(fileData, 1, send_dat.dat, 0, fileData.Length - 1);
|
|
send_dat.leng = fileData.Length;
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
|
|
public int SendDataSet()
|
|
{
|
|
int sendsize = 0;
|
|
byte bcc = 0;
|
|
byte[] len_dat = new byte[3];
|
|
Array.Clear(m_send_buf, 0, m_send_buf.Length);
|
|
|
|
m_send_buf[sendsize++] = Constants.D_DLE;
|
|
m_send_buf[sendsize++] = Constants.D_STX;
|
|
SetLen(len_dat, send_dat.leng);
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
if (len_dat[i] == Constants.D_DLE)
|
|
{
|
|
m_send_buf[sendsize++] = Constants.D_DLE;
|
|
}
|
|
m_send_buf[sendsize++] = len_dat[i];
|
|
bcc ^= len_dat[i];
|
|
}
|
|
|
|
m_send_buf[sendsize++] = send_dat.cmd;
|
|
bcc ^= send_dat.cmd;
|
|
for (int i = 0; i < send_dat.leng - 1; i++)
|
|
{
|
|
if (send_dat.dat[i] == Constants.D_DLE)
|
|
{
|
|
m_send_buf[sendsize++] = Constants.D_DLE;
|
|
}
|
|
m_send_buf[sendsize++] = send_dat.dat[i];
|
|
bcc ^= send_dat.dat[i];
|
|
}
|
|
m_send_buf[sendsize++] = Constants.D_DLE;
|
|
m_send_buf[sendsize++] = Constants.D_ETX;
|
|
bcc ^= Constants.D_ETX;
|
|
m_send_buf[sendsize++] = bcc;
|
|
send_dat.bcc = bcc;
|
|
|
|
m_all_sendsize = sendsize;
|
|
|
|
return Constants.E_OK;
|
|
}
|
|
|
|
public int SetLen(byte[] dat, int size)
|
|
{
|
|
if (size <= 999)
|
|
{
|
|
dat[0] = (byte)((size / 100) | 0x30);
|
|
dat[1] = (byte)(((size % 100) / 10) | 0x30);
|
|
dat[2] = (byte)((size % 100) % 10 | 0x30);
|
|
}
|
|
else
|
|
{
|
|
dat[0] = (byte)((size / 0x010000) | 0x70);
|
|
dat[1] = (byte)((size % 0x010000) / 0x100);
|
|
dat[2] = (byte)((size % 0x010000) % 0x100);
|
|
}
|
|
return Constants.E_OK;
|
|
}
|
|
|
|
public byte WaitRsp()
|
|
{
|
|
int pos_r = 0;
|
|
int size;
|
|
int i;
|
|
bool dle_flg = false;
|
|
Array.Clear(recv_buf, 0, recv_buf.Length);
|
|
recv_dat.ret = Constants.E_OK;
|
|
recv_dat.cmd = 0x00;
|
|
recv_dat.leng = 0;
|
|
recv_dat.bcc = 0x00;
|
|
Array.Clear(recv_dat.dat, 0, recv_dat.dat.Length);
|
|
|
|
size = m_ccom.rcv_dat(recv_buf, pos_r, 1);
|
|
if (size != 1)
|
|
{
|
|
return Constants.E_NG;
|
|
}
|
|
if (recv_buf[pos_r] == Constants.D_NAK)
|
|
{
|
|
return Constants.E_NG;
|
|
}
|
|
if (recv_buf[pos_r] != Constants.D_DLE)
|
|
{
|
|
return Constants.E_NG;
|
|
}
|
|
pos_r++;
|
|
|
|
size = m_ccom.rcv_dat(recv_buf, pos_r, 1);
|
|
if (recv_buf[pos_r] != Constants.D_STX || size != 1)
|
|
{
|
|
return Constants.E_NG;
|
|
}
|
|
pos_r++;
|
|
|
|
if (WaitRspLen(ref recv_buf, pos_r, ref recv_dat.leng, out size) != Constants.E_OK)
|
|
{
|
|
return Constants.E_NG;
|
|
}
|
|
pos_r += size;
|
|
|
|
if (m_ccom.rcv_dat(recv_buf, pos_r, 1) != 1)
|
|
{
|
|
return Constants.E_NG;
|
|
}
|
|
recv_dat.cmd = recv_buf[pos_r];
|
|
pos_r++;
|
|
|
|
if (recv_dat.cmd == (byte)Command.CMD_GDB_GETSERIAL)
|
|
{
|
|
//Tạo buffer để nhận dữ liệu
|
|
//size = m_ccom.rcv_dat(recv_buf, pos_r, recv_dat.leng - 1);
|
|
int _size = 0;
|
|
int _pos_r = pos_r;
|
|
while (_size < recv_dat.leng - 1)
|
|
{
|
|
var _tsize = m_ccom.rcv_dat(recv_buf, _pos_r, recv_dat.leng - 1 - _size);
|
|
_size += _tsize;
|
|
_pos_r += _tsize;
|
|
}
|
|
size = _size;
|
|
//pos_r = _pos_r;
|
|
if (size != recv_dat.leng - 1)
|
|
{
|
|
return Constants.E_NG;
|
|
}
|
|
Array.Copy(recv_buf, pos_r, recv_dat.dat, 0, recv_dat.leng - 1);
|
|
pos_r += size;
|
|
}
|
|
else
|
|
{
|
|
i = 0;
|
|
while (i < recv_dat.leng - 1)
|
|
{
|
|
if (m_ccom.rcv_dat(recv_buf, pos_r, 1) != 1)
|
|
{
|
|
return Constants.E_NG;
|
|
}
|
|
if (!dle_flg && recv_buf[pos_r] == Constants.D_DLE)
|
|
{
|
|
pos_r++;
|
|
dle_flg = true;
|
|
continue;
|
|
}
|
|
recv_dat.dat[i] = recv_buf[pos_r];
|
|
pos_r++;
|
|
i++;
|
|
dle_flg = false;
|
|
}
|
|
size = m_ccom.rcv_dat(recv_buf, pos_r, 3);
|
|
recv_dat.bcc = recv_buf[pos_r + 2];
|
|
pos_r += size;
|
|
}
|
|
m_all_recvsize = pos_r;
|
|
return Constants.E_OK;
|
|
}
|
|
|
|
public int WaitRspLen(ref byte[] dat, int pos, ref int leng, out int size)
|
|
{
|
|
int initialPos = pos;
|
|
|
|
if (m_ccom.rcv_dat(dat, pos, 1) != 1)
|
|
{
|
|
size = 0;
|
|
return Constants.E_NG;
|
|
}
|
|
if ((dat[pos] & 0xF0) == 0x70)
|
|
{
|
|
leng = (dat[pos] & 0x0F) * 0x10000;
|
|
pos++;
|
|
if (m_ccom.rcv_dat(dat, pos, 1) != 1)
|
|
{
|
|
size = 0;
|
|
return Constants.E_NG;
|
|
}
|
|
if (dat[pos] == Constants.D_DLE)
|
|
{
|
|
if (m_ccom.rcv_dat(dat, pos + 1, 1) != 1)
|
|
{
|
|
size = 0;
|
|
return Constants.E_NG;
|
|
}
|
|
pos++;
|
|
}
|
|
leng += dat[pos] * 0x100;
|
|
pos++;
|
|
|
|
if (m_ccom.rcv_dat(dat, pos, 1) != 1)
|
|
{
|
|
size = 0;
|
|
return Constants.E_NG;
|
|
}
|
|
if (dat[pos] == Constants.D_DLE)
|
|
{
|
|
if (m_ccom.rcv_dat(dat, pos + 1, 1) != 1)
|
|
{
|
|
size = 0;
|
|
return Constants.E_NG;
|
|
}
|
|
pos++;
|
|
}
|
|
leng += dat[pos];
|
|
pos++;
|
|
}
|
|
else
|
|
{
|
|
if (m_ccom.rcv_dat(dat, pos + 1, 2) != 2)
|
|
{
|
|
size = 0;
|
|
return Constants.E_NG;
|
|
}
|
|
if (((dat[pos] & 0x30) != 0x30) || ((dat[pos + 1] & 0x30) != 0x30) || ((dat[pos + 2] & 0x30) != 0x30))
|
|
{
|
|
size = 0;
|
|
return Constants.E_NG;
|
|
}
|
|
leng = (dat[pos] & 0x0F) * 100 + (dat[pos + 1] & 0x0F) * 10 + (dat[pos + 2] & 0x0F);
|
|
pos += 3;
|
|
}
|
|
|
|
size = pos - initialPos;
|
|
return Constants.E_OK;
|
|
}
|
|
|
|
public string GetSendDat(bool oneLine)
|
|
{
|
|
StringBuilder str = new StringBuilder();
|
|
|
|
string cmd = GetCommandName(send_dat.cmd);
|
|
|
|
var dat=string.Format("SEND {0} L:{1} ", cmd, send_dat.leng);
|
|
str.Append(dat);
|
|
|
|
if (!oneLine)
|
|
{
|
|
str.Append("DATA:");
|
|
for (int i = 0; i < send_dat.leng - 1; i++)
|
|
{
|
|
dat = string.Format("{0:X2} ", send_dat.dat[i]);
|
|
}
|
|
str.Append(dat);
|
|
str.Append(" Raw: ");
|
|
|
|
if (cmd_result == SendStatus.SEND_RECV_OK || cmd_result == SendStatus.RECV_ERR)
|
|
{
|
|
for (int i = 0; i < m_all_sendsize; i++)
|
|
{
|
|
dat = string.Format("{0:X2} ", m_send_buf[i]);
|
|
}
|
|
str.Append(dat);
|
|
}
|
|
else if (cmd_result == SendStatus.SEND_DAT_ERR || cmd_result == SendStatus.SEND_ERR)
|
|
{
|
|
str.Append("send err");
|
|
}
|
|
//str.Append("\r\n");
|
|
}
|
|
else
|
|
{
|
|
str.Append(" >> ");
|
|
str.Append(SetStText());
|
|
}
|
|
|
|
return str.ToString();
|
|
}
|
|
|
|
public string GetRecvDat()
|
|
{
|
|
StringBuilder str = new StringBuilder();
|
|
|
|
|
|
if (cmd_result == SendStatus.SEND_RECV_OK)
|
|
{
|
|
var dat=string.Format("RECV CM:0x{0:X2} L:{1} ", recv_dat.cmd, recv_dat.leng);
|
|
str.Append(dat);
|
|
str.Append("DATA:");
|
|
for (int i = 0; i < recv_dat.leng - 1; i++)
|
|
{
|
|
dat=string.Format("{0:X2} ", recv_dat.dat[i]);
|
|
str.Append(dat);
|
|
}
|
|
str.Append(" Raw: ");
|
|
|
|
for (int i = 0; i < m_all_recvsize; i++)
|
|
{
|
|
dat=string.Format("{0:X2} ", recv_buf[i]);
|
|
str.Append(dat);
|
|
}
|
|
}
|
|
else if (cmd_result == SendStatus.RECV_ERR)
|
|
{
|
|
str.Append("recv err");
|
|
}
|
|
//str.Append("\r\n");
|
|
return str.ToString();
|
|
}
|
|
|
|
public int ImgSave(FileStream file)
|
|
{
|
|
if (send_dat.ret == Constants.E_OK && recv_dat.ret == Constants.E_OK)
|
|
{
|
|
file.Write(recv_dat.dat, 0, recv_dat.leng - 1);
|
|
}
|
|
return Constants.E_OK;
|
|
}
|
|
|
|
public int SendXXCmd(byte cmd)
|
|
{
|
|
return SendXXCmd(new byte[] { cmd }, 1);
|
|
}
|
|
|
|
public int SendXXCmd(byte[] cmd, int len)
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = cmd[0];
|
|
send_dat.leng = len;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
|
|
for (int x = 0; x < len - 1; x++)
|
|
{
|
|
send_dat.dat[x] = cmd[x + 1];
|
|
}
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
|
|
public int SendEventRead(ushort dat)
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_DE_EVDATA_READ;
|
|
send_dat.leng = 1 + 2;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
send_dat.dat[0] = (byte)((dat & 0xFF00) >> 8);
|
|
send_dat.dat[1] = (byte)(dat & 0x00FF);
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
|
|
public int SendEventFix(ushort dat)
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_DE_EVDATA_FIX;
|
|
send_dat.leng = 1 + 2;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
send_dat.dat[0] = (byte)((dat & 0xFF00) >> 8);
|
|
send_dat.dat[1] = (byte)(dat & 0x00FF);
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
|
|
public int SendLock()
|
|
{
|
|
send_dat.ret = Constants.E_OK;
|
|
send_dat.cmd = (byte)Command.CMD_DE_LOCK;
|
|
send_dat.bcc = 0x00;
|
|
Array.Clear(send_dat.dat, 0, send_dat.dat.Length);
|
|
SetLockParam();
|
|
|
|
//SendDataSet();
|
|
//send_dat.ret = SendData();
|
|
//if (send_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.SEND_ERR;
|
|
// return Constants.E_NG_SEND;
|
|
//}
|
|
//recv_dat.ret = WaitRsp();
|
|
//if (recv_dat.ret != Constants.E_OK)
|
|
//{
|
|
// cmd_result = SendStatus.RECV_ERR;
|
|
// return Constants.E_NG_RECV;
|
|
//}
|
|
//cmd_result = SendStatus.SEND_RECV_OK;
|
|
//return Constants.E_OK;
|
|
return SendRecvData();
|
|
}
|
|
public LockParam GetLockParam()
|
|
{
|
|
return lock_param;
|
|
}
|
|
public void SetLockParam()
|
|
{
|
|
int size;
|
|
uint amount_i = 0;
|
|
uint amount_f = 0;
|
|
|
|
send_dat.dat[0] = 0x00;
|
|
send_dat.dat[1] = (byte)((lock_param.Register & 0xff00) >> 8);
|
|
send_dat.dat[2] = (byte)(lock_param.Register & 0xff);
|
|
send_dat.dat[3] = (byte)((lock_param.ID & 0xff000000) >> 24);
|
|
send_dat.dat[4] = (byte)((lock_param.ID & 0xff0000) >> 16);
|
|
send_dat.dat[5] = (byte)((lock_param.ID & 0xff00) >> 8);
|
|
send_dat.dat[6] = (byte)(lock_param.ID & 0xff);
|
|
send_dat.dat[7] = 9;
|
|
send_dat.dat[8] = (byte)((lock_param.TransactionNo & 0xff00) >> 8);
|
|
send_dat.dat[9] = (byte)(lock_param.TransactionNo & 0xff);
|
|
send_dat.dat[10] = (byte)lock_param.mode;
|
|
send_dat.dat[11] = (byte)(lock_param.Currency == Currency.CURRENCY_MLT ? 10 : (byte)lock_param.Currency);
|
|
|
|
switch (lock_param.mode)
|
|
{
|
|
case Mode.MODE_COUNT:
|
|
send_dat.dat[12] = 0;
|
|
size = 1 + 12 + 1;
|
|
break;
|
|
case Mode.MODE_MANUAL:
|
|
send_dat.dat[12] = 0;
|
|
amount_i = (uint)lock_param.Gengai.amount;
|
|
amount_f = (uint)((lock_param.Gengai.amount * 1000) - amount_i * 1000);
|
|
send_dat.dat[13] = (byte)((amount_i & 0xff000000) >> 24);
|
|
send_dat.dat[14] = (byte)((amount_i & 0xff0000) >> 16);
|
|
send_dat.dat[15] = (byte)((amount_i & 0xff00) >> 8);
|
|
send_dat.dat[16] = (byte)(amount_i & 0xff);
|
|
send_dat.dat[17] = (byte)((amount_f & 0xff00) >> 8);
|
|
send_dat.dat[18] = (byte)(amount_f & 0xff);
|
|
size = 1 + 12 + 7;
|
|
break;
|
|
case Mode.MODE_BATCH:
|
|
send_dat.dat[12] = (byte)lock_param.Batch.Regi_num;
|
|
Array.Copy(lock_param.Batch.batch_num, 0, send_dat.dat, 13, 64);
|
|
size = 1 + 12 + 65;
|
|
break;
|
|
case Mode.MODE_CHANGE:
|
|
case Mode.MODE_COLLECTION:
|
|
Array.Copy(lock_param.Cassette.CassetteID, 0, send_dat.dat, 12, 16);
|
|
size = 1 + 12 + 16;
|
|
break;
|
|
case Mode.MODE_SET:
|
|
send_dat.dat[12] = 5;
|
|
send_dat.dat[13] = 4;
|
|
send_dat.dat[14] = 2;
|
|
send_dat.dat[15] = 0;
|
|
send_dat.dat[16] = 5;
|
|
size = 1 + 12 + 5;
|
|
break;
|
|
default:
|
|
size = 1 + 12;
|
|
break;
|
|
}
|
|
send_dat.leng = size;
|
|
}
|
|
|
|
public string SetStText()
|
|
{
|
|
StringBuilder text = new StringBuilder();
|
|
|
|
switch (cmd_result)
|
|
{
|
|
case SendStatus.SEND_ERR:
|
|
case SendStatus.SEND_DAT_ERR:
|
|
text.Append("SEND_ERR");
|
|
break;
|
|
case SendStatus.RECV_ERR:
|
|
text.Append("RECV_ERR");
|
|
break;
|
|
case SendStatus.SEND_RECV_OK:
|
|
text.Append("SR1");
|
|
text.Append(GetSR1Summary(recv_dat.dat[0]));
|
|
text.Append(", ");
|
|
|
|
text.AppendFormat("SR2: ");
|
|
text.Append(GetSR2Summary(recv_dat.dat[1]));
|
|
text.Append(", ");
|
|
|
|
if (recv_dat.leng >= 15)
|
|
{
|
|
if (recv_dat.cmd == (byte)Command.CMD_DE_SENSE || recv_dat.cmd == (byte)Command.CMD_GDB_SENSE)
|
|
{
|
|
text.AppendFormat("Sent/unsent events:{0}/{1} ",
|
|
recv_dat.dat[13] * 0x0100 + recv_dat.dat[14],
|
|
recv_dat.dat[15] * 0x0100 + recv_dat.dat[16]);
|
|
if (recv_dat.leng == 84 || recv_dat.leng == 86)
|
|
{
|
|
text.Append(GetSummaryTotal(recv_dat.dat, 19));
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case SendStatus.SEND_NON:
|
|
default:
|
|
text.Append("SEND_NON");
|
|
break;
|
|
}
|
|
return text.ToString();
|
|
}
|
|
|
|
public string GetSummaryTotal(byte[] counts, int numDenoms, bool wordcounts = true)
|
|
{
|
|
StringBuilder ret = new StringBuilder();
|
|
double[] total = new double[10];
|
|
string[] pCurrencyID = new string[10];
|
|
|
|
Array.Clear(total, 0, total.Length);
|
|
Array.Clear(pCurrencyID, 0, pCurrencyID.Length);
|
|
|
|
if (mDenominationCount > 0 && mDenominationCount < 65)
|
|
{
|
|
numDenoms = Math.Min(numDenoms, mDenominationCount);
|
|
|
|
for (int x = 0; x < numDenoms; x++)
|
|
{
|
|
if (mDenomTable[x].mCurrenyIndex < total.Length)
|
|
{
|
|
int noteCount;
|
|
if (wordcounts)
|
|
{
|
|
noteCount = counts[x * 2] * 256 + counts[x * 2 + 1];
|
|
}
|
|
else
|
|
{
|
|
noteCount = counts[x];
|
|
}
|
|
total[mDenomTable[x].mCurrenyIndex] += mDenomTable[x].mDenomValue * noteCount;
|
|
pCurrencyID[mDenomTable[x].mCurrenyIndex] = mDenomTable[x].currency;
|
|
}
|
|
}
|
|
ret.Append("Counted: ");
|
|
for (int x = 0; x < total.Length; x++)
|
|
{
|
|
if (total[x] != 0)
|
|
{
|
|
ret.AppendFormat(" {0}: {1:0.00}", pCurrencyID[x] ?? "???", total[x]);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ret.Append(" No denom data");
|
|
}
|
|
|
|
return ret.ToString();
|
|
}
|
|
|
|
public string GetSR1Summary(byte sr1)
|
|
{
|
|
StringBuilder text = new StringBuilder();
|
|
|
|
text.AppendFormat("(0x{0:X2}): ", sr1);
|
|
switch (sr1)
|
|
{
|
|
case 0x40:
|
|
text.Append("CMD OK");
|
|
break;
|
|
case 0x41:
|
|
text.Append("No execution");
|
|
break;
|
|
case 0x42:
|
|
text.Append("Store fail,");
|
|
break;
|
|
case 0x43:
|
|
text.Append("Unknown command");
|
|
break;
|
|
case 0x44:
|
|
text.Append("Length error");
|
|
break;
|
|
case 0x46:
|
|
text.Append("CMD error (not executed)");
|
|
break;
|
|
case 0x47:
|
|
text.Append("Local processing");
|
|
break;
|
|
case 0x48:
|
|
text.Append("Already occupied");
|
|
break;
|
|
case 0x49:
|
|
text.Append("Abnormal data");
|
|
break;
|
|
default:
|
|
text.Append("Unknown SR1");
|
|
break;
|
|
}
|
|
return text.ToString();
|
|
}
|
|
public string GetS1Summary(byte s1)
|
|
{
|
|
string text = string.Format("(0x{0:X}): {1}{2}{3}{4}{5}{6}{7}{8}", s1,
|
|
(s1 & 0x80) != 0 ? "Locked, " : "Not locked, ",
|
|
(s1 & 0x40) != 0 ? "Escrow door closed, " : "Escrow door open, ",
|
|
(s1 & 0x20) != 0 ? "" : "bit5=false, ",
|
|
(s1 & 0x10) != 0 ? "" : "bit4=false, ",
|
|
(s1 & 0x08) != 0 ? "Cassette full, " : "Cassette not full, ",
|
|
(s1 & 0x04) != 0 ? "bit2=true, " : "",
|
|
(s1 & 0x02) != 0 ? "bit1=true, " : "",
|
|
(s1 & 0x01) != 0 ? "Dirty sensor, " : "No dirty sensor, ");
|
|
|
|
text = text.TrimEnd(',', ' ');
|
|
|
|
return text;
|
|
}
|
|
public string GetS2Summary(byte s2)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.AppendFormat("(0x{0:X}): ", s2);
|
|
|
|
switch (s2 & 0xf0)
|
|
{
|
|
case 0x00: text.Append("Login mode, "); break;
|
|
case 0x10: text.Append("Deposit mode, "); break;
|
|
case 0x20: text.Append("Counting mode, "); break;
|
|
case 0x30: text.Append("Manual mode, "); break;
|
|
case 0x40: text.Append("Batch mode, "); break;
|
|
case 0x50: text.Append("Close mode, "); break;
|
|
case 0x60: text.Append("Temporary close mode, "); break;
|
|
case 0x70: text.Append("Change mode, "); break;
|
|
case 0x80: text.Append("Collection mode, "); break;
|
|
case 0x90: text.Append("Setting mode, "); break;
|
|
case 0xa0: text.Append("Error mode, "); break;
|
|
case 0xb0: text.Append("Currency change mode, "); break;
|
|
case 0xc0:
|
|
case 0xd0: text.Append("Spare mode, "); break;
|
|
case 0xe0: text.Append("Important error mode, "); break;
|
|
case 0xf0: text.Append("Initial mode, "); break;
|
|
default: text.Append("Unexpected S2 mode value, "); break;
|
|
}
|
|
|
|
return text.ToString().TrimEnd(',', ' ');
|
|
}
|
|
public string GetSR2Summary(byte sr2)
|
|
{
|
|
StringBuilder text = new StringBuilder();
|
|
|
|
text.AppendFormat("(0x{0:X2}): ", sr2);
|
|
switch (sr2)
|
|
{
|
|
case 0x01:
|
|
text.Append("Initialising");
|
|
break;
|
|
case 0x1c:
|
|
text.Append("Initialisation error (cycle power)");
|
|
break;
|
|
case 0x1b:
|
|
text.Append("Resetting");
|
|
break;
|
|
case 0x0a:
|
|
text.Append("Waiting for notes to be removed");
|
|
break;
|
|
case 0x04:
|
|
text.Append("Stand by");
|
|
break;
|
|
case 0x07:
|
|
text.Append("Ready to count");
|
|
break;
|
|
case 0x09:
|
|
text.Append("Counting/batch");
|
|
break;
|
|
case 0x1f:
|
|
text.Append("Batch processing");
|
|
break;
|
|
case 0x0d:
|
|
text.Append("Setting");
|
|
break;
|
|
default:
|
|
text.Append("Unknown SR2");
|
|
break;
|
|
}
|
|
return text.ToString();
|
|
}
|
|
public string GetSR3Summary(byte sr3)
|
|
{
|
|
StringBuilder text = new StringBuilder();
|
|
text.AppendFormat("(0x{0:X2}): ", sr3);
|
|
|
|
switch (sr3)
|
|
{
|
|
case 0x40:
|
|
text.Append("Busy");
|
|
break;
|
|
case 0x41:
|
|
text.Append("Normal completion");
|
|
break;
|
|
case 0x42:
|
|
text.Append("Operation could not start");
|
|
break;
|
|
case 0x43:
|
|
text.Append("Stacker full");
|
|
break;
|
|
case 0x44:
|
|
text.Append("Reject pocket full");
|
|
break;
|
|
case 0x45:
|
|
text.Append("Failure to feed notes");
|
|
break;
|
|
case 0x4A:
|
|
text.Append("Waiting for reset");
|
|
break;
|
|
case 0x4C:
|
|
text.Append("Waiting for an error recovery sequence");
|
|
break;
|
|
default:
|
|
text.Append("Unknown SR3");
|
|
break;
|
|
}
|
|
|
|
return text.ToString();
|
|
}
|
|
public string GetD1Summary(byte d1)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.AppendFormat("(0x{0:X}): ", d1);
|
|
text.Append((d1 & 0x80) != 0 ? "bit7=true, " : "");
|
|
text.Append((d1 & 0x40) != 0 ? "Reject pocket full, " : "reject pocket not full, ");
|
|
text.Append((d1 & 0x20) != 0 ? "bit5=true, " : "");
|
|
text.Append((d1 & 0x10) != 0 ? "note(s) in reject pocket, " : "reject pocket empty, ");
|
|
text.Append((d1 & 0x08) != 0 ? "failure to feed, " : "last feed OK, ");
|
|
text.Append((d1 & 0x04) != 0 ? "bit3=true, " : "");
|
|
text.Append((d1 & 0x02) != 0 ? "note in feeder mech, " : "feeder mech clear, ");
|
|
text.Append((d1 & 0x01) != 0 ? "note(s) in feeder hopper" : "feeder hopper empty");
|
|
return text.ToString().TrimEnd(',', ' ');
|
|
}
|
|
public string GetD2Summary(byte d2)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.AppendFormat("(0x{0:X}): ", d2);
|
|
text.Append((d2 & 0x80) != 0 ? "bit7=true, " : "");
|
|
text.Append((d2 & 0x40) != 0 ? "bit6=true, " : "");
|
|
text.Append((d2 & 0x20) != 0 ? "bit5=true, " : "");
|
|
text.Append((d2 & 0x10) != 0 ? "bit4=true, " : "");
|
|
text.Append((d2 & 0x08) != 0 ? "bit3=true, " : "");
|
|
text.Append((d2 & 0x04) != 0 ? "bit2=true, " : "");
|
|
text.Append((d2 & 0x02) != 0 ? "bit1=true, " : "");
|
|
text.Append((d2 & 0x01) != 0 ? "notes in escrow" : "escrow empty");
|
|
return text.ToString().TrimEnd(',', ' ');
|
|
}
|
|
public string GetD3Summary(byte d3)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.AppendFormat("(0x{0:X}): ", d3);
|
|
text.Append((d3 & 0x80) != 0 ? "bit7=true, " : "");
|
|
text.Append((d3 & 0x40) != 0 ? "bit6=true, " : "");
|
|
text.Append((d3 & 0x20) != 0 ? "bit5=true, " : "");
|
|
text.Append((d3 & 0x10) != 0 ? "bit4=true, " : "");
|
|
text.Append((d3 & 0x08) != 0 ? "bit3=true, " : "");
|
|
text.Append((d3 & 0x04) != 0 ? "bit2=true, " : "");
|
|
text.Append((d3 & 0x02) != 0 ? "bit1=true, " : "");
|
|
text.Append((d3 & 0x01) != 0 ? "escrow full" : "escrow not full");
|
|
return text.ToString().TrimEnd(',', ' ');
|
|
}
|
|
public string GetD4Summary(byte d4)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.AppendFormat("(0x{0:X}): ", d4);
|
|
text.Append((d4 & 0x80) != 0 ? "bit7=true, " : "");
|
|
text.Append((d4 & 0x40) != 0 ? "bit6=true, " : "");
|
|
text.Append((d4 & 0x20) != 0 ? "bit5=true, " : "");
|
|
text.Append((d4 & 0x10) != 0 ? "bit4=true, " : "");
|
|
text.Append((d4 & 0x08) != 0 ? "bit3=true, " : "");
|
|
text.Append((d4 & 0x04) != 0 ? "bit2=true, " : "");
|
|
text.Append((d4 & 0x02) != 0 ? "bit1=true, " : "");
|
|
text.Append((d4 & 0x01) != 0 ? "batch complete" : "batch not complete");
|
|
return text.ToString().TrimEnd(',', ' ');
|
|
}
|
|
public string GetD5Summary(byte d5)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.AppendFormat("(0x{0:X}): ", d5);
|
|
text.Append((d5 & 0x80) != 0 ? "bit7=true, " : "");
|
|
text.Append((d5 & 0x40) != 0 ? "bit6=true, " : "");
|
|
text.Append((d5 & 0x20) != 0 ? "bit5=true, " : "");
|
|
text.Append((d5 & 0x10) != 0 ? "bit4=true, " : "");
|
|
text.Append((d5 & 0x08) != 0 ? "bit3=true, " : "");
|
|
text.Append((d5 & 0x04) != 0 ? "bit2=true, " : "");
|
|
text.Append((d5 & 0x02) != 0 ? "bit1=true, " : "");
|
|
text.Append((d5 & 0x01) != 0 ? "1+ forgotten notes sequences stored notes in this cassette" : "no forgotten notes are stored in this cassette");
|
|
return text.ToString().TrimEnd(',', ' ');
|
|
}
|
|
public string GetD6Summary(byte d6)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.AppendFormat("(0x{0:X}): ", d6);
|
|
text.Append((d6 & 0x80) != 0 ? "serial number capture data nearly full, " : "serial number capture data space available, ");
|
|
text.Append((d6 & 0x40) != 0 ? "serial number capture data full, " : "serial number capture data space not full, ");
|
|
text.Append((d6 & 0x20) != 0 ? "bit5=true, " : "");
|
|
text.Append((d6 & 0x10) != 0 ? "bit4=true, " : "");
|
|
text.Append((d6 & 0x08) != 0 ? "bit3=true, " : "");
|
|
text.Append((d6 & 0x04) != 0 ? "bit2=true, " : "");
|
|
text.Append((d6 & 0x02) != 0 ? "bit1=true, " : "");
|
|
text.Append((d6 & 0x01) != 0 ? "transport covers open" : "transport covers closed");
|
|
return text.ToString().TrimEnd(',', ' ');
|
|
}
|
|
public string GetD7D8Summary(byte d7, byte d8)
|
|
{
|
|
var text = new StringBuilder();
|
|
string errorDecode = "The error code was not found in the lookup list.";
|
|
int errorCode = d7 * 256 + d8;
|
|
|
|
try
|
|
{
|
|
using (var reader = new StreamReader("ErrorCodesExportedFromServiceManual.csv"))
|
|
{
|
|
string line;
|
|
while ((line = reader.ReadLine()) != null)
|
|
{
|
|
var tokens = line.Split(',');
|
|
if (int.TryParse(tokens[0], out int decimalCode) && decimalCode == errorCode)
|
|
{
|
|
errorDecode = tokens[2] + (tokens.Length > 3 ? ", " + tokens[3] : "");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (FileNotFoundException)
|
|
{
|
|
errorDecode = "Cannot open error lookup file ErrorCodesExportedFromServiceManual.csv";
|
|
}
|
|
|
|
text.AppendFormat("(0x{0:X}): {1}", errorCode, errorDecode);
|
|
return text.ToString().TrimEnd(',', ' ');
|
|
}
|
|
public string GetD9Summary(byte d9)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.AppendFormat("(0x{0:X}): ", d9);
|
|
|
|
switch (d9 & 0xf0)
|
|
{
|
|
case 0x10: text.Append("First currency"); break;
|
|
case 0x20: text.Append("Second currency"); break;
|
|
case 0x30: text.Append("Third currency"); break;
|
|
case 0x40: text.Append("Fourth currency"); break;
|
|
case 0x50: text.Append("Fifth currency"); break;
|
|
case 0x60: text.Append("Sixth currency"); break;
|
|
case 0x70: text.Append("Seventh currency"); break;
|
|
default: text.Append("Unexpected currency value"); break;
|
|
}
|
|
|
|
return text.ToString();
|
|
}
|
|
public string GetD10Summary(byte d10)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.AppendFormat("(0x{0:X}): ", d10);
|
|
text.Append((d10 & 0x80) != 0 ? "bit7=true, " : "");
|
|
text.Append((d10 & 0x40) != 0 ? "bit6=true, " : "");
|
|
text.Append((d10 & 0x20) != 0 ? "bit5=true, " : "");
|
|
text.Append((d10 & 0x10) != 0 ? "bit4=true, " : "");
|
|
text.Append((d10 & 0x08) != 0 ? "bit3=true, " : "");
|
|
text.Append((d10 & 0x04) != 0 ? "bit2=true, " : "");
|
|
text.Append((d10 & 0x02) != 0 ? "bit1=true, " : "");
|
|
text.Append((d10 & 0x01) != 0 ? "bit0=true, " : "");
|
|
return text.ToString().TrimEnd(',', ' ');
|
|
}
|
|
|
|
public int GetSerialNum(out ushort num)
|
|
{
|
|
ushort serial_num;
|
|
|
|
if (recv_dat.cmd == (byte)Command.CMD_GDB_SENSE && recv_dat.leng == Constants.DATLEN_GDBSense_Cnt)
|
|
{
|
|
serial_num = (ushort)(recv_dat.dat[83] * 0x100 + recv_dat.dat[84]);
|
|
if (serial_num <= 1000)
|
|
{
|
|
num = serial_num;
|
|
return Constants.E_OK;
|
|
}
|
|
}
|
|
num = 0x00;
|
|
return Constants.E_NG;
|
|
}
|
|
|
|
public bool ChkCntEnd()
|
|
{
|
|
return recv_dat.cmd != (byte)Command.CMD_GDB_SENSE || recv_dat.dat[1] != (byte)SR2.SR2_cnting;
|
|
}
|
|
|
|
public void GetRecvSerialSet(byte[] dat)
|
|
{
|
|
Array.Copy(recv_serialset, dat, recv_serialset.Length);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return GetSendDat(true);
|
|
}
|
|
|
|
public int GetSendDatLength()
|
|
{
|
|
return send_dat.leng;
|
|
}
|
|
|
|
public int GetRecDatLength()
|
|
{
|
|
return recv_dat.leng - 1;
|
|
}
|
|
|
|
public byte[] GetSendDatPtr()
|
|
{
|
|
return send_dat.dat;
|
|
}
|
|
|
|
public byte[] GetRecDatPtr()
|
|
{
|
|
return recv_dat.dat;
|
|
}
|
|
|
|
public Command GetCmdByte()
|
|
{
|
|
return (Command)send_dat.cmd;
|
|
}
|
|
|
|
public string GetCommandName(byte cmd)
|
|
{
|
|
switch (cmd)
|
|
{
|
|
case 0x22:
|
|
return "CMD_SENSE";
|
|
case 0x40:
|
|
return "CMD_ST_UPLOAD";
|
|
case 0x41:
|
|
return "CMD_END_UPLOAD";
|
|
case 0x44:
|
|
return "CMD_REQ_UPLOAD";
|
|
case 0x45:
|
|
return "CMD_ST_DOWNLOAD";
|
|
case 0x46:
|
|
return "CMD_END_DOWNLOAD";
|
|
case 0x49:
|
|
return "CMD_REQ_DOWNLOAD";
|
|
case 0x4A:
|
|
return "CMD_P_UPDATE";
|
|
case 0x4D:
|
|
return "CMD_GETFILEINFO";
|
|
case 0x59:
|
|
return "CMD_VERSION";
|
|
case 0x60:
|
|
return "CMD_DE_SENSE";
|
|
case 0x61:
|
|
return "CMD_DE_SET_TIME";
|
|
case 0x62:
|
|
return "CMD_DE_SETDATA_READ";
|
|
case 0x63:
|
|
return "CMD_DE_BVDATA_READ";
|
|
case 0x64:
|
|
return "CMD_DE_EVDATA_READ";
|
|
case 0x65:
|
|
return "CMD_DE_EVDATA_FIX";
|
|
case 0x66:
|
|
return "CMD_DE_READ_CASSETTE";
|
|
case 0x70:
|
|
return "CMD_DE_LOCK";
|
|
case 0x71:
|
|
return "CMD_DE_UNLOCK";
|
|
case 0x73:
|
|
return "CMD_DE_CNTSTART";
|
|
case 0x74:
|
|
return "CMD_DE_CNTEND";
|
|
case 0x75:
|
|
return "CMD_DE_STORESTART";
|
|
case 0x76:
|
|
return "CMD_DE_CANCEL";
|
|
case 0x77:
|
|
return "CMD_DE_RESET";
|
|
case 0x78:
|
|
return "CMD_DE_TRANSACTION_READ";
|
|
case 0x79:
|
|
return "CMD_DE_DEALFORGOTTEN";
|
|
case 0x80:
|
|
return "CMD_GDB_SENSE";
|
|
case 0x81:
|
|
return "CMD_GDB_BVDATA_READ";
|
|
case 0x82:
|
|
return "CMD_GDB_SETDATA";
|
|
case 0x83:
|
|
return "CMD_GDB_SETRJSERIAL";
|
|
case 0x84:
|
|
return "CMD_GDB_SETDATAREAD";
|
|
case 0xA0:
|
|
return "CMD_GDB_GETSERIAL";
|
|
default:
|
|
return "Unknown Command";
|
|
}
|
|
}
|
|
|
|
public void ClearDenomTable()
|
|
{
|
|
for (int x = 0; x < GetDenomTableElements(); x++)
|
|
{
|
|
if (mDenomTable[x].currency != null)
|
|
{
|
|
mDenomTable[x].currency = null;
|
|
}
|
|
mDenomTable[x].mCurrenyIndex = 0;
|
|
mDenomTable[x].currency = null;
|
|
mDenomTable[x].issue = 0;
|
|
mDenomTable[x].mDenomValue = 0;
|
|
}
|
|
|
|
mDenominationCount = 0;
|
|
}
|
|
|
|
public CDenom[] GetDenomTablePtr()
|
|
{
|
|
return mDenomTable;
|
|
}
|
|
|
|
public int GetDenomTableElements()
|
|
{
|
|
return mDenomTable.Length;
|
|
}
|
|
|
|
public void SetDenominationCount(int c)
|
|
{
|
|
mDenominationCount = c;
|
|
}
|
|
}
|
|
|
|
public class Constants
|
|
{
|
|
public const byte D_DLE = 0x10;
|
|
public const byte D_STX = 0x02;
|
|
public const byte D_NAK = 0x15;
|
|
public const byte D_ETX = 0x03;
|
|
public const byte E_OK = 0x00;
|
|
public const byte E_NG = 0x01;
|
|
public const byte E_NG_FILE = 0x02;
|
|
public const byte E_NG_DAT = 0x03;
|
|
public const byte E_NG_SEND = 0x04;
|
|
public const byte E_NG_RECV = 0x05;
|
|
public const int DATLEN_GDBSense_Cnt = 86;
|
|
}
|
|
|
|
public class SendDataStruct
|
|
{
|
|
public byte ret;
|
|
public byte cmd;
|
|
public int leng;
|
|
public byte bcc;
|
|
public byte[] dat = new byte[1024];
|
|
}
|
|
|
|
public class RecvData
|
|
{
|
|
public byte ret;
|
|
public byte cmd;
|
|
public int leng;
|
|
public byte bcc;
|
|
public byte[] dat = new byte[8192];
|
|
}
|
|
|
|
public enum SendStatus
|
|
{
|
|
SEND_NON,
|
|
SEND_RECV_OK,
|
|
SEND_DAT_ERR,
|
|
SEND_ERR,
|
|
RECV_ERR
|
|
}
|
|
|
|
public enum Mode
|
|
{
|
|
MODE_DEPOSIT = 1,
|
|
MODE_COUNT = 2,
|
|
MODE_MANUAL = 3,
|
|
MODE_BATCH = 4,
|
|
MODE_CLOSE = 5,
|
|
MODE_TCLS = 6,
|
|
MODE_CHANGE = 7,
|
|
MODE_COLLECTION = 8,
|
|
MODE_SET = 9,
|
|
MODE_SECERROR = 14
|
|
}
|
|
|
|
public enum Currency
|
|
{
|
|
CURRENCY01, //‘æ‚P’ʉÝ
|
|
CURRENCY02, //‘æ‚Q’ʉÝ
|
|
CURRENCY03, //‘æ‚R’ʉÝ
|
|
CURRENCY04, //‘æ‚S’ʉÝ
|
|
CURRENCY05, //‘æ‚T’ʉÝ
|
|
CURRENCY06, //‘æ‚U’ʉÝ
|
|
CURRENCY07, //‘æ‚V’ʉÝ
|
|
CURRENCY_MLT, //’ʉ݃}ƒ‹ƒ`
|
|
}
|
|
|
|
enum SR2
|
|
{
|
|
SR2_init = 0x01,
|
|
SR2_wait = 0x04,
|
|
SR2_cntwait = 0x07,
|
|
SR2_cnting = 0x09,
|
|
SR2_check = 0x0a,
|
|
SR2_seting = 0x0d,
|
|
SR2_reset = 0x1b,
|
|
SR2_rst_wait = 0x1c,
|
|
SR2_ras = 0x1d,
|
|
SR2_batch = 0x1f,
|
|
};
|
|
|
|
public enum Command
|
|
{
|
|
CMD_NULL = 0, // uninitialised / not a command value
|
|
CMD_SENSE = 0x22,
|
|
CMD_ST_UPLOAD = 0x40,
|
|
CMD_END_UPLOAD = 0x41,
|
|
CMD_REQ_UPLOAD = 0x44,
|
|
CMD_ST_DOWNLOAD = 0x45,
|
|
CMD_END_DOWNLOAD = 0x46,
|
|
CMD_REQ_DOWNLOAD = 0x49,
|
|
CMD_P_UPDATE = 0x4A,
|
|
CMD_GETFILEINFO = 0x4D,
|
|
CMD_VERSION = 0x59,
|
|
CMD_DE_SENSE = 0x60,
|
|
CMD_DE_SET_TIME = 0x61,
|
|
CMD_DE_SETDATA_READ = 0x62,
|
|
CMD_DE_BVDATA_READ = 0x63,
|
|
CMD_DE_EVDATA_READ = 0x64,
|
|
CMD_DE_EVDATA_FIX = 0x65,
|
|
CMD_DE_READ_CASSETTE = 0x66,
|
|
CMD_DE_LOCK = 0x70,
|
|
CMD_DE_UNLOCK = 0x71,
|
|
CMD_DE_CNTSTART = 0x73,
|
|
CMD_DE_CNTEND = 0x74,
|
|
CMD_DE_STORESTART = 0x75,
|
|
CMD_DE_CANCEL = 0x76,
|
|
CMD_DE_RESET = 0x77,
|
|
CMD_DE_TRANSACTION_READ = 0x78,
|
|
CMD_DE_DEALFORGOTTEN = 0x79,
|
|
CMD_GDB_SENSE = 0x80,
|
|
CMD_GDB_BVDATA_READ = 0x81,
|
|
CMD_GDB_SETDATA = 0x82,
|
|
CMD_GDB_SETRJSERIAL = 0x83,
|
|
CMD_GDB_SETDATAREAD = 0x84,
|
|
CMD_GDB_GETSERIAL = 0xA0,
|
|
}
|
|
|
|
public class Com232C
|
|
{
|
|
SerialPort serialPort = null;
|
|
public Com232C(SerialPort _serialPort)
|
|
{
|
|
this.serialPort = _serialPort;
|
|
}
|
|
public byte send_dat(byte[] buf, int size)
|
|
{
|
|
//Debug.WriteLine(DE70_CMD.ByteArrayToString(buf, 0, size));
|
|
try
|
|
{
|
|
serialPort.Write(buf, 0, size);
|
|
return Constants.E_OK;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
try
|
|
{
|
|
Log.Fatal(e, "DE70_send_dat");
|
|
if (serialPort.IsOpen)
|
|
serialPort.Close();
|
|
serialPort.Open();
|
|
}
|
|
catch (Exception e2)
|
|
{
|
|
Log.Fatal(e2,"DE70_send_dat2");
|
|
}
|
|
|
|
}
|
|
|
|
// Implement serial communication send function
|
|
return Constants.E_NG;
|
|
}
|
|
|
|
public int rcv_dat(byte[] buf, int pos, int size)
|
|
{
|
|
try
|
|
{
|
|
return serialPort.Read(buf, pos, size);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
try
|
|
{
|
|
Log.Fatal(e, "DE70_rcv_dat");
|
|
if (serialPort.IsOpen)
|
|
serialPort.Close();
|
|
serialPort.Open();
|
|
}
|
|
catch (Exception e2)
|
|
{
|
|
Log.Fatal(e2, "DE70_rcv_dat2");
|
|
}
|
|
|
|
}
|
|
return -1;
|
|
// Implement serial communication receive function
|
|
|
|
}
|
|
}
|
|
|
|
public class LockParam
|
|
{
|
|
public int Register;
|
|
public int ID;
|
|
public int TransactionNo;
|
|
public Mode mode;
|
|
public Currency Currency;
|
|
public Gengai Gengai = new Gengai();
|
|
public Batch Batch = new Batch();
|
|
public Cassette Cassette = new Cassette();
|
|
}
|
|
|
|
public class Gengai
|
|
{
|
|
public double amount;
|
|
}
|
|
|
|
public class Batch
|
|
{
|
|
public int Regi_num;
|
|
public byte[] batch_num = new byte[64];
|
|
}
|
|
|
|
public class Cassette
|
|
{
|
|
public byte[] CassetteID = new byte[16];
|
|
}
|
|
|
|
public class CDenom
|
|
{
|
|
public int mCurrenyIndex;
|
|
public string currency;
|
|
public int issue;
|
|
public double mDenomValue;
|
|
}
|
|
} |