예제 #1
0
파일: Viper.cs 프로젝트: Osceus/Cobra
 protected void OnNewViperReadError(ViperReadException exception)
 {
     if (this.NewReadException != null)
     {
         this.NewReadException(exception);
     }
 }
예제 #2
0
 private void ViperNode_NewReadException(ViperReadException ex)
 {
     OnNewComError(ex.Message);
 }
예제 #3
0
 protected override void processMessage(char header)
 {
     try
     {
         byte[] message;
         switch (header)
         {
             case GET_COMMUNICATION_CHANNEL:
                 message = readGetMessage(GET_COMMUNICATION_CHANNEL);
                 OnNewCommunicationChannel((int)(byte)message[0]);
                 break;
             case SET_COMMUNICATION_CHANNEL:
                 confirmCheckSumSet(SET_COMMUNICATION_CHANNEL);
                 break;
             case GET_NODE_NUMBER:
                 message = readGetMessage(GET_NODE_NUMBER);
                 OnNewNodeNumber((int)BitConverter.ToInt16(message, 0));
                 break;
             case SET_NODE_NUMBER:
                 confirmCheckSumSet(SET_NODE_NUMBER);
                 break;
             case GET_FILTER_VALUE:
                 message = readGetMessage(GET_FILTER_VALUE);
                 OnNewFilterValue((int)(byte)message[0]);
                 break;
             case SET_FILTER_VALUE:
                 confirmCheckSumSet(SET_FILTER_VALUE);
                 break;
             case GET_PACK_NUMBER:
                 message = readGetMessage(GET_PACK_NUMBER);
                 OnNewPackNumber((int)(byte)message[0]);
                 break;
             case SET_PACK_NUMBER:
                 confirmCheckSumSet(SET_PACK_NUMBER);
                 break;
             case GET_CELL_GAIN:
                 message = readGetMessage(GET_CELL_GAIN);
                 OnNewCellGain(((int)BitConverter.ToUInt16(message, 0)));
                 break;
             case SET_CELL_GAIN:
                 confirmCheckSumSet(SET_CELL_GAIN);
                 break;
             case GET_CELL_OFFSET:
                 message = readGetMessage(GET_CELL_OFFSET);
                 OnNewCellOffset((int)BitConverter.ToInt16(message, 0));
                 break;
             case SET_CELL_OFFSET:
                 confirmCheckSumSet(SET_CELL_OFFSET);
                 break;
             case GET_SERIAL_NUMBER:
                 message = readGetMessage(GET_SERIAL_NUMBER);
                 OnNewSerialNumber(getAsciiString(message));
                 break;
             case SET_SERIAL_NUMBER:
                 confirmCheckSumSet(SET_SERIAL_NUMBER);
                 break;
             case GET_PART_NUMBER:
                 message = readGetMessage(GET_PART_NUMBER);
                 OnNewPartNumber(getAsciiString(message));
                 break;
             case SET_PART_NUMBER:
                 confirmCheckSumSet(SET_PART_NUMBER);
                 break;
             case GET_MAC_ADDRESS:
                 message = readGetMessage(GET_MAC_ADDRESS);
                 OnNewMacAddress(new MacAddress(message));
                 break;
             case GET_CELL_CALIBRATED:
                 message = readGetMessage(GET_CELL_CALIBRATED);
                 OnNewCellCalibrated((int)BitConverter.ToUInt16(message, 0));
                 break;
             case GET_COMMAND_NIBBLE:
                 handleNibbleMessage();
                 break;
             case SET_COMMAND_NIBBLE:
                 confirmCheckSumSet(SET_COMMAND_NIBBLE);
                 break;
             case GET_NODE_STATUS:
                 handleStatusMessage();
                 break;
             case GET_NODE_VOLTAGE:
                 handleVoltageMessage();
                 break;
             case GET_SOFTWARE_REVISION:
                 message = readGetMessage(GET_SOFTWARE_REVISION);
                 OnNewSoftwareRevision(new SoftwareRevision((int)message[0], (int)message[1]));
                 break;
             case SET_MASTER_SCALER:
                 confirmCheckSumSet(SET_MASTER_SCALER);
                 break;
             case GET_MASTER_SCALER:
                 message = readGetMessage(GET_MASTER_SCALER);
                 OnNewMasterScaler((double)BitConverter.ToSingle(message, 0));
                 break;
             case GET_NUMBER_OF_NODES:
                 message = readGetMessage(GET_NUMBER_OF_NODES);
                 OnNewNumberOfNodes((int)BitConverter.ToInt16(message, 0));
                 break;
             case SET_NUMBER_OF_NODES:
                 confirmCheckSumSet(SET_NUMBER_OF_NODES);
                 break;
             default:
                 ViperReadException vre = new ViperReadException("Unknown Message From Viper: " + header.ToString());
                 OnNewViperReadError(vre);
                 break;
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Error parsing command. Header: " + header.ToString(), ex);
     }
 }