Esempio n. 1
0
File: mcp.cs Progetto: youthv/MCSo
 // ====================================================================================
 public int Open()
 {
     DoConnect();
     Command = new McCommand(CommandFrame);
     Command.SetChannelNumber(appcn);
     return(0);
 }
Esempio n. 2
0
        public bool SetASCIIString(string ASCIIString, bool reverse)
        {
            bool isOk = !string.IsNullOrWhiteSpace(ASCIIString);

            if (isOk)
            {
                this.RawValue = McCommand.ASCIIStringToShortArray(ASCIIString, reverse);
            }
            return(isOk);
        }
Esempio n. 3
0
        public bool GetDInput(int address, ref short[] state)
        {
            bool isOk = false;

            if (address >= 0 && this.InputDAddress >= 0 && this.InputDCount > 0)
            {
                this.updateInputBuffer_D();

                int index = address - this.InputDAddress;
                if (this.inputBuffer_D != null && this.inputBuffer_D.Length > index)
                {
                    string strdata = McCommand.ShortArrayToASCIIString(false, inputBuffer_D);
                    state = McCommand.ASCIIStringToShortArray(strdata, false);
                    isOk  = true;
                }
            }
            return(isOk);
        }
Esempio n. 4
0
        private void read()
        {
            if (mcProtocol == null || !mcProtocol.IsConnected)
            {
                return;
            }

            short[] readData = new short[1];
            var     rtn      = mcProtocol.ExecuteRead("D", 1000, 10, ref readData);

            if (rtn != 0)
            {
                Console.WriteLine("Error code: " + rtn);
            }
            else
            {
                Console.WriteLine("Read success.");
                // Data format convert. All convert function in McCommand
                string strData    = McCommand.ShortArrayToASCIIString(false, readData[0]);
                string intDataStr = McCommand.ShortArrayToInt16String(readData[1]);
            }
        }
Esempio n. 5
0
        private void write()
        {
            if (mcProtocol == null || !mcProtocol.IsConnected)
            {
                return;
            }

            short[] writeData = McCommand.Int16StringToShortArray("1");

            // 1 word = 16 bit = 2 character
            //short[] writeData = McCommand.ASCIIStringToShortArray("HI");

            int rtn = mcProtocol.ExecuteWrite("D", 1000, 1, writeData);

            if (rtn != 0)
            {
                Console.WriteLine("Error code: " + rtn);
            }
            else
            {
                Console.WriteLine("Write success.");
            }
        }
Esempio n. 6
0
 // ====================================================================================
 public int Open()
 {
     DoConnect();
     Command = new McCommand(CommandFrame);
     return(0);
 }
Esempio n. 7
0
        internal List <McCommander> GetCommanders(int[] ids)
        {
            List <McCommander> commanderList = new List <McCommander>();

            #region Commanders
            foreach (var item in McDbCommunication.ReadCommanders(ids))
            {
                commanderList.Add(item);
            }
            #endregion

            foreach (var item in commanderList)
            {
                #region Leadership Role
                if (item.leadershipRoleId < 1)
                {
                    item.LeadershipRole = null;
                }
                else
                {
                    item.LeadershipRole = GetLeadershipRoles(new int[1] {
                        item.leadershipRoleId
                    })[0];
                }
                #endregion

                #region Commands
                List <McCommand> commandList = new List <McCommand>();
                commandList.AddRange(GetCommands(McDbCommunication.ReadCommandIdsToCommander(item.Id)));

                if (item.LeadershipRole != null)
                {
                    bool      duplicate = false;
                    McCommand lrCommand = GetCommands(new int[1] {
                        item.LeadershipRole.CommandId
                    })[0];

                    foreach (McCommand command in commandList)
                    {
                        if (command.Id == lrCommand.Id)
                        {
                            duplicate = true;
                            break;
                        }
                    }

                    if (!duplicate)
                    {
                        commandList.Add(lrCommand);
                    }
                }

                commandList.OrderBy(x => x.Name);

                item.CommandList = commandList;
                #endregion

                #region Faction
                if (item.factionId < 1)
                {
                    item.Faction = null;
                }
                else
                {
                    item.Faction = GetFactions(new int[1] {
                        item.factionId
                    })[0];
                }
                #endregion

                #region Leadership Score
                int leadershipScore = Math.Max(item.hitDice, item.professionSoldier);

                leadershipScore += item.mentalAbility;

                if (item.isCouncilPosition || item.LeadershipRole.MainDepartment)
                {
                    leadershipScore += 5;
                }
                else if (item.LeadershipRole != null)
                {
                    leadershipScore += 3;
                }

                if (item.isFeatLeadership)
                {
                    leadershipScore += 3;
                }

                if (item.LeadershipRole.Id == 1 || item.LeadershipRole.Id == 2 || item.LeadershipRole.Id == 3 || item.LeadershipRole.Id == 4 || item.LeadershipRole.Id == 5 || item.LeadershipRole.Id == 6 || item.LeadershipRole.Id == 14 || item.LeadershipRole.Id == 21)
                {
                    leadershipScore += 1;
                }

                leadershipScore += item.bonusLeadership;

                item.LeadershipScore = leadershipScore;
                #endregion
            }

            commanderList.OrderBy(x => x.Name);

            return(commanderList);
        }
Esempio n. 8
0
 public string GetASCIIString(bool reverse)
 {
     return(McCommand.ShortArrayToASCIIString(reverse, this.RawValue));
 }