Esempio n. 1
0
        private void SendMsg(string msg)
        {
            byte[] Len  = BitConverter.GetBytes((short)(msg.Length));
            byte[] data = System.Text.Encoding.ASCII.GetBytes(msg);
            byte[] buf  = new byte[1024];
            int    lrc  = 0;
            int    i    = 0;

            buf[i++] = (byte)'V';
            buf[i++] = (byte)'2';
            buf[i++] = Len[1];
            buf[i++] = Len[0];
            for (int j = 0; j < data.Length; j++)
            {
                buf[i++] = data[j];
                lrc      = lrc ^ data[j];
            }
            buf[i++] = (byte)lrc;
            m_sp.SendCmd(buf, 0, i);
            string sDebug = System.Text.Encoding.ASCII.GetString(buf, 0, i);
            string sh     = "";

            for (int m = 0; m < sDebug.Length; m++)
            {
                sh += "0x" + ((int)sDebug[m]).ToString("X") + " ";
            }
            Program.g_log.Info("vxlink sent " + i + " bytes:" + sDebug + " Hex:" + sh);
        }
        private void DoTCmd(double dPurchaseAmount, double dCashOutAmount, double dRefundAmount, string sRefNum, char tt)
        {
            int    nRefNumLength   = sRefNum.Length;
            string sPurchaseAmount = ((int)(Math.Round(dPurchaseAmount, 2) * 100)).ToString("D12");            //12 bytes left zero padding eg: $12.00 to 000000001200
            string sCashoutAmount  = ((int)(Math.Round(dCashOutAmount, 2) * 100)).ToString("D12");
            string sRefundAmount   = ((int)(Math.Round(dRefundAmount, 2) * 100)).ToString("D12");

            char cmd = 'T';

            byte[] buf = new byte[1024];
            int    p   = 0;

            buf[p++] = 0x02;
            buf[p++] = (byte)cmd;
            buf[p++] = (byte)tt;
            for (int i = 0; i < nRefNumLength; i++)
            {
                buf[p++] = (byte)sRefNum[i];
            }
            for (int i = 0; i < sPurchaseAmount.Length; i++)
            {
                buf[p++] = (byte)sPurchaseAmount[i];
            }
            for (int i = 0; i < sCashoutAmount.Length; i++)
            {
                buf[p++] = (byte)sCashoutAmount[i];
            }
            for (int i = 0; i < sRefundAmount.Length; i++)
            {
                buf[p++] = (byte)sRefundAmount[i];
            }
            buf[p++] = 0x03;

            int lrc = 0;

            for (int i = 1; i < p; i++)
            {
                lrc = lrc ^ buf[i];
            }
            buf[p++] = (byte)lrc;
            m_ssp.SendCmd(buf, 0, p);
        }
Esempio n. 3
0
        private void DoTCmd(double dPurchaseAmount, double dCashOutAmount, double dRefundAmount, string sRefNum, char tt)
        {
            int nRefNumLength = sRefNum.Length;
//			string sPurchaseAmount = ((int)(Math.Round(dPurchaseAmount,2) * 100)).ToString("D12"); //12 bytes left zero padding eg: $12.00 to 000000001200
//			string sCashoutAmount = ((int)(Math.Round(dCashOutAmount,2) * 100)).ToString("D12");
//			string sRefundAmount = ((int)(Math.Round(dRefundAmount,2) * 100)).ToString("D12");

            string sPurchaseAmount   = "";
            double ddPurchaseAmount  = Math.Round((dPurchaseAmount * 10), 2);
            double dddPurchaseAmount = ddPurchaseAmount * 10;

            sPurchaseAmount = ((int)dddPurchaseAmount).ToString("D12");             //12 bytes left zero padding eg: $12.00 to 000000001200

            string sCashoutAmount   = "";
            double ddCashoutAmount  = Math.Round((dCashOutAmount * 10), 2);
            double dddCashoutAmount = ddCashoutAmount * 10;

            sCashoutAmount = ((int)(dddCashoutAmount)).ToString("D12");

            string sRefundAmount   = "";
            double ddRefundAmount  = Math.Round(dRefundAmount * 10, 2);
            double dddRefundAmount = ddRefundAmount * 10;

            sRefundAmount = ((int)(dddRefundAmount)).ToString("D12");

            char cmd = 'T';

            byte[] buf = new byte[1024];
            int    p   = 0;

            buf[p++] = 0x02;
            buf[p++] = (byte)cmd;
            buf[p++] = (byte)tt;
            for (int i = 0; i < nRefNumLength; i++)
            {
                buf[p++] = (byte)sRefNum[i];
            }
            for (int i = 0; i < sPurchaseAmount.Length; i++)
            {
                buf[p++] = (byte)sPurchaseAmount[i];
            }
            for (int i = 0; i < sCashoutAmount.Length; i++)
            {
                buf[p++] = (byte)sCashoutAmount[i];
            }
            for (int i = 0; i < sRefundAmount.Length; i++)
            {
                buf[p++] = (byte)sRefundAmount[i];
            }
            buf[p++] = 0x03;

            int lrc = 0;

            for (int i = 1; i < p; i++)
            {
                lrc = lrc ^ buf[i];
            }
            buf[p++] = (byte)lrc;
            m_sp.SendCmd(buf, 0, p);

            string sDebug = System.Text.Encoding.ASCII.GetString(buf, 0, p);
            string sh     = "";

            for (int m = 0; m < sDebug.Length; m++)
            {
                sh += "0x" + ((int)sDebug[m]).ToString("X") + " ";
            }
            Program.g_log.Info("t1000 sent " + p + " bytes:" + sDebug + " Hex:" + sh);
        }
Esempio n. 4
0
 private void SendMsg(string msg)
 {
     byte[] buf = System.Text.Encoding.ASCII.GetBytes(msg);
     m_sp.SendCmd(buf, 0, buf.Length);
 }