Code convert vb6 help

Interested in integrating USB-UIRT support into an application? Look here!

Moderator: jrhees

Code convert vb6 help

Postby Hugolain » Sat Oct 22, 2005 1:14 am

Hello,
I use this Function to convert the codes of the type: $80, $AB, $C2 ...
Code: Select all
Private Sub CcBtnConvert_Click()
    CcTxtIRCode.Text = ByteToIRCode(Val("&H" & CcTxtHexa.Text))
End Sub

Public Function ByteToIRCode(ByVal vInput As Byte) As String
Const Header As String = "R08008104"
Const Bit0 As String = "2121"
Const Bit1 As String = "808221"
    Do Until vInput = 0
        If vInput Mod 2 = 1 Then
            ByteToIRCode = ByteToIRCode & Bit1
        Else
            ByteToIRCode = ByteToIRCode & Bit0
        End If
        vInput = vInput \ 2
    Loop
    ByteToIRCode = Header & ByteToIRCode
End Function

Can one help me has to adapt my Function for the codes of the type: $300+DIR ,$3AA ,$3F0 ...please?
Cordially
Hugolain

PS:
The IR Carrier is 39.2kHz. Data is modulated using a space coded signal with 12 data bits (data clock is 1200Hz, but actual data rate varies depending on the data).
For modulating the signals yourself, the signal looks something like this:
Timing based on 1/1200 second clock (~.833ms)
Signal is normally high (idle, no IR).
Start: signal goes low for 8/1200 sec.
Data bits: for each of 12 data bits, space encoded signal depending on bit value
Sends the most significant data bit first
If the data bit is 0: signal goes high for 1/1200 sec, and low for 1/1200 sec.
If the data bit is 1: signal goes high for 4/1200 sec, and low for 1/1200 sec.
BTW: the first 4 bits are always "0011" for the Robosapien V2
When completed, signal goes high again.
No explicit stop bit. Minimal between signals is not known.
Hugolain
 
Posts: 16
Joined: Mon May 23, 2005 11:05 pm

Postby Hugolain » Mon Oct 24, 2005 6:50 pm

Is that it correct?

Private Sub CcBtnConvert_Click()
CcTxtIRCode.Text = ByteToIRCode(Val("&H" & CcTxtHexa.Text))
End Sub

Public Function ByteToIRCode(ByVal vInput As Integer) As String
Const Header As String = "R08008104"
Const Bit0 As String = "2121"
Const Bit1 As String = "808221"
Do Until vInput = 0
If vInput Mod 2 = 1 Then
ByteToIRCode = ByteToIRCode & Bit1
Else
ByteToIRCode = ByteToIRCode & Bit0
End If
vInput = vInput \ 2
Loop
ByteToIRCode = Header & ByteToIRCode
End Function

Private Sub Form_Load()

End Sub
Hugolain
 
Posts: 16
Joined: Mon May 23, 2005 11:05 pm

Postby Hugolain » Tue Oct 25, 2005 8:37 pm

Small error!

replace:
Code: Select all
If vInput Mod 2 = 1 Then
ByteToIRCode = ByteToIRCode & Bit1
Else
ByteToIRCode = ByteToIRCode & Bit0
End If

by:
Code: Select all
If vInput Mod 2 = 1 Then
ByteToIRCode = Bit1 & ByteToIRCode
Else
ByteToIRCode = Bit0 & ByteToIRCode
End If
Hugolain
 
Posts: 16
Joined: Mon May 23, 2005 11:05 pm

Postby Hugolain » Thu Oct 27, 2005 9:34 am

appreciate your help please !!
hugolain
Hugolain
 
Posts: 16
Joined: Mon May 23, 2005 11:05 pm

Postby jrhees » Thu Oct 27, 2005 3:35 pm

You have another error -- you'll need the loop to execute 12 times (once for each bit) -- whereas currently the way your code is written, the loop will only repeat 10 times (since no IR code appears to have bits 10 or 11 set to '1'.

-Jon
jrhees
Site Admin
 
Posts: 1652
Joined: Tue Jan 28, 2003 11:49 pm

Postby Hugolain » Thu Oct 27, 2005 8:16 pm

Is that it correct?

Code: Select all
Private Sub CcBtnConvert_Click()
    CcTxtIRCode.Text = ByteToIRCode(Val("&H" & CcTxtHexa.Text),12)
End Sub


Code: Select all
Public Function ByteToIRCode(ByVal vInput As Integer, Optional ByVal vNbBits As Integer = 8) As String
Const Header As String = "R08008104"
Const Bit0 As String = "2121"
Const Bit1 As String = "808221"

    Do Until vNbBits <= 0
        If vInput Mod 2 = 1 Then
            ByteToIRCode = Bit1 & ByteToIRCode
        Else
            ByteToIRCode = Bit0 & ByteToIRCode
        End If
        vInput = vInput \ 2
        vNbBits = vNbBits - 1
    Loop
    ByteToIRCode = Header & ByteToIRCode
End Function
Hugolain
 
Posts: 16
Joined: Mon May 23, 2005 11:05 pm

Postby jrhees » Fri Oct 28, 2005 12:37 am

I think so...?

-Jon
jrhees
Site Admin
 
Posts: 1652
Joined: Tue Jan 28, 2003 11:49 pm


Return to Developers

Who is online

Users browsing this forum: No registered users and 30 guests