Exemplo n.º 1
0
        public static void WriteByte(byte register, byte value)
        {
            byte[] regAddr = new byte[] { register, value };
            int    ret     = SystemImports.Write(I2C_BUS_HANDLE, regAddr, regAddr.Length);

            if (ret < 0)
            {
                throw new Exception("Error writing to the I2C bus!");
            }
        }
Exemplo n.º 2
0
        public static void OpenBus(string busname)
        {
            I2C_BUS_HANDLE = SystemImports.Open(busname, I2C_OPEN_READ_WRITE);
            if (I2C_BUS_HANDLE < 0)
            {
                throw new Exception("Cannot open I2C bus!");
            }

            //set I2C address to PIC
            SystemImports.Ioctl(I2C_BUS_HANDLE, I2C_SLAVE, I2C_SLAVE_ADDRESS);
        }
Exemplo n.º 3
0
        public static byte[] ReadMultipleBytes(byte register, int length)
        {
            byte[] regAddr = new byte[] { register };
            int    ret     = SystemImports.Write(I2C_BUS_HANDLE, regAddr, regAddr.Length);

            if (ret < 0)
            {
                throw new Exception("Error writing to the I2C bus!");
            }

            byte[] returnDat = new byte[length];
            int    count     = SystemImports.Read(I2C_BUS_HANDLE, returnDat, returnDat.Length);

            return(returnDat);
        }
Exemplo n.º 4
0
        //DO NOT USE, DOESN'T WORK, YET!
        public static void writeMultipleBytes(byte register, byte[] values)
        {
            byte[] regAddr = new byte[values.Length + 1];
            regAddr[0] = register;

            for (int i = 1; i < values.Length; i++)
            {
                regAddr[i] = values[i - 1];
            }

            int ret = SystemImports.Write(I2C_BUS_HANDLE, regAddr, regAddr.Length);

            if (ret < 0)
            {
                throw new Exception("Error writing to the I2C bus!");
            }
        }
Exemplo n.º 5
0
        public override void VisitUsingDirective(UsingDirectiveSyntax node)
        {
            // Only collect "using XXX"
            if (node.UsingKeyword.IsMissing)
            {
                return;
            }

            var nodeName       = node.Name.ToString();
            var namespaceParts = nodeName.Split('.');

            if (namespaceParts[0] == "System")
            {
                SystemImports.Add(node.ToString());
            }
            else if (!collectedNamespaces.Contains(nodeName)) // Did we already collect the sources from the namespace?
            {
                // Find the configured Path for the Namespace
                var sourcePath = additionalSources.FirstOrDefault(x => x.Name == namespaceParts[0]);
                if (sourcePath == null)
                {
                    throw new SourceMergerException($"The namespace '{nodeName}' is not configured in AdditionalSources");
                }

                // Create the folder path
                // using Namespace.UnderNamespace => NamespacePath\UnderNamespace
                var folderPath = Path.Combine(sourcePath.Path, Path.Combine(namespaceParts.Skip(1).ToArray()));
                if (!Directory.Exists(folderPath))
                {
                    throw new SourceMergerException($"The folder '{folderPath}' for the namespace '{node.Name}' could not be found.");
                }

                // Collect all content from the files in the folder
                collectedNamespaces.Add(nodeName);
                CollectFolderContent(folderPath, SearchOption.TopDirectoryOnly);
            }
        }
Exemplo n.º 6
0
 public Import(Func <string, TypeDefinition> findType, ModuleDefinition moduleDefinition)
 {
     System = new SystemImports(findType, moduleDefinition);
 }