【问题标题】:Duplicating an array using .NETMF使用 .NETMF 复制数组
【发布时间】:2014-11-23 22:53:50
【问题描述】:

如何使用 .netmf(VB 或 C#)多次重复数组?

您将在下面找到我用来构建 Byte() 的函数。它所做的只是获取一个 8 字符的字符串(例如 10101000),并将每个字符的相位替换为 252 和 0 的 128 并将其转储到字节数组中。例如。

Dim bytes() as array = {252,128,252,128,252,128,128,128} 

^^^^ 将是等价的。^^^^

假设我使用我的函数并传递一个字符串 10101011

Dim N as integer = 3
Dim Teststring as string = "10101011"
Dim testbyte() as byte = Allbytes2send(Teststring , N)

Testbyte() 现在应该用相位字符串填充 3 次

For each b in Testbyte
Debug.Print(b.tostring)
Next
'{252,128,252,128,252,128,252,252,252,128,252,128,252,128,252,252,252,128,252,128,252,128,252,252}  

功能

 Shared Function Allbytes2send(ByVal color As String) As Byte()



    Dim bitcolor As String() = New String(color.Length - 1) {}

    Dim b2sa As Byte() = New Byte(bitcolor.Length - 1) {}

    For i As Integer = 0 To color.Length - 1
        bitcolor(i) = color(i).ToString()
    Next

    For i As Integer = 0 To bitcolor.Length - 1
        Dim data As String = bitcolor(i)
        Select Case data
            Case "0"
                bitcolor(i) = "128"
            Case "1"
                bitcolor(i) = "252"
        End Select
    Next

    For i As Integer = 0 To bitcolor.Length - 1
        b2sa(i) = Byte.Parse(bitcolor(i))
    Next




    Return b2sa
End Function

【问题讨论】:

    标签: c# arrays vb.net .net-micro-framework


    【解决方案1】:

    想通了,我将它包装在另一个函数中。通过使用 Array.copy 并重新分配我的字节数组,我能够动态更改数组的大小并使用预定数字乘以任何给定数字进行复制。

      Shared Function SendAllLeds(ByVal LedsData As Byte(), ByVal LedCount As Integer) As Byte()
    
        Dim testbyte2() As Byte = Nothing
        Dim y, z As Integer
    
    
        y = (24 * LedCount) - 1
        z = 0
    
        ReDim testbyte2(y)
    
        While z <= y
            Array.Copy(LedsData, 0, testbyte2, z, 24)
            z += 24
        End While
    
        Return testbyte2
    
    
    End Function
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      • 2018-04-26
      • 1970-01-01
      • 2010-10-08
      • 2015-06-05
      相关资源
      最近更新 更多