Visual basic and cfa-633

ejf28

New member
yes its com 3. If it wasn't set to the right com then the wintest and lcd smartie wouldn't see it either.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

Attachments

So you do actually have a standard comm port (COM1), but I guess you don't have the connection brought out to a bracketed connector on the back panel. The web page you linked to newegg for your mobo doesn't mention serial ports in the specs, but lists a "COM bracket" in the parts list. Whats with that?

Anyway, if you bring out the serial port connection, it could be part of your troubleshooting setup. Are you at all interested in pursuing the serial port troubleshooting, or else whaddya gonna do now? I can't think of any other way to proceed.
 

ejf28

New member
Well after trying many many examples from the internet, I tried programming in visual basic 2008 since I have that as well. Even though I could not display anything properly, I created a sub that was called everytime there was input and when I pressed a button the event fired properly, so it sorta proves there's a connection of some kind at least... After looking through much code I do believe that my problem is the crc. Once calculated I have no idea what type of data it should be sent out to the display as. I believe that the connection is being made like I said, so I think what we need to do more so is look into how the crc should be sent. I was trying to send a clear screen command, since that seems to be just a tad simpler:

Win test says:
aC=6( 6 = Clear LCD),L=0,D="",CRC=0x5B97

therefore the command is 6, data is nothing but there still needs to be a line for the length 0 I believe then followed by the crc, so something like this:
"600x5B97"

However as stated this isn't correct since the crc isn't a string, but I just wrote that as an illustration more so.. What type is used to send data to the cfa 633, one byte at a time, a byte array all at once, string, integer, or whatever? I have to be certain on that first and then convert my 6 and 0 to whatever is needed followed by converting that crc to whatever is needed.

Sorry for any repeats but just decided to post where I am at in my mind for trial and error.
 

ejf28

New member
Oh and also from doing some reading, I really don't think that it being a usb connection matters, since the driver provided from crystalfontz page makes that gap, so the system recognizes it as a serial port, like the device manager says. I also reinstalled the drivers just in case, and set the com port to be com1 instead just to makes things a little bit easier, even though no success still other than the button pressing being recognized,lcd smartie, and wintest working.
 
So, your port seems to work, then it must be a crc problem. Based on the Wintest debug info, this should work:

Dim blob(6) As Byte 'array longer than necessary, who cares
blob(0) = 6
blob(1) = 0
blob(2) = &H97
blob(3) = &H5B
mscomm1.Output = blob

Try that and see what happens. If the packet is accepted, you should get a return packet that begins with &H46.
 

ejf28

New member
I tried to do what you said but since I'm using the serialport object in visual basic 2008 (since I had some success with it before) it is a little bit different for syntax. I have several ways to send and receive data now. The commands that are available regarding those are:
write
writeline

read
readbyte
readchar
readexisting
readline

The write line is for sending something as a string and write is for bytes. I did your bunch of bytes and it actually worked and cleared the screen! woohoo haha. As for interpreting the incoming results, I am a bit unsure since you can read in various ways. I did a similar method for reading but I get around 4000 bytes incoming so not sure if that is the result we were looking for. I am very happy that it at least cleared it, after I get a hold on the visual basic 2008 ways I may go at it again for the mscomm method again too.

Here is what code I have used so far:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If sp.IsOpen = False Then
            sp.PortName = "COM1"
            sp.Open()
        End If

        Dim blob(6) As Byte 'array longer than necessary, who cares
        blob(0) = 6
        blob(1) = 0
        blob(2) = &H97
        blob(3) = &H5B
        sp.Write(blob, 0, blob.Length)

    End Sub

    Public Sub Receive_data() Handles sp.DataReceived
        Dim incoming(sp.ReadBufferSize) As Byte
        sp.Read(incoming, 0, sp.ReadBufferSize)

    End Sub
 

ejf28

New member
OK and now I have tried to send a string again but no luck. Here is the code I used to try that with:
Code:
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If sp.IsOpen = False Then
            sp.PortName = "COM1"
            sp.Open()
        End If
        Dim crc As WORD
        Dim blob(19) As Byte 'array longer than necessary, who cares
        blob(0) = 7
        blob(1) = 16
        blob(2) = Asc("a")
        blob(3) = Asc(" ")
        blob(4) = Asc(" ")
        blob(5) = Asc(" ")
        blob(6) = Asc(" ")
        blob(7) = Asc(" ")
        blob(8) = Asc(" ")
        blob(9) = Asc(" ")
        blob(10) = Asc(" ")
        blob(11) = Asc(" ")
        blob(12) = Asc(" ")
        blob(13) = Asc(" ")
        blob(14) = Asc(" ")
        blob(15) = Asc(" ")
        blob(16) = Asc(" ")
        blob(17) = Asc(" ")
        crc = Get_Crc(blob, blob.Length)

        blob(18) = crc.Lo
        blob(19) = crc.Hi
        sp.Write(blob, 0, blob.Length)

    End Sub

    Public Sub Receive_data() Handles sp.DataReceived
        Dim incoming(sp.ReadBufferSize) As Byte
        sp.Read(incoming, 0, sp.ReadBufferSize)

    End Sub
 
Ok, great! It looks like you're on the road to success, at least serial port-wise.

As for the 4000 bytes in the receive buffer, maybe you need to purge the RX as part of the open() procedure. Next thing to do is get the crc calculation function working, so that you can handle any packet data.

You notice in that 4 byte sample packet, that the crc bytes are reversed from what the Wintest debug window reported, so as to send LSB first and MSB last. Also, I know that the "0x1234" format is for C and C++ (which Wintest is written in), but I suspect that VB wants to see hex values as "&H1234".

As for your next attempt:

Dim blob(19) As Byte 'the bytes are 0 thru 18
.... snip ....
crc = Get_Crc(blob, blob.Length) 'blob length is 19 (should be 20), but
' you want to calc only on the first 18 bytes (0 - 17)

blob(18) = crc.Lo
blob(19) = crc.Hi 'this is the 20th byte, which doesn't exist in the array
sp.Write(blob, 0, blob.Length) 'blob.length is 19

This cannot work because you are shoving 20 bytes into a 19 byte array.
So, you need:
Dim blob(20) As Byte
 

ejf28

New member
Sorry but what you said was confusing to me. Before the crc is calculated, isn't the length 18 since 3 slots for the type and length:
Code:
 blob(0) = 7
        blob(1) = 1
        blob(2) = 6
The next 16 for 16 characters to fill a line.
Which would equal 18 -> calculate the crc for the final 2
and then the final amount is 20?

Here is what I have, only modified the length to fit in two bytes rather than one, wasn't sure what else you were saying to change:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If sp.IsOpen = False Then
            sp.PortName = "COM1"
            sp.Open()
        End If
        Dim crc As WORD
        Dim blob(20) As Byte
        blob(0) = 7
        blob(1) = 1
        blob(2) = 6
        blob(3) = Asc("a")
        blob(4) = Asc(" ")
        blob(5) = Asc(" ")
        blob(6) = Asc(" ")
        blob(7) = Asc(" ")
        blob(8) = Asc(" ")
        blob(9) = Asc(" ")
        blob(10) = Asc(" ")
        blob(11) = Asc(" ")
        blob(12) = Asc(" ")
        blob(13) = Asc(" ")
        blob(14) = Asc(" ")
        blob(15) = Asc(" ")
        blob(16) = Asc(" ")
        blob(17) = Asc(" ")
        blob(18) = Asc(" ")
        crc = Get_Crc(blob, blob.Length)

        blob(19) = crc.Lo
        blob(20) = crc.Hi
        sp.Write(blob, 0, blob.Length)

    End Sub
 

CF Tech

Administrator
Commands 7 & 8 are deprecated in the CFA-635. Please use command 31.

Please try this:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If sp.IsOpen = False Then
            sp.PortName = "COM1"
            sp.Open()
        End If
        Dim blob(17) As Byte
        blob(0) = 31
        blob(1) = 13
        blob(2) = 5
        blob(3) = 1
        blob(4) = 72
        blob(5) = 101
        blob(6) = 108
        blob(7) = 108
        blob(8) = 111
        blob(9) = 32
        blob(10) = 87
        blob(11) = 111
        blob(12) = 114
        blob(13) = 108
        blob(14) = 100
        blob(15) = 105
        blob(16) = 232
        sp.Write(blob, 0, blob.Length)
    End Sub
Or maybe this:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If sp.IsOpen = False Then
            sp.PortName = "COM1"
            sp.Open()
        End If
        Dim crc As WORD
        Dim blob(17) As Byte
        blob(0) = 31
        blob(1) = 13
        blob(2) = 5
        blob(3) = 1
        blob(4) = 72
        blob(5) = 101
        blob(6) = 108
        blob(7) = 108
        blob(8) = 111
        blob(9) = 32
        blob(10) = 87
        blob(11) = 111
        blob(12) = 114
        blob(13) = 108
        blob(14) = 100
        crc = Get_Crc(blob, blob.Length)
        blob(15) = crc.Lo
        blob(16) = crc.Hi
        sp.Write(blob, 0, blob.Length)
    End Sub
Or this:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If sp.IsOpen = False Then
            sp.PortName = "COM1"
            sp.Open()
        End If
        Dim crc As WORD
        Dim blob(17) As Byte
        blob(0) = 31
        blob(1) = 13
        blob(2) = 5
        blob(3) = 1
        blob(4) = Asc("H")
        blob(5) = Asc("e")
        blob(6) = Asc("l")
        blob(7) = Asc("l")
        blob(8) = Asc("o")
        blob(9) = Asc(" ")
        blob(10) = Asc("W")
        blob(11) = Asc("o")
        blob(12) = Asc("r")
        blob(13) = Asc("l")
        blob(14) = Asc("d")
        crc = Get_Crc(blob, blob.Length)

        blob(15) = crc.Lo
        blob(16) = crc.Hi
        sp.Write(blob, 0, blob.Length)

    End Sub
All these versions should be functionally the same.
 
@CF Tech:
Brent, you are making the same mistake that the OP has been making:

crc = Get_Crc(blob, blob.Length)

where the last 2 bytes of blob() are being included in the crc calc, but shouldn't be (they are where the crc goes).

Should be:
crc = Get_Crc(blob, blob.Length - 2)

@ejf28:
Sorry but what you said was confusing to me. Before the crc is calculated, isn't the length 18 since 3 slots for the type and length:
Code:
 blob(0) = 7
 blob(1) = 1
 blob(2) = 6
You are making the mistake of changing the value 16 into two values: 1 and 6. Should be:
Code:
 blob(0) = 7
 blob(1) = 16
Read my previous post again. Are you familiar with arrays, in which the first element is the "0th" index, and the last element index is "array.length - 1"? So an array of dim(20) has indexes from 0 to 19. For an array of dim(19), there is no 19th index.
 

ejf28

New member
I tried the first method and for the first time in ages it seems, it worked in displaying it!
I tried the second method which i noticed is just the crc part added in and it didn't work.. After looking what was being shown, the first method had 105 and 232 for the crc values but when actually getting the crc through the method it displays 255 and 255. Last method doesn't work prob for same reason too.
 
... when actually getting the crc through the method it displays 255 and 255. Last method doesn't work prob for same reason too.
Right, see my comment above. CF Tech's code is getting the crc on all 17 bytes, instead of just the first 15 data bytes.
Should be:
crc = Get_Crc(blob, blob.Length - 2)
 

ejf28

New member
so like this?

Code:
  If sp.IsOpen = False Then
            sp.PortName = "COM1"
            sp.Open()
        End If
        Dim crc As WORD
        Dim blob(19) As Byte 'array longer than necessary, who cares
        blob(0) = 7
        blob(1) = 16
        blob(2) = Asc("a")
        blob(3) = Asc(" ")
        blob(4) = Asc(" ")
        blob(5) = Asc(" ")
        blob(6) = Asc(" ")
        blob(7) = Asc(" ")
        blob(8) = Asc(" ")
        blob(9) = Asc(" ")
        blob(10) = Asc(" ")
        blob(11) = Asc(" ")
        blob(12) = Asc(" ")
        blob(13) = Asc(" ")
        blob(14) = Asc(" ")
        blob(15) = Asc(" ")
        blob(16) = Asc(" ")
        blob(17) = Asc(" ")
        crc = Get_Crc(blob, blob.Length - 2)

        blob(18) = crc.Lo
        blob(19) = crc.Hi
        sp.Write(blob, 0, blob.Length)
 
so like this?

Code:
  If sp.IsOpen = False Then
            sp.PortName = "COM1"
            sp.Open()
        End If
        Dim crc As WORD
        Dim blob(19) As Byte 'array longer than necessary, who cares
        blob(0) = 7
        blob(1) = 16
        blob(2) = Asc("a")
.... snip ....
        blob(16) = Asc(" ")
        blob(17) = Asc(" ")
        crc = Get_Crc(blob, blob.Length - 2)

        blob(18) = crc.Lo
        blob(19) = crc.Hi
        sp.Write(blob, 0, blob.Length)
Almost right. The crc part looks good, but your array is still too small:
Dim blob(19) As Byte
should be
Dim blob(20) As Byte
 
USB LCD Displays - Graphic and Character LCDs with a Keypad

ejf28

New member
Code:
 If sp.IsOpen = False Then
            sp.PortName = "COM1"
            sp.Open()
        End If
        Dim crc As WORD
        Dim blob(20) As Byte 'array longer than necessary, who cares
        blob(0) = 7
        blob(1) = 16
        blob(2) = Asc("a")
        blob(3) = Asc(" ")
        blob(4) = Asc(" ")
        blob(5) = Asc(" ")
        blob(6) = Asc(" ")
        blob(7) = Asc(" ")
        blob(8) = Asc(" ")
        blob(9) = Asc(" ")
        blob(10) = Asc(" ")
        blob(11) = Asc(" ")
        blob(12) = Asc(" ")
        blob(13) = Asc(" ")
        blob(14) = Asc(" ")
        blob(15) = Asc(" ")
        blob(16) = Asc(" ")
        blob(17) = Asc(" ")
        crc = Get_Crc(blob, blob.Length - 2)

        blob(18) = crc.Lo
        blob(19) = crc.Hi
        sp.Write(blob, 0, blob.Length)
That? still doesnt send if it is
 

ejf28

New member
Code:
 Public Sub Receive_data() Handles sp.DataReceived
        Dim incoming(sp.ReadBufferSize) As Byte
        sp.Read(incoming, 0, sp.ReadBufferSize)

    End Sub


    Dim crcLookupTable(256) As WORD

    'This function returns the CRC of the array at data for length positions
    Private Function Get_Crc(ByRef data() As Byte, ByVal length As Short) As WORD
        Dim Index As Short
        Dim Table_Index As Short
        Dim newCrc As WORD
        newCrc.Lo = &HFFS
        newCrc.Hi = &HFFS
        For Index = 0 To length - 1
            'exclusive-or the input byte with the low-order byte of the CRC register
            'to get an index into crcLookupTable
            Table_Index = newCrc.Lo Xor data(Index)
            'shift the CRC register eight bits to the right
            newCrc.Lo = newCrc.Hi
            newCrc.Hi = 0
            ' exclusive-or the CRC register with the contents of Table at Table_Index
            newCrc.Lo = newCrc.Lo Xor crcLookupTable(Table_Index).Lo
            newCrc.Hi = newCrc.Hi Xor crcLookupTable(Table_Index).Hi
        Next Index
        'Invert & return newCrc
        Get_Crc.Lo = newCrc.Lo Xor &HFFS
        Get_Crc.Hi = newCrc.Hi Xor &HFFS
    End Function

    Private Structure WORD
        Dim Lo As Byte
        Dim Hi As Byte
    End Structure
Thats all I have other than the Initialize_CRC_Lookup_Table() since thats alot to show on here
 

ejf28

New member
not sure I just copied and pasted that from the previous cfa 631 example in another forum on here
 
Top