Example #1
0
        private void ProcessData(string cmd)
        {
            try
            {
                CDM1Unit unit = (CDM1Unit)ECardDevice.CreateDeviceUnit(cmd);


                CDM1Device device = new CDM1Device();
                CDM1Unit   ret    = device.SendCommand(unit);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
Example #2
0
        private bool openWebSokcet()
        {
            try
            {
                allSockets = new List <IWebSocketConnection>();

                webSocketServer = new WebSocketServer("ws://0.0.0.0:" + _workSpace.ListenPort.ToString());

                webSocketServer.Start(socket =>
                {
                    //接收线程创建
                    socket.OnOpen = () =>
                    {
                        ShowCustInfoPro(socket.ConnectionInfo.ClientIpAddress.ToString() + "已连接");

                        if (allSockets.Count >= 1)
                        {
                            return;
                        }
                        ShowClientLinkInfo(socket.ConnectionInfo.ClientIpAddress.ToString());
                        allSockets.Add(socket);
                    };
                    //线程关闭
                    socket.OnClose = () =>
                    {
                        ShowCustInfoPro(socket.ConnectionInfo.ClientIpAddress.ToString() + "已断开");

                        allSockets.Remove(socket);

                        ShowClientLinkInfo(String.Empty);
                    };
                    socket.OnMessage = message =>
                    {
                        CmdUnit unit = ECardDevice.CreateDeviceUnit(message);

                        switch (unit.Type)
                        {
                        case (int)CDDeviceType.DCD10:

                            ProcessDeviceDCD10Command(allSockets[0], unit);

                            break;

                        case (int)CDDeviceType.CD_M1:
                            ProcessDeviceCDM1Command(allSockets[0], unit);

                            break;

                        default:
                            break;
                        }
                    };
                });


                ShowCustInfoPro("服务已开启");

                return(true);
            }
            catch
            {
                throw;
            }
        }