USB-UIRT Forum Forum Index USB-UIRT Forum
Plug-n-Play IR Solution
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Code convert vb6 help

 
Post new topic   Reply to topic    USB-UIRT Forum Forum Index -> Developers
View previous topic :: View next topic  
Author Message
Hugolain



Joined: 23 May 2005
Posts: 16

PostPosted: Sat Oct 22, 2005 1:14 am    Post subject: Code convert vb6 help Reply with quote

Hello,
I use this Function to convert the codes of the type: $80, $AB, $C2 ...
Code:
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:
Quote:
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.
Back to top
View user's profile Send private message
Hugolain



Joined: 23 May 2005
Posts: 16

PostPosted: Mon Oct 24, 2005 6:50 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Hugolain



Joined: 23 May 2005
Posts: 16

PostPosted: Tue Oct 25, 2005 8:37 pm    Post subject: Reply with quote

Small error!

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

by:
Code:
If vInput Mod 2 = 1 Then
ByteToIRCode = Bit1 & ByteToIRCode
Else
ByteToIRCode = Bit0 & ByteToIRCode
End If
Back to top
View user's profile Send private message
Hugolain



Joined: 23 May 2005
Posts: 16

PostPosted: Thu Oct 27, 2005 9:34 am    Post subject: Reply with quote

appreciate your help please !!
hugolain
Back to top
View user's profile Send private message
jrhees
Site Admin


Joined: 28 Jan 2003
Posts: 1652

PostPosted: Thu Oct 27, 2005 3:35 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
Hugolain



Joined: 23 May 2005
Posts: 16

PostPosted: Thu Oct 27, 2005 8:16 pm    Post subject: Reply with quote

Is that it correct?

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


Code:
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
Back to top
View user's profile Send private message
jrhees
Site Admin


Joined: 28 Jan 2003
Posts: 1652

PostPosted: Fri Oct 28, 2005 12:37 am    Post subject: Reply with quote

I think so...?

-Jon
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    USB-UIRT Forum Forum Index -> Developers All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group