예제 #1
0
        public void GetOperatingParameters(ref Dictionary <LinacPacketFormat.VariableIdEnum, object> parameterList)
        {
            Array values = Enum.GetValues(typeof(LinacPacketFormat.VariableIdEnum));

            LinacPacketFormat.CommandPacket command = new LinacPacketFormat.CommandPacket(LinacPacketFormat.CommandEnum.Read, LinacPacketFormat.TypeEnum.Query);
            command.Size = 1;

            LinacPacketFormat.DataPacket data = new LinacPacketFormat.DataPacket();
            data.variableId = LinacPacketFormat.VariableIdEnum.OperatingParameters;
            data.dataType   = LinacPacketFormat.DataTypeEnum.None;

            try
            {
                List <LinacPacketFormat.DataPacket> response = SendCommand(command, data, true);
            }
            catch (Exception e)
            {
            }
            //Console.WriteLine(String.Format("{0}: {1}", data.variableId, data.dataType )); // For Debugging
        }
예제 #2
0
        public void GetOperatingParameters(ref Dictionary<LinacPacketFormat.VariableIdEnum, object> parameterList)
        {
            Array values = Enum.GetValues(typeof(LinacPacketFormat.VariableIdEnum));
                
            LinacPacketFormat.CommandPacket command = new LinacPacketFormat.CommandPacket(LinacPacketFormat.CommandEnum.Read, LinacPacketFormat.TypeEnum.Query);
            command.Size = 1;

            LinacPacketFormat.DataPacket data = new LinacPacketFormat.DataPacket();
            data.variableId = LinacPacketFormat.VariableIdEnum.OperatingParameters;
            data.dataType = LinacPacketFormat.DataTypeEnum.None;

            try
            {
                List<LinacPacketFormat.DataPacket> response = SendCommand(command, data, true);
            }
            catch (Exception e)
            {
            }
            //Console.WriteLine(String.Format("{0}: {1}", data.variableId, data.dataType )); // For Debugging

        }
예제 #3
0
        private void ProcessCommand(byte[] cmd, int size)
        {
            LinacPacketFormat.CommandPacket command = new LinacPacketFormat.CommandPacket();
            command = command.Deserialize(cmd);

            int dataLength = Marshal.SizeOf(typeof(LinacPacketFormat.DataPacket));
            byte[] data = new byte[dataLength];
            int dataRead = 0;

            if (command.Command == LinacPacketFormat.CommandEnum.Ping)
            {
                _pingAckReceived = true;
            }
            else if (command.Command == LinacPacketFormat.CommandEnum.Unsolicited)
            {
                Dictionary<LinacPacketFormat.VariableIdEnum, object> commandList = new Dictionary<LinacPacketFormat.VariableIdEnum, object>();
                object dataValue;

                for (int packetNum = 0; packetNum < command.Size; packetNum++)
                {
                    //number of packets following command packet
                    dataRead = _networkStream.Read(data, 0, data.Length);

                    //deserialize data packet
                    LinacPacketFormat.DataPacket dataPacket = new LinacPacketFormat.DataPacket();
                    dataPacket = dataPacket.Deserialize(data);
                    
                    if (dataPacket.dataType == LinacPacketFormat.DataTypeEnum.Decimal)
                    {
                        dataValue = BitConverter.ToUInt32(dataPacket.data, 0);
                    }
                    else if (dataPacket.dataType == LinacPacketFormat.DataTypeEnum.Float)
                    {
                        dataValue = BitConverter.ToSingle(dataPacket.data, 0);
                    }
                    else //string
                    {
                        dataValue = BitConverter.ToString(dataPacket.data);
                    }

                    commandList.Add(dataPacket.variableId, dataValue);
                }

                if (ProcessCommandEvent != null)
                    ProcessCommandEvent(commandList);
            }
            else
            {

                Dictionary<LinacPacketFormat.VariableIdEnum, object> commandList = new Dictionary<LinacPacketFormat.VariableIdEnum, object>();

                for (int packetNum = 0; packetNum < command.Size; packetNum++)
                {
                    //number of packets following command packet
                    dataRead = _networkStream.Read(data, 0, data.Length);

                    //deserialize data packet
                    LinacPacketFormat.DataPacket dataPacket = new LinacPacketFormat.DataPacket();
                    dataPacket = dataPacket.Deserialize(data);

                    commandList.Add(dataPacket.variableId, dataPacket.data);
                }


                if (ProcessCommandEvent != null)
                    ProcessCommandEvent(commandList);
                

                if (!_commandResponseEvent.Set())
                {
                    _logger.LogError("setting _commandResponseEvent returned false", new StackTrace(true));
                }
            }
        }
예제 #4
0
        private List <LinacPacketFormat.DataPacket> SendCommand(LinacPacketFormat.CommandPacket command, LinacPacketFormat.DataPacket data, bool expectingReply)
        {
            List <LinacPacketFormat.DataPacket> receiveData;

            byte[] commandbuffer = command.Serialize();

            _networkStream.Write(commandbuffer, 0, commandbuffer.Length);

            byte[] databuffer = data.Serialize();

            _commandResponseList.Clear();

            _networkStream.Write(databuffer, 0, databuffer.Length);

            if (expectingReply)
            {
                //wait for response
                if (_commandResponseEvent.WaitOne(2000))
                {
                    receiveData = _commandResponseList;
                }
                else
                {
                    receiveData = null;
                }
            }
            else
            {
                throw new Exception("Host not connected");
            }

            return(receiveData);
        }
예제 #5
0
        private void ProcessCommand(byte[] cmd, int size)
        {
            LinacPacketFormat.CommandPacket command = new LinacPacketFormat.CommandPacket();
            command = command.Deserialize(cmd);

            int dataLength = Marshal.SizeOf(typeof(LinacPacketFormat.DataPacket));

            byte[] data     = new byte[dataLength];
            int    dataRead = 0;

            if (command.Command == LinacPacketFormat.CommandEnum.Ping)
            {
                _pingAckReceived = true;
            }
            else if (command.Command == LinacPacketFormat.CommandEnum.Unsolicited)
            {
                Dictionary <LinacPacketFormat.VariableIdEnum, object> commandList = new Dictionary <LinacPacketFormat.VariableIdEnum, object>();
                object dataValue;

                for (int packetNum = 0; packetNum < command.Size; packetNum++)
                {
                    //number of packets following command packet
                    dataRead = _networkStream.Read(data, 0, data.Length);

                    //deserialize data packet
                    LinacPacketFormat.DataPacket dataPacket = new LinacPacketFormat.DataPacket();
                    dataPacket = dataPacket.Deserialize(data);

                    if (dataPacket.dataType == LinacPacketFormat.DataTypeEnum.Decimal)
                    {
                        dataValue = BitConverter.ToUInt32(dataPacket.data, 0);
                    }
                    else if (dataPacket.dataType == LinacPacketFormat.DataTypeEnum.Float)
                    {
                        dataValue = BitConverter.ToSingle(dataPacket.data, 0);
                    }
                    else //string
                    {
                        dataValue = BitConverter.ToString(dataPacket.data);
                    }

                    commandList.Add(dataPacket.variableId, dataValue);
                }

                if (ProcessCommandEvent != null)
                {
                    ProcessCommandEvent(commandList);
                }
            }
            else
            {
                Dictionary <LinacPacketFormat.VariableIdEnum, object> commandList = new Dictionary <LinacPacketFormat.VariableIdEnum, object>();

                for (int packetNum = 0; packetNum < command.Size; packetNum++)
                {
                    //number of packets following command packet
                    dataRead = _networkStream.Read(data, 0, data.Length);

                    //deserialize data packet
                    LinacPacketFormat.DataPacket dataPacket = new LinacPacketFormat.DataPacket();
                    dataPacket = dataPacket.Deserialize(data);

                    commandList.Add(dataPacket.variableId, dataPacket.data);
                }


                if (ProcessCommandEvent != null)
                {
                    ProcessCommandEvent(commandList);
                }


                if (!_commandResponseEvent.Set())
                {
                    _logger.LogError("setting _commandResponseEvent returned false", new StackTrace(true));
                }
            }
        }