• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ComPort类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ComPort的典型用法代码示例。如果您正苦于以下问题:C# ComPort类的具体用法?C# ComPort怎么用?C# ComPort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ComPort类属于命名空间,在下文中一共展示了ComPort类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Port

        public Port(ref ComPort _drvcport)
        {
            InitializeComponent();

            // Initialize communication port
            _port = _drvcport;
            InitializePortConfiguration(_port.PortConfig);
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:8,代码来源:Port.cs


示例2: ControlSystem

		/// <summary>
		/// Constructor of the Control System Class. Make sure the constructor always exists.
		/// If it doesn't exit, the code will not run on your 3-Series processor.
		/// </summary>
		public ControlSystem() : base()
		{
			// subscribe to control system events
			CrestronEnvironment.SystemEventHandler += new SystemEventHandler(CrestronEnvironment_SystemEventHandler);
			CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
			CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
			
			// Set the number of threads which you want to use in your program - At this point the threads cannot be created but we should
			// define the max number of threads which we will use in the system.
			// the right number depends on your project; do not make this number unnecessarily large
			Thread.MaxNumberOfUserThreads = 20;


            if (this.SupportsComPort)
            {
                MyCOMPort = this.ComPorts[1];
                MyCOMPort.SerialDataReceived += new ComPortDataReceivedEvent(myComPort_SerialDataReceived);

                if (MyCOMPort.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    ErrorLog.Error("COM Port couldn't be registered. Cause: {0}", MyCOMPort.DeviceRegistrationFailureReason);

                if (MyCOMPort.Registered)
                    MyCOMPort.SetComPortSpec(ComPort.eComBaudRates.ComspecBaudRate9600,
                                             ComPort.eComDataBits.ComspecDataBits8,
                                             ComPort.eComParityType.ComspecParityNone,
                                             ComPort.eComStopBits.ComspecStopBits1,
                                             ComPort.eComProtocolType.ComspecProtocolRS232,
                                             ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone,
                                             ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone,
                                         false);
            }

			// ensure this processor has ethernet then setup the EISC
			if (this.SupportsEthernet)
			{
				myEISC = new EthernetIntersystemCommunications(eISCIPID, eISCIP, this);
				if (myEISC.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
				{
					ErrorLog.Error(">>> The EISC was not registered: {0}", myEISC.RegistrationFailureReason);
				}
				else
				{
					// Device has been registered. Now register for the event handlers
					myEISC.OnlineStatusChange += new OnlineStatusChangeEventHandler(myEISC_OnlineStatusChange);
					myEISC.SigChange += new SigEventHandler(myEISC_SigChange);
					ErrorLog.Notice(">>> The EISC has been registered successfully");
				}
			}
			else
			{
				ErrorLog.Error(">>> This processor does not support ethernet, so this program will not run");
			}


		}
开发者ID:kurtjcu,项目名称:Crestron.SimpleSharp.RMC3-EISC-TV,代码行数:59,代码来源:Controlsystem.cs


示例3: CallFunction

        // Main Access Point
        internal override object CallFunction(string name, string description, ComPort port, object[] param)
        {
            object value = new object();
            OutputData = new byte[0];
            ReadedBytes = 0;

            if (description == string.Empty)
                description = ((Tree)FP_Panel).GetDescription(name);

            switch (name)
            {
                #region Initialization
                case "SetPrintParams":
                    {
                        break;
                    }
                case "SetDateTime":
                    {
                        SetDateTime sdt = new SetDateTime(Protocol_Name, description);
                        if (sdt.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            SetDateTime(port, sdt.NewDateTime);
                        sdt.Dispose();
                        break;
                    }
                case "Fiscalize":
                    {
                        string[] _errMsgs = new string[9] {
                                "������� ���������� ������ ���������",
                                "�� �������� ��������� �����",
                                "������������ ���������� ����� ��� ���� ���������",
                                "³������� ���",
                                "�� ������� ���� �� ���� (������ Z-���)",
                                "�� ����� �������� ������",
                                "���������� ����� ���������� � ����",
                                "���� ������ (����������) ������",
                                "������� �� ������������"};
                        break;
                    }
                case "SetTaxRate":
                    {
                        SetTaxRate str = new SetTaxRate(Protocol_Name, description);
                        if (str.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            object[] taxData = SetTaxRate(port, str.Password, str.DecimalPoint, str.UseRates, str.Rates);
                            string _infotext = string.Empty;

                            if (Methods.IsEmpty(taxData))
                            {
                                _infotext = string.Format("{0}\r\n\r\n{1} - {2}\r\n{3}: {4:0.00} [{5}]\r\n{6}: {7:0.00} [{8}]\r\n{9}: {10:0.00} [{11}]\r\n{12}: {13:0.00} [{14}]",
                                    "�������� ������",
                                    "ʳ������ ����� ���� ����", (byte)taxData[0],
                                    "����� �", (double)taxData[5], (bool)taxData[1] ? "���������" : "�� ���������",
                                    "����� �", (double)taxData[6], (bool)taxData[2] ? "���������" : "�� ���������",
                                    "����� �", (double)taxData[7], (bool)taxData[3] ? "���������" : "�� ���������",
                                    "����� �", (double)taxData[8], (bool)taxData[4] ? "���������" : "�� ���������");

                                value = taxData;
                            }
                            else
                                _infotext = "���� �����";

                            System.Windows.Forms.MessageBox.Show(_infotext, Protocol_Name,
                                System.Windows.Forms.MessageBoxButtons.OK,
                                System.Windows.Forms.MessageBoxIcon.Information);
                        }
                        str.Dispose();
                        break;
                    }
                case "SetSaleMode":
                    {
                        SetSaleMode ssm = new SetSaleMode(Protocol_Name, description);
                        if (ssm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            SetSaleMode(port, ssm.SaleMode);
                        ssm.Dispose();
                        break;
                    }
                case "SetSerialNum":
                    {
                        SetSerialNum ssm = new SetSerialNum(Protocol_Name, description);
                        if (ssm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            char r = SetSerialNum(port, ssm.CountryCode, ssm.SerialNumber);
                            string _infotext = string.Empty;

                            if (r == 'P')
                                _infotext = "������� �������� ������";
                            if (r == 'F')
                                _infotext = "��������������� �������� ������\r\n���������� ����� ��� �����������\r\n�� ����������� ����";
                            if (r == '\0')
                                _infotext = "���� ������ �� ��������";

                            System.Windows.Forms.MessageBox.Show(_infotext, Protocol_Name,
                                System.Windows.Forms.MessageBoxButtons.OK,
                                System.Windows.Forms.MessageBoxIcon.Information);
                        }
                        ssm.Dispose();
                        break;
                    }
                case "SetFixNum":
//.........这里部分代码省略.........
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:101,代码来源:fpmain.cs


示例4: SubTotal

 private double[] SubTotal(ComPort port, bool print, bool indicate, double disc, bool discmode)
 {
     return new double[0];
 }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:4,代码来源:fpmain.cs


示例5: SetTaxRate

        private object[] SetTaxRate(ComPort port, string pwd, byte dpoint, bool[] userates, double[] rates)
        {
            lastFuncName = "SetTaxRate";
            CMD = 83;

            //Creating data
            string _data = pwd + ',' + dpoint.ToString() + ',';
            foreach (bool a in userates)
                _data += a ? '1' : '0';
            foreach (double r in rates)
                _data += ',' + r.ToString(NumberFormat);

            DataForSend = Encoding.GetEncoding(1251).GetBytes(_data);

            //Preparing data
            InputData = CreateInputData(CMD, DataForSend);

            //Sending and reciving data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();

            // Perform processing recived data
            string _taxdata = Encoding.GetEncoding(1251).GetString(OutputData);
            object[] _taxInfo = new object[9];
            if (_taxdata.Length != 0)
            {
                string[] _trItems = _taxdata.Split(new char[] { ',' });
                _taxInfo[0] = byte.Parse(_trItems[0]);
                _taxInfo[1] = _trItems[1][0] == '1' ? true : false;
                _taxInfo[2] = _trItems[1][1] == '1' ? true : false; ;
                _taxInfo[3] = _trItems[1][2] == '1' ? true : false; ;
                _taxInfo[4] = _trItems[1][3] == '1' ? true : false; ;

                _taxInfo[5] = double.Parse(_trItems[2], NumberFormat);
                _taxInfo[6] = double.Parse(_trItems[3], NumberFormat);
                _taxInfo[7] = double.Parse(_trItems[4], NumberFormat);
                _taxInfo[8] = double.Parse(_trItems[5], NumberFormat);
            }

            return _taxInfo;
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:43,代码来源:fpmain.cs


示例6: SetSaleMode

        private void SetSaleMode(ComPort port, byte mode)
        {
            lastFuncName = "SetSaleMode";
            CMD = 84;

            //Creating data
            DataForSend = Encoding.GetEncoding(1251).GetBytes(mode.ToString());

            //Preparing data
            InputData = CreateInputData(CMD, DataForSend);

            //Sending and reciving data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:17,代码来源:fpmain.cs


示例7: SetGetArticle

        private string[] SetGetArticle(ComPort port, char option, object[] param)
        {
            lastFuncName = "SetGetArticle";
            CMD = 107;

            //Creating data
            string _data = option.ToString();
            if (!Methods.IsEmpty(param))
                for (int i = 0; i < param.Length; i++)
                    _data += param[i].ToString();

            DataForSend = Encoding.GetEncoding(1251).GetBytes(_data);

            //Preparing data
            InputData = CreateInputData(CMD, DataForSend);

            //Sending and reciving data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();

            //Perform processing recived data
            string _art = Encoding.GetEncoding(1251).GetString(OutputData);
            string[] artInfo = new string[0];

            if (_art.Length != 0)
                artInfo = _art.Split(new char[1] { ',' });

            return artInfo;
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:31,代码来源:fpmain.cs


示例8: SendGetData

        private bool SendGetData(ComPort port, int totRead, bool close)
        {
            string exceptionMsg = "";

            if (!port.IsOpen)
                try
                {
                    port.Open();
                }
                catch { }

            if (port.IsOpen && port.Write(InputData))
            {
                //WinAPI.OutputDebugString("W");

                int t = totRead;
                byte[] buffer = new byte[512];
                OutputData = new byte[0];
                do
                {
                    Array.Clear(buffer, 0, buffer.Length);
                    //WinAPI.OutputDebugString("R");
                    if (port.Read(ref buffer, out ReadedBytes))
                    {
                        Array.Resize<byte>(ref OutputData, (int)(OutputData.Length + ReadedBytes));
                        Array.Copy(buffer, 0, OutputData, OutputData.Length - ReadedBytes, ReadedBytes);
                        try
                        {
                            //WinAPI.OutputDebugString("D");
                            switch (DecodeAnswer())
                            {
                                case "busy":
                                    {
                                        //WinAPI.OutputDebugString("S");
                                        Thread.Sleep(200);
                                        break;
                                    }
                                case "true":
                                    {
                                        //WinAPI.OutputDebugString("T");
                                        ErrorFlags[lastFuncName] = false;
                                        return true;
                                    }
                                case "false":
                                    {
                                        //WinAPI.OutputDebugString("F");
                                        t--;
                                        Thread.Sleep(50);
                                        break;
                                    }
                                case "failed":
                                    {
                                        throw new Exception("������� ��������� ������� \"" + lastFuncName + "\"");
                                    }
                            }
                        }
                        catch (Exception ex)
                        {
                            exceptionMsg = "\r\n" + ex.Message;
                            break;
                        }
                    }
                    else
                        break;

                } while (t > 0);
                //WinAPI.OutputDebugString("E");
            }

            if (close)
                port.Close();

            ErrorFlags[lastFuncName] = true;
            throw new Exception("������� ������� � ���������� ��������" + " " + Protocol_Name + exceptionMsg);
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:75,代码来源:fpmain.cs


示例9: PrintCopy

        private void PrintCopy(ComPort port, byte copies)
        {
            lastFuncName = "PrintCopy";
            CMD = 109;

            //Creating data
            if (copies > 1)
            {
                DataForSend = new byte[1];
                DataForSend[0] = (byte)(copies + 0x30);
            }
            else
                DataForSend = new byte[0];
            InputData = CreateInputData(CMD, DataForSend);

            //sending and getting data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:21,代码来源:fpmain.cs


示例10: OpenNOrder

        private ushort[] OpenNOrder(ComPort port)
        {
            lastFuncName = "OpenNOrder";
            CMD = 38;

            //Making data
            InputData = CreateInputData(CMD, new byte[0]);

            //sending and getting data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();

            // Perform processing recived data
            string _noinfo = Encoding.GetEncoding(1251).GetString(OutputData);
            ushort[] _noinf = new ushort[4];
            if (_noinfo.Length != 0)
            {
                string[] _noItems = _noinfo.Split(new char[1] { ',' });
                _noinf[0] = ushort.Parse(_noItems[0]);
                _noinf[1] = ushort.Parse(_noItems[1]);
                _noinf[2] = ushort.Parse(_noItems[2]);
                if (_noItems.Length == 4)
                    _noinf[3] = ushort.Parse(_noItems[3]);
            }
            return _noinf;
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:28,代码来源:fpmain.cs


示例11: OpenFOrder

 private ushort[] OpenFOrder(ComPort port, byte uid, string pwd, byte cdno, bool extended)
 {
     return new ushort[0];
 }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:4,代码来源:fpmain.cs


示例12: OpenBox

        private void OpenBox(ComPort port, byte impulse)
        {
            lastFuncName = "OpenBox";
            CMD = 106;

            if (impulse != 0)
                DataForSend = Encoding.GetEncoding(1251).GetBytes(impulse.ToString());
            else
                DataForSend = new byte[0];

            //Making data
            InputData = CreateInputData(CMD, DataForSend);

            //sending and getting data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:19,代码来源:fpmain.cs


示例13: LoadLogo

        private void LoadLogo(ComPort port, string pwd, byte[][] logo)
        {
            lastFuncName = "LoadLogo";
            CMD = 115;

            byte _wCorr = 0;
            if (logo[0].Length < 54)
                _wCorr += (byte)(54 - logo[0].Length);
            byte[] _predata = new byte[0];
            for (int _r = 0; _r < logo.Length; _r++)
            {
                //Creating data
                _predata = Encoding.GetEncoding(1251).GetBytes(pwd + ',' + _r + ',');

                DataForSend = new byte[_predata.Length + logo[_r].Length + _wCorr];
                Array.Copy(_predata, 0, DataForSend, 0, _predata.Length);
                Array.Copy(logo[_r], 0, DataForSend, _predata.Length, logo[_r].Length);

                //Preparing data
                InputData = CreateInputData(CMD, DataForSend);

                //Sending and reciving data
                SendGetData(port, 20, true);

                //Next code for command
                GetNextCmdCode();
            }
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:28,代码来源:fpmain.cs


示例14: LineFeed

        private void LineFeed(ComPort port, byte lines)
        {
            lastFuncName = "LineFeed";
            CMD = 44;

            DataForSend = Encoding.GetEncoding(1251).GetBytes(lines.ToString());

            //Making data
            InputData = CreateInputData(CMD, DataForSend);

            //sending and getting data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:16,代码来源:fpmain.cs


示例15: GetUserInfo

        private object[] GetUserInfo(ComPort port, byte uid)
        {
            lastFuncName = "GetUserInfo";
            CMD = 112;

            DataForSend = Encoding.GetEncoding(1251).GetBytes(uid.ToString());

            //Making data
            InputData = CreateInputData(CMD, DataForSend);

            //sending and getting data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();

            // Perform processing recived data
            object[] _user = new object[12];
            string _userInfo = Encoding.GetEncoding(1251).GetString(OutputData);
            if (_userInfo.Length != 0)
            {//0, 0;0.00, 0;0.00, 0;0.00, 0;0.00, 0;0.00, gfdgfdgfd
                string[] _userItems = _userInfo.Split(new char[2] { ',', ';' });
                _user[0] = uint.Parse(_userItems[0]);
                _user[1] = uint.Parse(_userItems[1]);
                _user[2] = double.Parse(_userItems[2], NumberFormat);
                _user[3] = uint.Parse(_userItems[3]);
                _user[4] = double.Parse(_userItems[4], NumberFormat);
                _user[5] = uint.Parse(_userItems[5]);
                _user[6] = double.Parse(_userItems[6], NumberFormat);
                _user[7] = uint.Parse(_userItems[7]);
                _user[8] = double.Parse(_userItems[8], NumberFormat);
                _user[9] = uint.Parse(_userItems[9]);
                _user[10] = double.Parse(_userItems[10], NumberFormat);
                _user[11] = _userItems[11];
            }

            return _user;
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:38,代码来源:fpmain.cs


示例16: ResetOrder

        private void ResetOrder(ComPort port)
        {
            lastFuncName = "ResetOrder";
            CMD = 57;

            //Making data
            InputData = CreateInputData(CMD, new byte[0]);

            //sending and getting data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:14,代码来源:fpmain.cs


示例17: SaleArtIndicate

 private void SaleArtIndicate(ComPort port, char sign, uint artno, uint tot, double nprice, double disc, bool discmode)
 {
 }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:3,代码来源:fpmain.cs


示例18: PrintDiagInfo

        private void PrintDiagInfo(ComPort port)
        {
            lastFuncName = "PrintDiagInfo";
            CMD = 71;

            //Preparing data
            InputData = CreateInputData(CMD, new byte[0]);

            //Sending and reciving data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:14,代码来源:fpmain.cs


示例19: SetDateTime

        private void SetDateTime(ComPort port, DateTime dt)
        {
            lastFuncName = "SetDateTime";
            CMD = 61;

            //Creating data
            DataForSend = Encoding.GetEncoding(1251).GetBytes(dt.ToString("dd-MM-yy HH:mm:ss"));

            //Preparing data
            InputData = CreateInputData(CMD, DataForSend);

            //Sending and reciving data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:17,代码来源:fpmain.cs


示例20: PrintNText

        private void PrintNText(ComPort port, string ntext)
        {
            lastFuncName = "PrintNText";
            CMD = 42;

            //Creating data
            ntext = ntext.Replace('�', 'i').Replace('�', 'I');
            DataForSend = Encoding.GetEncoding(1251).GetBytes(ntext);

            //Preparing data
            InputData = CreateInputData(CMD, DataForSend);

            //sending and getting data
            SendGetData(port, 20, true);

            //Next code for command
            GetNextCmdCode();
        }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:18,代码来源:fpmain.cs



注:本文中的ComPort类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ComPtr类代码示例发布时间:2022-05-24
下一篇:
C# Columns类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap