Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
smileymicros
PostPosted: Apr 29, 2007 - 01:48 AM
Raving lunatic


Joined: Nov 17, 2004
Posts: 6137
Location: Great Smokey Mountains.

js wrote:
hmmmm no function keys as requested by me, I want my money back Smile sorry folks but without functions keys a terminal program is of not much use to me in everyday use.
Haven't used VB for about a year now and even forgot how to load up the source file Laughing it's all coming back so I may have a play at adding some banks of function keys.


At the end of the Developer Terminal pdf file is a list of features requested in the Freaks thread, those that were included and those that weren't. I don't see 'function keys' so maybe I missed your request. What are you asking for and why wouldn't a macro do?

I might consider an upgrade, but I'll have to double the price.

Smiley

_________________
FREE TUTORIAL: 'Quick Start Guide for Using the WinAVR C Compiler with ATMEL's AVR Butterfly' AVAILABLE AT: http://www.smileymicros.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
AllN
PostPosted: Apr 29, 2007 - 01:52 AM
Posting Freak


Joined: Feb 14, 2007
Posts: 1858
Location: San Diego California

Thanks, when I get a chance I will post the differences especially if I can make it a class also. Funny that’s what they needed it in was basic. The hardest part was getting my head back into Visual Basic, as it has been a long time since a client required it. But it came right back and except for still trying to use pointers in my basic code.

I wrote mine and had the class running in two days (really)!
How long did it take you?
(Sounds like a test or challenge to me, John and you know you just kludged this together it’s a piece of junk. I’d be embarrassed!)
Shut-up! Ignore him Smiley!!!
Thanks for the info on the simple terminal but we are past that hurdle and are conversing with their robot and about to begin exploring mapping its environment with GPS for the rough section map and X/Y matrix down to .25 inches. The only part we are actually adding to one of my existing programs is the higher resolution .25” map for the X/Y plane.

smileymicros wrote:
Jonil wrote:
Thank you for a great software, I've been using the old C# version for a while and it's working fine.
A question, is there a way to invert the data received and get the LSB first, for example if received 0x5B print out 0x25 (called inverse convention)?


Thanks to the miracle of open source, the good news is "YES! You too can send reversed or inverted or any other kind of manipulated byte you can dream up... " The bad news is that you have to do it yourself. I will make myself a note to look at C# this weekend and see if there is a simple equivalent to a rotate or shift. This will probably be a bear in VB, but we'll see. If you figure this out before I get a chance, please post your solution.

Smiley


I extracted this from one of my old programs that should help! I through together a test program that should give you the idea as well as convert any Decimal, Hex, Octal, or Binary number to each equivalent. Don't forget to press return after you enter a number thats what fires the event that displays the values!
Make note it returns a 32 bit binary but you could then just use the VB Mid and the StrReverse reverse commands to shift and rotate!
Hope this helps!
This is a lot of code for a shift, sorry basic!

1) Create a blank form in Visual Basic.
2) Add four text boxes, Named:
a. txtDecimal
b. txtHexadecimal
c. txtOctal
d. txtBinary
3) Then simply past this code in the code space for the form.
4) Input a Hex # in the following format “&H5B” as I have little data checking going on.
5) It displays a 32 bit binary # with 8 Bits separated by spaces. To remove the spaces simply add False to all of the Long2Binary(lValue) functions EG: Long2Binary(lValue, False) and no more spaces.
6) Have fun!
Hope this helps,
John

Ps:
By the way out of fairness Smiley I have to mention, my days are like dog years. Two days for me is actually 40 hours as I rarely sleep more than 4 hrs a night once I’m All In.
(I’ll bet my code is shorter than yours! Hehehe)
Ignore him, Really!
---------------------------------------------------------------
Code:

Option Explicit
Dim mDontRecurse As Boolean

Private Sub Form_Load()
    mDontRecurse = False
End Sub

Private Sub txtBinary_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then DisplayValue txtBinary ',False

End Sub

Private Sub txtDecimal_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then DisplayValue txtDecimal ',False
End Sub

Private Sub txtHexadecimal_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then DisplayValue txtHexadecimal ',False

End Sub

Private Sub txtOctal_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then DisplayValue txtOctal ', False

End Sub

'-Displays values for Dec, Hex, Oct, and 32 Bit Binary
Private Sub DisplayValue(ByVal source As TextBox)
Dim sTmp As String
Dim lValue As Long
   
    ' Don't recurse.
    If mDontRecurse Then Exit Sub
    mDontRecurse = True

    ' Get the Value.
    On Error Resume Next
    Select Case source.Name
        Case "txtDecimal"
            lValue = CLng(source.Text)
        Case "txtHexadecimal"
            sTmp = UCase$(Trim$(source.Text))
            If Left$(sTmp, 2) <> "&H" Then sTmp = "&H" & sTmp
            lValue = CLng(sTmp)
        Case "txtOctal"
            sTmp = UCase$(Trim$(source.Text))
            If Left$(sTmp, 2) <> "&O" Then sTmp = "&O" & sTmp
            lValue = CLng(sTmp)
        Case "txtBinary"
            lValue = Binary2Long(source.Text)
    End Select
    On Error GoTo 0

    ' Display the lValue in their different formats.
    If source.Name <> "txtDecimal" Then
        txtDecimal.Text = Format$(lValue)
    End If
    If source.Name <> "txtHexadecimal" Then
        txtHexadecimal.Text = "&H" & Hex$(lValue)
    End If
    If source.Name <> "txtOctal" Then
        txtOctal.Text = "&O" & Oct$(lValue)
    End If
    If source.Name <> "txtBinary" Then
        txtBinary.Text = Long2Binary(lValue)
    End If

    mDontRecurse = False
End Sub
 

'Converts this 32 bit binary value into a Long.
Private Function Binary2Long(ByVal sBinaryValue As String) As Long
Dim sHexValue As String
Dim iNibble As Integer
Dim iNibbleValue As Integer
Dim iFactor As Integer
Dim iBit As Integer

    ' Remove any leading &B if present.
    ' (Note: &B is not a standard prefix, it just
    ' makes some sense.)
    sBinaryValue = UCase$(Trim$(sBinaryValue))
    If Left$(sBinaryValue, 2) = "&B" Then sBinaryValue = Mid$(sBinaryValue, 3)

    ' Strip out spaces in case the bytes are separated
    ' by spaces.
    sBinaryValue = Replace(sBinaryValue, " ", "")

    ' Left pad with zeros so we have a full 32 bits.
    sBinaryValue = Right$(String(32, "0") & sBinaryValue, 32)

    ' Read the bits in nibbles from right to left.
    ' (A nibble is half a byte. No kidding!)
    For iNibble = 7 To 0 Step -1
        ' Convert this nibble into a hexadecimal string.
        iFactor = 1
        iNibbleValue = 0

        ' Read the nibble's bits from right to left.
        For iBit = 3 To 0 Step -1
            If Mid$(sBinaryValue, 1 + iNibble * 4 + iBit, 1) = "1" Then
                iNibbleValue = iNibbleValue + iFactor
            End If
            iFactor = iFactor * 2
        Next iBit

        ' Add the nibble's value to the left of the
        ' result hex string.
        sHexValue = Hex$(iNibbleValue) & sHexValue
    Next iNibble

    ' Convert the result string into a long.
    Binary2Long = CLng("&H" & sHexValue)
End Function
 
 
 ' Converts this Long value into a 32 bit binary string.
Private Function Long2Binary(ByVal lValue As Long, _
    Optional ByVal bSeparateBinary As Boolean = True) As String
Dim sHex As String
Dim iDigit As Integer
Dim iDigitValue As Integer
Dim sNibble As String
Dim sResult As String
Dim iFactor As Integer
Dim iBit As Integer

    ' Convert into hex.
    sHex = Hex$(lValue)

    ' Zero-pad to a full 8 characters.
    sHex = Right$(String$(8, "0") & sHex, 8)

    ' Read the hexadecimal digits
    ' one at a time from right to left.
    For iDigit = 8 To 1 Step -1
        ' Convert this hexadecimal digit into a
        ' binary nibble.
        iDigitValue = CLng("&H" & Mid$(sHex, iDigit, 1))

        ' Convert the value into bits.
        iFactor = 1
        sNibble = ""
        For iBit = 3 To 0 Step -1
            If iDigitValue And iFactor Then
                sNibble = "1" & sNibble
            Else
                sNibble = "0" & sNibble
            End If
            iFactor = iFactor * 2
        Next iBit

        ' Add the nibble's string to the left of the
        ' result string.
        sResult = sNibble & sResult
    Next iDigit

    ' Add spaces between bytes if desired.
    If bSeparateBinary Then
        sResult = Mid$(sResult, 1, 8) & " " & _
                  Mid$(sResult, 9, 8) & " " & _
                  Mid$(sResult, 17, 8) & " " & _
                  Mid$(sResult, 25, 8)
    End If

    Long2Binary = sResult
   
End Function


'Edited: I get no respect. Even my code laughs at me!

_________________
Resistance is futile…… You will be compiled!


Last edited by AllN on Apr 29, 2007 - 03:48 AM; edited 2 times in total
 
 View user's profile Send private message  
Reply with quote Back to top
AllN
PostPosted: Apr 29, 2007 - 02:03 AM
Posting Freak


Joined: Feb 14, 2007
Posts: 1858
Location: San Diego California

That didn't work!
It changes the formatting to smiley faces!
How do I download a file?
Until then if you need a copy PM me with your email address and I will send it to you!
John

Edited: I get no respect. Even my code laughs at me!

_________________
Resistance is futile…… You will be compiled!
 
 View user's profile Send private message  
Reply with quote Back to top
zbaird
PostPosted: Apr 29, 2007 - 03:22 AM
Raving lunatic


Joined: Aug 13, 2006
Posts: 6700
Location: Bellingham, WA - USA

Quote:
I may have a play at adding some banks of function keys.

If you overdraw at the function key bank does your keyboard bounce?

_________________
Chuck Baird
"It's better to catch the trapeze than test the safety net" -- RPi book
http://www.cbaird.org
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
AllN
PostPosted: Apr 29, 2007 - 03:30 AM
Posting Freak


Joined: Feb 14, 2007
Posts: 1858
Location: San Diego California

zbaird wrote:
Quote:
I may have a play at adding some banks of function keys.

If you overdraw at the function key bank does your keyboard bounce?


I'll bet it does. Twice at least and Microsoft will bill you for it!
Cheers,
John

_________________
Resistance is futile…… You will be compiled!
 
 View user's profile Send private message  
Reply with quote Back to top
smileymicros
PostPosted: Apr 29, 2007 - 03:32 AM
Raving lunatic


Joined: Nov 17, 2004
Posts: 6137
Location: Great Smokey Mountains.

AllN wrote:

' Add spaces between bytes if desired.
If bSeparateBinary Then
sResult = Mid$(sResult, 1, Cool & " " & _
Mid$(sResult, 9, Cool & " " & _
Mid$(sResult, 17, Cool & " " & _
Mid$(sResult, 25, Cool
End If

Long2Binary = sResult

End Function


'Edited: I get no respect. Even my code laughs at me!


By using the Code button you get:
Code:

    ' Add spaces between bytes if desired.
    If bSeparateBinary Then
        sResult = Mid$(sResult, 1, 8) & " " & _
                  Mid$(sResult, 9, 8) & " " & _
                  Mid$(sResult, 17, 8) & " " & _
                  Mid$(sResult, 25, 8)
    End If

    Long2Binary = sResult
   
End Function


'Edited: I get no respect. Even my code laughs at me!



And the code stops laughing. I can't speak for the rest of us though.

Smiley

_________________
FREE TUTORIAL: 'Quick Start Guide for Using the WinAVR C Compiler with ATMEL's AVR Butterfly' AVAILABLE AT: http://www.smileymicros.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
AllN
PostPosted: Apr 29, 2007 - 03:44 AM
Posting Freak


Joined: Feb 14, 2007
Posts: 1858
Location: San Diego California

OH! That what it for.
Thanks,
John

_________________
Resistance is futile…… You will be compiled!
 
 View user's profile Send private message  
Reply with quote Back to top
AllN
PostPosted: Apr 29, 2007 - 03:58 AM
Posting Freak


Joined: Feb 14, 2007
Posts: 1858
Location: San Diego California

smileymicros wrote:

And the code stops laughing. I can't speak for the rest of us though.

Smiley

Anything that worked is usually fine with me. Can’t tell you how often I get that response from my colleagues after viewing my code. Being an optimist, I always thought I was just a very funny programmer. You don’t think all these years they were laughing at me and I never knew it. Ahh, couldn’t be! Either way I like to make people laugh so that’s OK too.

Cheers,
John
PS:
Tell you what. You always make me laugh! Now all we have to find out is. Is it with you, or at you!
I love this site!!!!

_________________
Resistance is futile…… You will be compiled!
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Apr 29, 2007 - 05:38 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20363
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

Quote:
What are you asking for and why wouldn't a macro do?

I guess function keys ARE macros at the end of the day but with buttons attached to them and loadable so that they can be set up and used for different tasks and for different projects.
Do you have hanging around the predecessor to Hyperteminal? It came with Win 3.11 and I use it all the time. Unfortunately it is old with max 19200 baud but it is very handy. The whole program is only 145K so if you would like to play with it and don't have a copy I can post it here. There is also Super Term that has saveable and loadable function keys with the addition that they are actually linked to the keyboard's function keys.
A couple of example of their use is here in my superflasher thread, the keys are set up to talk to Carl's LCD firmware. (both Terminal and Super Term screens)

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=48732&start=60

Here is a page of my interface to the 68HC11EVM to program chips and one to talk to some Omron cardreader for service purposes.

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
js
PostPosted: Apr 29, 2007 - 06:08 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20363
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

ps I found the original thread
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=257703
and my comments were:
Quote:
See the 4 buttons you have at the bottom l/h? The old Win 3.11 Terminal program has 4 layers of 8 user programmable function keys which can be saved to a file, so the function for every key (both the key names and what gets sent out) for every project can be saved and reloaded. This for me is the MOST important feature of that old terminal (which I use almost daily).
ohh and the ability to go into a single screen like a real terminal, while I'm wishing VT100 emulation would be nice too with full ANSI support....well you asked for it
...must be discrimination against non C users... Laughing

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Paul Turner
PostPosted: Apr 29, 2007 - 07:45 AM
Wannabe


Joined: Oct 15, 2004
Posts: 69
Location: Australia

Hi, Not wanting to dis' anyone, my source for serial info and code is usually Jan Axelson, have you seen this? http://www.lvr.com/serport.htm#com_port_terminal
Also, I use uCon from here -
http://www.microcross.com/html/micromonitor.html
Much more than HyperTerminal! (Programmable Function keys too!)

_________________
I have coded for about 2 dozen architectures, and they all have their place.
Don't get too religious about them (but AVR is excellent!)
 
 View user's profile Send private message  
Reply with quote Back to top
smileymicros
PostPosted: Apr 29, 2007 - 03:04 PM
Raving lunatic


Joined: Nov 17, 2004
Posts: 6137
Location: Great Smokey Mountains.

js wrote:
ps I found the original thread
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=257703
and my comments were:
Quote:
See the 4 buttons you have at the bottom l/h? The old Win 3.11 Terminal program has 4 layers of 8 user programmable function keys which can be saved to a file, so the function for every key (both the key names and what gets sent out) for every project can be saved and reloaded. This for me is the MOST important feature of that old terminal (which I use almost daily).
ohh and the ability to go into a single screen like a real terminal, while I'm wishing VT100 emulation would be nice too with full ANSI support....well you asked for it
...must be discrimination against non C users... Laughing


I totally misunderstood what you wanted! I see now that you want the terminal to respond to non-ASCII keys on the PC keyboard, specifically the function keys like F1 to F12. That is a very good idea and I'll look into it.

Smiley

_________________
FREE TUTORIAL: 'Quick Start Guide for Using the WinAVR C Compiler with ATMEL's AVR Butterfly' AVAILABLE AT: http://www.smileymicros.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
smileymicros
PostPosted: Apr 29, 2007 - 05:47 PM
Raving lunatic


Joined: Nov 17, 2004
Posts: 6137
Location: Great Smokey Mountains.

Paul Turner wrote:
Hi, Not wanting to dis' anyone, my source for serial info and code is usually Jan Axelson, have you seen this? http://www.lvr.com/serport.htm#com_port_terminal
Also, I use uCon from here -
http://www.microcross.com/html/micromonitor.html
Much more than HyperTerminal! (Programmable Function keys too!)


I am a great admirer of Jan Axelson's work and anytime anyone asks basic USB questions here, I refer them to her website. I hadn't seen her terminal in .NET and I will look at how she wrote it. It is a much simpler terminal than mine, more like the Simple Terminal I posted a while back.

Smiley

_________________
FREE TUTORIAL: 'Quick Start Guide for Using the WinAVR C Compiler with ATMEL's AVR Butterfly' AVAILABLE AT: http://www.smileymicros.com


Last edited by smileymicros on Apr 29, 2007 - 07:32 PM; edited 1 time in total
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Jonil
PostPosted: Apr 29, 2007 - 06:41 PM
Wannabe


Joined: Feb 08, 2006
Posts: 62
Location: Sweden

smileymicros wrote:


This was a byte reception bug that required me to make some changes that are in the new files labeled Beta r02.

Jonil - Major thanks for this catch Very Happy I'd like to send you a Butterfly if you will contact me at my smileymicros email with your address.

Smiley


Smiley, thanks for the offer, but I think I have enough toys to play around with.
Better you send me some more time instead Wink

I've been testing the new version and now it's working fine. I will continue to search for bugs but unfortunately I'm quite busy with other things for two weeks.

Thanks for the great work so far.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
js
PostPosted: Apr 30, 2007 - 12:44 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20363
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

@Paul
Quote:
I use uCon from here
Pretty good for my use, I would like MORE programmable buttons, (is there EVER enough? Laughing ) but it has a few more than Superterm. With some projects I can go up to 32 buttons and with the old Terminal one can just switch banks but when the max number is reached then one would need to load up another lot of keys. It is very rare that I need 32 keys though....well at least that's the maximum I could use so far Smile

@Smiley
Quote:
That is a very good idea and I'll look into it.
Adding programmable function buttons is easy enough as you know, the hard thing I could not get my head around with VB was on how to make them saveable and loadable. With Delphi it was just a matter of editing the .ini file where the configuration is saved, not as easy with VB2005 it seems. I asked for help on M$ forum but it looked like one would have to get some database file happening (that's what a .ini file is anyway of some sort) but i could not get my simple head around on how to do it. Simple enough to modify parameters like serial ports etc which are part of the program and get saved automatically by VB on exit. I know you'll get it working...think of the prestige, fame, you will be invited to the White house for dinner with the Bushes..all of them. Not much money though Laughing

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
AllN
PostPosted: May 01, 2007 - 06:16 PM
Posting Freak


Joined: Feb 14, 2007
Posts: 1858
Location: San Diego California

Well I’m back home.
I just installed VB 2005 Express and I will check out your terminal program tonight and compare it if time allows. I imported the Shift Rotate convert VB 6.0 program to VB Express to compare and I must say I like the class layout.
The import sure helps you learn quickly. I like it.
Here is the convert program imported into VB 2005 Express.
Code:
Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class Converter
   Inherits System.Windows.Forms.Form
   Dim mDontRecurse As Boolean
   
   Private Sub Converter_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
      mDontRecurse = False
   End Sub
   
   Private Sub txtBinary_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtBinary.KeyPress
      Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
      If KeyAscii = 13 Then DisplayValue(txtBinary) ',False
      
      eventArgs.KeyChar = Chr(KeyAscii)
      If KeyAscii = 0 Then
         eventArgs.Handled = True
      End If
   End Sub
   
   Private Sub txtDecimal_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtDecimal.KeyPress
      Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
      If KeyAscii = 13 Then DisplayValue(txtDecimal) ',False
      eventArgs.KeyChar = Chr(KeyAscii)
      If KeyAscii = 0 Then
         eventArgs.Handled = True
      End If
   End Sub
   
   Private Sub txtHexadecimal_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtHexadecimal.KeyPress
        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
        If KeyAscii = 13 Then DisplayValue(txtHexadecimal)
      
      eventArgs.KeyChar = Chr(KeyAscii)
      If KeyAscii = 0 Then
         eventArgs.Handled = True
      End If
   End Sub
   
   Private Sub txtOctal_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtOctal.KeyPress
      Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
        If KeyAscii = 13 Then DisplayValue(txtOctal)
      
      eventArgs.KeyChar = Chr(KeyAscii)
      If KeyAscii = 0 Then
         eventArgs.Handled = True
      End If
   End Sub
   
   '-Displays values for Dec, Hex, Oct, and 32 Bit Binary
   Private Sub DisplayValue(ByVal source As System.Windows.Forms.TextBox)
      Dim sTmp As String
      Dim lValue As Integer
      
      ' Don't recurse.
      If mDontRecurse Then Exit Sub
      mDontRecurse = True
      
      ' Get the Value.
      On Error Resume Next
      Select Case source.Name
         Case "txtDecimal"
            lValue = CInt(source.Text)
         Case "txtHexadecimal"
            sTmp = UCase(Trim(source.Text))
            If VB.Left(sTmp, 2) <> "&H" Then sTmp = "&H" & sTmp
            lValue = CInt(sTmp)
         Case "txtOctal"
            sTmp = UCase(Trim(source.Text))
            If VB.Left(sTmp, 2) <> "&O" Then sTmp = "&O" & sTmp
            lValue = CInt(sTmp)
         Case "txtBinary"
            lValue = Binary2Long(source.Text)
      End Select
      On Error GoTo 0
      
      ' Display the lValue in their different formats.
      If source.Name <> "txtDecimal" Then
         txtDecimal.Text = VB6.Format(lValue)
      End If
      If source.Name <> "txtHexadecimal" Then
         txtHexadecimal.Text = "&H" & Hex(lValue)
      End If
      If source.Name <> "txtOctal" Then
         txtOctal.Text = "&O" & Oct(lValue)
      End If
      If source.Name <> "txtBinary" Then
         txtBinary.Text = Long2Binary(lValue)
      End If
      
      mDontRecurse = False
   End Sub
   

   
   'Converts this 32 bit binary value into a Long.
   Private Function Binary2Long(ByVal sBinaryValue As String) As Integer
      Dim sHexValue As String
      Dim iNibble As Short
      Dim iNibbleValue As Short
      Dim iFactor As Short
      Dim iBit As Short

        sHexValue = ""
      ' Remove any leading &B if present.
      ' (Note: &B is not a standard prefix, it just
      ' makes some sense.)
      sBinaryValue = UCase(Trim(sBinaryValue))
      If VB.Left(sBinaryValue, 2) = "&B" Then sBinaryValue = Mid(sBinaryValue, 3)
      
      ' Strip out spaces in case the bytes are separated
      ' by spaces.
      sBinaryValue = Replace(sBinaryValue, " ", "")
      
      ' Left pad with zeros so we have a full 32 bits.
      sBinaryValue = VB.Right(New String("0", 32) & sBinaryValue, 32)
      
      ' Read the bits in nibbles from right to left.
      ' (A nibble is half a byte. No kidding!)
      For iNibble = 7 To 0 Step -1
         ' Convert this nibble into a hexadecimal string.
         iFactor = 1
         iNibbleValue = 0
         
         ' Read the nibble's bits from right to left.
         For iBit = 3 To 0 Step -1
            If Mid(sBinaryValue, 1 + iNibble * 4 + iBit, 1) = "1" Then
               iNibbleValue = iNibbleValue + iFactor
            End If
            iFactor = iFactor * 2
         Next iBit
         
         ' Add the nibble's value to the left of the
         ' result hex string.
         sHexValue = Hex(iNibbleValue) & sHexValue
      Next iNibble
      
      ' Convert the result string into a long.
      Binary2Long = CInt("&H" & sHexValue)
   End Function
   
   
   
   
   ' Converts this Long value into a 32 bit binary string.
   Private Function Long2Binary(ByVal lValue As Integer, Optional ByVal bSeparateBinary As Boolean = True) As String
      Dim sHex As String
      Dim iDigit As Short
      Dim iDigitValue As Short
      Dim sNibble As String
      Dim sResult As String
      Dim iFactor As Short
      Dim iBit As Short

        sResult = ""
      ' Convert into hex.
      sHex = Hex(lValue)
      
      ' Zero-pad to a full 8 characters.
      sHex = VB.Right(New String("0", 8) & sHex, 8)
      
      ' Read the hexadecimal digits
      ' one at a time from right to left.
      For iDigit = 8 To 1 Step -1
         ' Convert this hexadecimal digit into a
         ' binary nibble.
         iDigitValue = CInt("&H" & Mid(sHex, iDigit, 1))
         
         ' Convert the value into bits.
         iFactor = 1
         sNibble = ""
         For iBit = 3 To 0 Step -1
            If iDigitValue And iFactor Then
               sNibble = "1" & sNibble
            Else
               sNibble = "0" & sNibble
            End If
            iFactor = iFactor * 2
         Next iBit
         
         ' Add the nibble's string to the left of the
         ' result string.
         sResult = sNibble & sResult
      Next iDigit
      
      ' Add spaces between bytes if desired.
      If bSeparateBinary Then
         sResult = Mid(sResult, 1, 8) & " " & Mid(sResult, 9, 8) & " " & Mid(sResult, 17, 8) & " " & Mid(sResult, 25, 8)
      End If
      
      Long2Binary = sResult
      
   End Function
End Class

Cheers,
John

_________________
Resistance is futile…… You will be compiled!
 
 View user's profile Send private message  
Reply with quote Back to top
AllN
PostPosted: May 02, 2007 - 01:24 AM
Posting Freak


Joined: Feb 14, 2007
Posts: 1858
Location: San Diego California

smileymicros wrote:
... so if you will take a look at the code and compare your methods with mine and make your observations public, it would be helpful.
Smiley


Well they are about the same. Not the functions or functionality. Yours is much more suited for the Butterfly and embedded systems in general, as your understanding is far ahead of mine. But they both essentially use a serial Comm event to process data. You use one timer1 to set showCTS_DSR_CD so do I. But I use a 2nd timer to clear some error messages when they occur.
Now the launguage comparsion VB 6.0 to VB Express.
It takes a lot longer to step through someone elses code in VB Express. You step through everything the from class and buttion definition, everything.
If you’re any kind of object oriented programmer I think you’ll aggree Express would probally be easier to learn. If you had to learn basic.
If this is the first laungauge your learning seems it’s not quite as basic or as easy for a true beginner.
For 1st timers I belive VB 6.0 would be eaiser. But you should never go backwards. So just learn C, C+, C++, or C#. You’ll be further head in the long run.
PS:
Here is my comm Event and Textbox keypress event that does all of the work.
Code:

Private Static Sub CommModem3_OnComm()
Dim EVMsg$, ERMsg$, iRslt%
Dim buffer As Variant
   
    ' Branch according to the CommEvent property.
    Select Case CommModem3.CommEvent
        ' Event messages.
        Case comEvReceive
     
            buffer = CommModem3.Input
            Debug.Print "Receive - " & StrConv(buffer, vbUnicode)
            ShowData txtTermRX, (StrConv(buffer, vbUnicode))
           
            gdReceived = gdReceived + Len(StrConv(buffer, vbUnicode))
            If Timer2.Enabled = False Then
                sbrStatus.Panels("Status").Text = gdReceived & " Rec'd"
            End If
           
        Case comEvSend
       
        Case comEvCTS
            If imgCtsOff.Visible = True Then
                imgCtsOff.Visible = False
            Else
                imgCtsOff.Visible = True
            End If
            EVMsg$ = "Change in CTS Detected"
           
        Case comEvDSR
            If imgDsrOff.Visible = True Then
                imgDsrOff.Visible = False
            Else
                imgDsrOff.Visible = True
            End If
            EVMsg$ = "Change in DSR Detected"
        Case comEvCD
            If imgCdOff.Visible = True Then
                imgCdOff.Visible = False
            Else
                imgCdOff.Visible = True
            End If
            EVMsg$ = "Change in CD Detected"
        Case comEvRing
            If imgRiOff.Visible = True Then
                imgRiOff.Visible = False
            Else
                imgRiOff.Visible = True
            End If
            EVMsg$ = "The Phone is Ringing"
        Case comEvEOF
            EVMsg$ = "End of File Detected"

        ' Error messages.
        Case comBreak
            ERMsg$ = "Break Received"
        Case comCDTO
            ERMsg$ = "Carrier Detect Timeout"
        Case comCTSTO
            ERMsg$ = "CTS Timeout"
        Case comDCB
            ERMsg$ = "Error retrieving DCB"
        Case comDSRTO
            ERMsg$ = "DSR Timeout"
        Case comFrame
            ERMsg$ = "Framing Error"
        Case comOverrun
            ERMsg$ = "Overrun Error"
        Case comRxOver
            ERMsg$ = "Receive Buffer Overflow"
        Case comRxParity
            ERMsg$ = "Parity Error"
        Case comTxFull
            ERMsg$ = "Transmit Buffer Full"
        Case Else
            ERMsg$ = "Unknown error or event"
    End Select
   
    If Len(EVMsg$) Then
        ' Display event messages in the status bar.
        sbrStatus.Panels("Status").Text = "Status: " & EVMsg$
               
        ' Enable timer so that the message in the status bar
        ' is cleared after 2 seconds
        Timer2.Enabled = True
       
    ElseIf Len(ERMsg$) Then
        ' Display event messages in the status bar.
        sbrStatus.Panels("Status").Text = "Status: " & ERMsg$
       
        ' Display error messages in an alert message box.
        Beep
       iRslt = MsgBox(ERMsg$, 1, "Click Cancel to quit, OK to ignore.")
       
        ' If the user clicks Cancel (2)...
        If iRslt = 2 Then
            CommModem3.PortOpen = False    ' Close the port and quit.
        End If
       
        ' Enable timer so that the message in the status bar
        ' is cleared after 2 seconds
        Timer2.Enabled = True
    End If
End Sub

' Keystrokes trapped here are sent to the MSComm
' control where they are echoed back via the
' OnComm (comEvReceive) event, and displayed
' with the ShowData procedure.
Private Sub txtTermRX_KeyPress(KeyAscii As Integer)
    ' If the port is opened...
    If CommModem3.PortOpen Then
        ' Send the keystroke to the port.
        CommModem3.Output = Chr$(KeyAscii)

        ' Unless gbEcho is on, there is no need to
        ' let the text control display the key.
        ' A modem usually echos back a character
        If Not gbEcho(3) Then
            ' Place position at end of terminal
            txtTermRX.SelStart = Len(txtTermRX)
            KeyAscii = 0
        End If
    End If
     
End Sub


Hope this helps
Learn C
Cheers,
John

_________________
Resistance is futile…… You will be compiled!
 
 View user's profile Send private message  
Reply with quote Back to top
danielson
PostPosted: May 19, 2007 - 08:55 PM
Wannabe


Joined: Jun 28, 2001
Posts: 75


I think I found a bug...

I've noticed with non-ASCII data that it doesn't always
get displayed as its received. I've tested it minimally but it seems to stay in queue only to be displayed the next time data is received...and if that data is non-standard (example, contains NULLs, maybe no new-line character)... it is also truncated and the end-result that you're always missing some data..

I tested with a cool but unbelievably-crippled program ("RS232 Hex Comm Demo") and it works great.

Also, something it does that I love, if you're interested is...in ascii mode, it displays ascii and then hex characters inside paranthesis... This could be confusing of course if your MCU is sending like (01) back in ASCII, but you can figure how to format the hex display...

All in all though, a pretty-sweet and useful program. I've been using it to develop a packet-engine for MCU to MCU communication over a half-duplex, bi-directional UART
 
 View user's profile Send private message  
Reply with quote Back to top
smileymicros
PostPosted: Feb 18, 2008 - 03:08 AM
Raving lunatic


Joined: Nov 17, 2004
Posts: 6137
Location: Great Smokey Mountains.

Well this thing is getting a bit long in the tooth, but I was using it today and realized that I never fixed the bug about not sending values > 0x7F. After most of a day futzing with it I found that the SerialPort class defaults to ASCIIEncoding so when you try to send anything > 0x7F it sends 0x3F instead. Since the 0x#F is ASCII for '?' I guess I should have gotten a clue sooner.

Anyway, the fix is:
Code:

    // JWP 2/17/08 Set encoding to 8 bits - was ASCII
    serialPort1.Encoding = System.Text.Encoding.UTF8;

Just add this line at the beginning of the MainForm class.

Smiley

_________________
FREE TUTORIAL: 'Quick Start Guide for Using the WinAVR C Compiler with ATMEL's AVR Butterfly' AVAILABLE AT: http://www.smileymicros.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
PaulCo
PostPosted: Apr 01, 2008 - 08:43 AM
Newbie


Joined: Jan 03, 2008
Posts: 11


major thanks
just what i needed
PaulCo
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits