Пример #1
0
        private static void ReciveDataSocket(EventSocketSendProgram eventData)
        {
            int command = 0;

            switch (eventData.Action)
            {
            case ActionTicket.INITIAL:
                if (dicCounter.Count() == 0 && dicService.Count() == 0)
                {
                    InitKeyBoardSend(eventData.DicCounter, eventData.DicService);
                }
                return;

            case ActionTicket.ACTION_CREATE:    // không làm gì
                break;

            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_RESTORE:
                command = (int)CheckByteSend.BYTE_COMMAND.RESTORE_COMMAND;
                break;

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

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

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

            default:
                //bug
                break;
            }

            if (eventData.ObjSend != null)
            {
                string counterID    = eventData.ObjSend.counter_id;
                int    indexService = getIndexService(eventData.ObjSend.service_id, counterID);
                if (indexService != -1)
                {
                    string data    = eventData.ObjSend.cnum;
                    var    address = dicCounterKeyboard.FirstOrDefault(d => d.Value.CounterID == counterID).Key;
                    if (address > 0)
                    {
                        var byteRes = modBus.BuildText(ActionTicket.DEVICE_ID, address, command, data, indexService);
                        serialPort.SendData(byteRes);
                    }
                    else
                    {
                        //bug
                    }
                }
                else
                {
                    //truyền lỗi xuống port
                }
            }
            resByte = null;
        }
Пример #2
0
 public void SerialPortPing(Dictionary <int, KeyBoardCounter> dicCounterKeyboard)
 {
     if (serialPort.openPort())
     {
         byte[] byteRes = modBus.BuildText(DEVICE_KEYBOARD, dicCounterKeyboard.Values.ToArray()[0].AddressKeyboard, (int)CheckByteSend.BYTE_COMMAND.STATUS_COMMAND, "", 1);
         serialPort.SendData(byteRes);
     }
 }