资源简介

本资源以银联刷卡机串口通信为示例,在控制台工程中实现了串口的收发控制和超时提醒。测试程序的功能时,需要将样例报文复制放在,虚拟串口的响应行中,依照程序提示,发送数据后,再通过虚拟串口回复报文,控制台程序获取数据后,显示接收结果。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestSerialPortConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            SerialPortService sps = new SerialPortService();
            string[] ports = sps.getSerialPort();
            Console.WriteLine(“端口信息显示如下:“);
            for (int i = 0; i < ports.Length; i++)
            {
                Console.Write(ports[i] + “  “);
            }
            Console.WriteLine(“\n“);
            Console.WriteLine(“按回车键进入下一步进行端口打开测试“);
            Console.ReadLine();
            Console.WriteLine(“打开端口测试。。。。“);
            if (sps.openSerialPort(“COM2“))
                Console.WriteLine(“打开端口成功!“);
            else
                Console.WriteLine(“打开端口失败!“);
            Console.WriteLine(“按回车键启动接收线程 “);
            Console.ReadLine();
            Console.WriteLine(“启动接收线程测试“); 
            sps.receiveThread();
            Console.WriteLine(“线程接收启动完成“);
            Console.WriteLine(“回车键进行发送测试“);
            Console.ReadLine();
            Console.WriteLine(“发送测试连接数据“);
            if (sps.sendTest())
                Console.WriteLine(“报文发送成功!“);
            else
                Console.WriteLine(“报文发送失败“);

            Console.WriteLine(“回车键重发测试数据“);
            Console.ReadLine();
            Console.WriteLine(“重发测试连接数据“);
            if (sps.sendTest())
                Console.WriteLine(“报文发送成功!“);
            else
                Console.WriteLine(“报文发送失败“);

            Console.WriteLine(“按回车键关闭端口“);
            Console.ReadLine();
            sps.closeSerialPort();
            Console.WriteLine(“端口已正常关闭!“);
            Console.WriteLine(“按任意键退出程序!“);
            Console.ReadLine();
                
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3084  2016-06-16 15:29  SerialPortTestConsole\COM-POS测试指令.txt

     文件      10240  2016-06-16 15:52  SerialPortTestConsole\TestSerialPortConsole\bin\Debug\TestSerialPortConsole.exe

     文件      22016  2016-06-16 15:52  SerialPortTestConsole\TestSerialPortConsole\bin\Debug\TestSerialPortConsole.pdb

     文件      11600  2016-06-16 15:53  SerialPortTestConsole\TestSerialPortConsole\bin\Debug\TestSerialPortConsole.vshost.exe

     文件        490  2015-10-22 09:54  SerialPortTestConsole\TestSerialPortConsole\bin\Debug\TestSerialPortConsole.vshost.exe.manifest

     文件       5858  2016-06-16 15:52  SerialPortTestConsole\TestSerialPortConsole\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        436  2016-06-16 15:53  SerialPortTestConsole\TestSerialPortConsole\obj\x86\Debug\TestSerialPortConsole.csproj.FileListAbsolute.txt

     文件      10240  2016-06-16 15:52  SerialPortTestConsole\TestSerialPortConsole\obj\x86\Debug\TestSerialPortConsole.exe

     文件      22016  2016-06-16 15:52  SerialPortTestConsole\TestSerialPortConsole\obj\x86\Debug\TestSerialPortConsole.pdb

     文件       2160  2016-06-16 15:42  SerialPortTestConsole\TestSerialPortConsole\Program.cs

     文件       1374  2016-06-15 18:22  SerialPortTestConsole\TestSerialPortConsole\Properties\AssemblyInfo.cs

     文件      11498  2016-06-16 15:52  SerialPortTestConsole\TestSerialPortConsole\SerialPortService.cs

     文件       2511  2016-06-15 18:26  SerialPortTestConsole\TestSerialPortConsole\TestSerialPortConsole.csproj

     文件        905  2016-06-15 18:22  SerialPortTestConsole\TestSerialPortConsole.sln

    ..A..H.     18944  2016-06-16 15:53  SerialPortTestConsole\TestSerialPortConsole.suo

     目录          0  2016-06-15 18:22  SerialPortTestConsole\TestSerialPortConsole\obj\x86\Debug\TempPE

     目录          0  2016-06-16 15:52  SerialPortTestConsole\TestSerialPortConsole\obj\x86\Debug

     目录          0  2016-06-16 11:43  SerialPortTestConsole\TestSerialPortConsole\bin\Debug

     目录          0  2016-06-15 18:22  SerialPortTestConsole\TestSerialPortConsole\obj\x86

     目录          0  2016-06-15 18:22  SerialPortTestConsole\TestSerialPortConsole\bin

     目录          0  2016-06-15 18:22  SerialPortTestConsole\TestSerialPortConsole\obj

     目录          0  2016-06-15 18:22  SerialPortTestConsole\TestSerialPortConsole\Properties

     目录          0  2016-06-15 18:23  SerialPortTestConsole\TestSerialPortConsole

     目录          0  2016-06-16 16:56  SerialPortTestConsole

----------- ---------  ---------- -----  ----

               123372                    24


评论

共有 条评论