Moneris 半集成解决方案不起作用 [英] Moneris Semi Integrated Solution Not Working

查看:53
本文介绍了Moneris 半集成解决方案不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此时我非常沮丧,我想我会将此作为最后的手段发布.

I am quite frustrated at this point, and I thought I would post this as a last resort.

我正在开发一个 C# .NET 4.5 应用程序,该应用程序将通过 USB 与 Moneris 支付设备进行通信.它是 Moneris ICT-250,Moneris 将其称为半集成"应用程序.我一直在尝试发送测试付款以使设备使用串行端口类工作,但似乎没有任何效果.

I am in the process of developing a C# .NET 4.5 app that will communicate via USB to a Moneris payment device. Its a Moneris ICT-250 and Moneris refers to this as a "semi-integrated" application. I have been trying to send over a test payment to get the device to work using the Serial Port class but nothing seems to be working.

首先,Moneris 确实提供了一个模拟器来启动和运行.我可以确认我可以继续,设置测试付款 - 比如说 100.00 美元 - 发送它......然后设备亮起.它还输出请求和响应的详细日志.

For starters, Moneris does provide a simulator to get up and running. I can confirm that I can go ahead, set up a test payment - say $100.00 - send it off....and the device lights up. It also outputs a detailed log of both the request and response.

每个请求都必须是一个特定格式的字符串,用于标识付款类型、金额等……我已将在日志中找到的字符串发送出去,但似乎没有任何效果.设备未注册失败或成功.

Each request has to be a specifically formatted string that identifies the payment type, amount, etc....I have taken the string that is found in the log and sent that off, but nothing appears to be working. The device doesn't register a fail or a success.

我知道设备已正确连接.如果我更改端口号或拔掉设备,我的 catch 会处理它(如下).

I know that the device is connected properly. If I change the port number or unplug the device, my catch will handle it (below).

下面是一个简单的控制台应用程序.我的代码有问题吗?有没有其他人有任何连接到半集成 Moneris 解决方案的经验?我愿意接受任何想法.Moneris 无法提供任何支持或代码片段.至少可以说非常令人沮丧......

Below is a simple Console app. Is something wrong in my code? Has anyone else had any experience in connecting to a semi-integrated Moneris solution? I am open to any ideas. Moneris is unable to provide any support or code snippets. Very frustrating to say the least...

谢谢大家!代码如下:)

Thanks everyone! Code is below :)

using System;
using System.IO.Ports;

class Moneris_Integration
{
    public static void Main()
    {
        SerialPort port = new SerialPort("COM8");

        // These properties are required by the device         
        port.BaudRate = 19200;
        port.Parity = Parity.Even;
        port.StopBits = StopBits.One;
        port.DataBits = 8;

        port.Open();

        // This is the request that is sent by the simulator to the device
        port.Write("<STX>02<FS>0011000<FS>0020<ETX><LRC>");

        port.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

        Console.WriteLine("===| Moneris Test |===");
        Console.ReadKey();
    }

    private static void DataReceivedHandler(
                        object sender,
                        SerialDataReceivedEventArgs e)
    {
        SerialPort sp = (SerialPort)sender;
        string incomingData = sp.ReadExisting();
        Console.WriteLine("Response:");
        Console.Write(incomingData);
    }
}

推荐答案

好的 - 我开始工作了.我想在这里发布我的解决方案,以防其他人在尝试通过他们所谓的半集成"解决方案与 Moneris 支付设备进行通信时遇到困难.

OK - I got this working. I want to post my solution here in case someone else get's stuck with trying to communicate to a Moneris payment device through what they call a "semi-integrated" solution.

每个人的建议都让我思考......所以经过更多的研究和测试,我能够让设备工作.

Everyone's suggestions got me thinking...so after some more research and testing, I was able to get the device to work.

注意:在这个例子中,发送的十六进制是硬编码的(目前),我对 LRC 进行了硬编码.展望未来,十六进制请求 + LRC 将需要动态计算.另外,将 DataBits 设置为 7 而不是 8!

NOTE: In this example, the hex being sent over is hard coded (for now) and I have hard coded the LRC. Moving forward, the hex requests + LRC will need to be calculated on the fly. Also, set the DataBits to 7 and NOT 8!!

using System;
using System.IO.Ports;

class Moneris_Integration
{
    public static void Main()
    {
        SerialPort port = new SerialPort("COM4");

        port.BaudRate = 19200;
        port.Parity = Parity.Even;
        port.StopBits = StopBits.One;
        port.DataBits = 7;      // Changed to 7. Was incorrectly told it was 8.

        port.Open();

        // You'll need to change this to be whatever your app is trying to send at the time
        // Last array item is the LRC. In my case, it was 0x31
        var bytesToSend = new byte[] { 0x02, 0x30, 0x30, 0x1c, 0x30, 0x30, 0x31, 0x31, 0x30, 0x30, 0x30, 0x1c, 0x30, 0x30, 0x32, 0x30, 0x03, 0x31 };

        port.Write(bytesToSend, 0, bytesToSend.Length);

        port.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

        Console.ReadKey();
    }

    public static byte calculateLRC(byte[] bytes)
    {
        byte LRC = 0;
        for (int i = 0; i < bytes.Length; i++)
        {
            if (i == 0)
            {
                LRC = bytes[i];
            }
            else
            {
                LRC ^= bytes[i];
            }

        }
        return LRC;
    }

    private static void DataReceivedHandler(
    object sender,
    SerialDataReceivedEventArgs e)
    {
        SerialPort sp = (SerialPort)sender;
        string incomingData = sp.ReadExisting();
        Console.WriteLine("Response:");
        Console.Write(incomingData);
    }
}

这篇关于Moneris 半集成解决方案不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆