private void dataRecive(EventProgram ev)
        {
            switch (ev.Action)
            {
            case ActionTicket.MESSAGE_ERROR:
                SendKeyBoard(ev);
                break;

            default:
                DataReceived(ev); break;
            }
        }
示例#2
0
        void comSendWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (!comSendWorker.CancellationPending && checkQueue())
            {
                mRecive.WaitOne();
                var data = queueRecive.Dequeue();
                mRecive.ReleaseMutex();
                // nhận data từ bàn phím xử lý gọi lên socket
                var resBytes = CheckByteSend.getByteSendList(data, dicCounterKeyboard);
                if (resBytes != null && resBytes.Count() > 0)
                {
                    foreach (var resByte in resBytes)
                    {
                        string idCounter = "";
                        idCounter = dicCounterKeyboard[resByte.AddressKey].CounterID;

                        switch (resByte.DeviceId)
                        {
                        case (int)CheckByteSend.DEVICE_ID.DEVICE_KEYBOARD:

                            if (dicCounterKeyboard.ContainsKey(resByte.AddressKey))
                            {
                                var    arrAcNum    = CheckByteSend.GetActionByCommand(resByte.Command, resByte.Cnum, resByte.NumServicesOrCounter, idCounter, dicService, dicCounter);
                                string action      = arrAcNum[0];
                                string counterMove = arrAcNum[1];
                                string serviceMove = arrAcNum[2];
                                string cNumMove    = arrAcNum[3];

                                if (action == null && string.IsNullOrWhiteSpace(counterMove) && string.IsNullOrWhiteSpace(serviceMove) && string.IsNullOrWhiteSpace(cNumMove))
                                {
                                    Console.WriteLine("Lỗi Send Action: " + MessageError.ERROR_08);
                                    EventProgram ev = new EventProgram(ActionTicket.MESSAGE_ERROR, resByte.AddressKey, idCounter, MessageError.ERROR_08, 0);
                                    DataReceived(ev);
                                }
                                else if (!string.IsNullOrWhiteSpace(action))
                                {
                                    List <string> lstCou = new List <string>();
                                    List <string> lstSer = new List <string>();

                                    if (!string.IsNullOrWhiteSpace(counterMove))
                                    {
                                        lstCou = new List <string> {
                                            counterMove
                                        };
                                    }
                                    else if (!string.IsNullOrWhiteSpace(serviceMove))
                                    {
                                        lstSer = new List <string> {
                                            serviceMove
                                        };
                                    }
                                    //string action, int add, string couterID, string cNum, int indexSer
                                    EventProgram ev = new EventProgram(action, idCounter, cNumMove, lstCou, lstSer);
                                    DataReceived(ev);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Khong ton tai dia chi nay!");
                            } break;

                        case (int)CheckByteSend.DEVICE_ID.DEVICE_FEED_BACK:
                            var resByteRecive = dicCounterKeyboard.Values.FirstOrDefault(m => m.AddressFeedBack == resByte.AddressKey);
                            if (resByteRecive != null)
                            {
                                var rating = CheckByteSend.GetRatingByCommand(resByte.Command);
                                if (rating != 0)
                                {
                                    EventProgram ev = new EventProgram(ActionTicket.RATING_ONCE, resByteRecive.CounterID, rating);
                                    DataReceived(ev);
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }
        public void SendKeyBoard(EventProgram eventData)
        {
            string action  = eventData.Action;
            int    command = 0;

            switch (action)
            {
            case ActionTicket.INITIAL_SER:
                // nạp service
                var byteService = modBus.SetService(0, eventData.LstServices);
                serialPort.SendData(byteService);
                return;

            case ActionTicket.INITIAL_COU:
                // nạp counter
                //var byteCounter = modBus.SetCounter(0, "Quầy/Counter", eventData.LstCounter, 0);
                var byteCounter = modBus.SetCounter(0, "Quầy/ Counter", eventData.LstAllCounter, eventData.DicAddKey);
                serialPort.SendData(byteCounter);
                break;

            case ActionTicket.ACTION_RESET:
                //reset
                var byteset = modBus.BuildText(DEVICE_KEYBOARD, 0, (int)CheckByteSend.BYTE_COMMAND.RESET_COUNTER, "", -1);
                serialPort.SendData(byteset);
                return;

            case "call_hst":
                command = (int)CheckByteSend.BYTE_COMMAND.NEXT_COMMAND;
                break;

            case ActionTicket.ACTION_ALL_RESTORE:
                command = (int)CheckByteSend.BYTE_COMMAND.RESTORE_COMMAND;
                var byteRestore = modBus.BuildTextAllRetore(DEVICE_KEYBOARD, eventData.Address, command, eventData.LstTicket, eventData.DicService);
                serialPort.SendData(byteRestore);
                return;

            case ActionTicket.CALL_LIST_WATTING:
                command = (int)CheckByteSend.BYTE_COMMAND.CALL_LIST_WATTING;
                var byteCall = modBus.BuildTextAllRetore(DEVICE_KEYBOARD, eventData.Address, command, eventData.LstTicket, eventData.DicService);
                serialPort.SendData(byteCall);
                return;

            case ActionTicket.ACTION_CALL:
                command = (int)CheckByteSend.BYTE_COMMAND.NEXT_COMMAND;
                break;

            case ActionTicket.ACTION_RECALL:
                command = (int)CheckByteSend.BYTE_COMMAND.RECALL_COMMAND;
                break;

            case ActionTicket.ACTION_CANCEL:
                command = (int)CheckByteSend.BYTE_COMMAND.DELETE_COMMAND;
                break;

            case ActionTicket.ACTION_CONNECT_COUNTER: command = (int)CheckByteSend.BYTE_COMMAND.NEXT_COMMAND; break;

            case ActionTicket.ACTION_CREATE: break;

            case ActionTicket.ACTION_FEEDBACK: break;

            case ActionTicket.ACTION_FINISH: command = (int)CheckByteSend.BYTE_COMMAND.FINISH_COMMAND; break;

            case ActionTicket.ACTION_MOVE_COUNTER:
                command = (int)CheckByteSend.BYTE_COMMAND.FORWARD_COMMAND_COUNTER;
                break;

            case ActionTicket.ACTION_MOVE_SERVICE:
                command = (int)CheckByteSend.BYTE_COMMAND.FORWARD_COMMAND_SERVICE;
                break;

            case ActionTicket.ACTION_RATING: break;

            case ActionTicket.ACTION_RESET_COUNTER: command = (int)CheckByteSend.BYTE_COMMAND.NEXT_COMMAND; break;

            case ActionTicket.ACTION_RESTORE:
                command = (int)CheckByteSend.BYTE_COMMAND.CALLSTORE_COMMAND;
                break;

            case ActionTicket.MESSAGE_ERROR:
                serialPortError(eventData.CNum, eventData.Address); return;

            case ActionTicket.CALL_PRIORITY: break;

            case ActionTicket.CONNECT:
                serialPortError(MessageError.ERROR_06, eventData.Address);
                return;

            case ActionTicket.DISCONNECT:
                serialPortError(MessageError.ERROR_07, eventData.Address);
                return;

            case ActionTicket.ERROR_SERVER: break;

            case ActionTicket.OPEN_SERVER: break;

            case ActionTicket.RATING_ONCE: break;

            //case ActionTicket.RELOAD: break;
            default: break;
            }
            var byteRst = modBus.BuildText(DEVICE_KEYBOARD, eventData.Address, command, eventData.CNum, eventData.IndexService);

            serialPort.SendData(byteRst);
        }