First of all there is a small error in Michael's codeTry this to send all four bytes at onceVB Code:
'This line ' B = B Or 2 ^ (K - 1) 'Should be B = B Or 2 ^ (8 - K)msdn says that the output should be a variant.VB Code:
Option Explicit Private Sub Command1_Click() Dim sdata As Variant sdata = Array("11111000", "11110100", "11110010", "11110001") MSComm1.Output = BinToByte(sdata) End Sub Private Function BinToByte(ByVal Bin As Variant) As Variant Dim B As Byte, K As Long, j As Long Dim s As String s = "" For j = LBound(Bin) To UBound(Bin) B = 0 For K = 1 To 8 If Mid$(Bin(j), K, 1) = "1" Then B = B Or 2 ^ (8 - K) End If Next K s = s & Chr(B) Next j BinToByte = s End Function




Reply With Quote