• We recently switched our forum platform. If you experience any issues please email support@crystalfontz.com

Visual basic and cfa-633

ejf28

New member
Hello I was trying to send a test packet to my cfa633 module using visual basic and nothing was displayed on the module itself so wanted to see if someone could look at my code. I tried to keep it pretty basic, just sending the text "test" to appear on the module. The crc_lookup_table and get_crc are both functions used in the sample code provided on the forums.

Dim mscomm1 As New MSCommLib.MSComm
mscomm1.CommPort = 3
mscomm1.Settings = "19200,n,8,1"
mscomm1.PortOpen = True


Initialize_CRC_Lookup_Table()
Dim type As String
Dim datalength As Integer
Dim data(4) As Byte
Dim crc As WORD
Dim packet As String

type = 31
data(0) = 0 ' row
data(1) = 0 ' col




data(2) = Asc("test")
datalength = data.Length
crc = Get_Crc(data, datalength)
data(3) = crc.Hi
data(4) = crc.Lo
packet = type & datalength & data(0) & data(1) & data(2) & data(3) & data(4)

mscomm1.Output = packet
MessageBox.Show(packet)


Thank you for looking at the code and hopefully I will be able to display stuff eventually. I also hope that I posted this in the right section, if not I appologize.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
Based on the data sheet section on "Packet Structure", I see two errors.

1. The crc includes all bytes in the packet except the crc itself. You are not including the "type" and "datalength" bytes in the crc.

2. The crc is sent LSB first. You are sending MSB first.

Also, I think these two:
Dim type As String
Dim datalength As Integer

should be "As Byte", not string or integer, but I'm not all that familiar with VB, so I could be wrong.

And, this:
data(2) = Asc("test")
is putting the numeric value of the first character of the string into the 3rd byte of the "data()" array. I have other ideas about what's wrong with your code, but lets deal with these first.
 

ejf28

New member
as I understood from when i called tech support, the line of code sent has to look like this: Type/datalength/data/crc (without /'s of course) so i thought the crc has to be on the end. From what you are saying should the order be crc/data/datalength/type? Also he said that its all basically sent out as a string to the lcd, so thats why i had those two things not as bytes. I'm not sure on anything so thank you for responding at least
 
Yes, tech support is correct in describing the order of the bytes in the packet. I think you don't understand what I wrote, so I'll embellish a bit.

1. You are not including the "type" and "datalength" bytes in the crc. Your function call:
crc = Get_Crc(data, datalength)
only includes the "data()", and ignores the first two bytes of the packet. Also, the data() array is too short to contain your data.

2. The crc, at the end of the packet, is byte-reversed in your code.

Here is an example of code that should do what you want (leaving out the serial port stuff):
Code:
Dim type As Byte
Dim length As Byte
Dim cursor(2) As Byte
Dim text As String
Dim subpacket As String
Dim crc As WORD
Dim packet As String

type = 31
cursor(0) = 0   ' row
cursor(1) = 0   ' col
text = "test"   ' here is your variable length text
length = Len(text)
subpacket = type & length & cursor & text   ' this is everything except the crc
crc = Get_Crc(subpacket, Len(subpacket))
packet = subpacket & crc.Lo & crc.Hi   ' put crc bytes at end of data
 
Last edited by a moderator:

ejf28

New member
thank you very much, a couple things had to be modified for it to work, and i understand the ordering now, the only thing wrong with your example was calculating the crc. it needs a byte array to be provided, in your example it is just a string. So i am guessing that i need to remake almost identical to the subpacket at that point but in a byte array format?
 

ejf28

New member
Here is what i have as of now (still doesnt work):
Dim mscomm1 As New MSCommLib.MSComm
mscomm1.CommPort = 3
mscomm1.Settings = "19200,n,8,1"
mscomm1.PortOpen = True



Initialize_CRC_Lookup_Table()
'sample code type/datalength/data/crc
'31/00a/crc no /'s though

Dim type As Byte
Dim length As Byte
Dim cursor(2) As Byte
Dim text As String
Dim subpacket As String
Dim crc As WORD
Dim packet As String

type = 31
cursor(0) = 0 ' row
cursor(1) = 0 ' col
text = "test" ' here is your variable length text
length = Len(text)
subpacket = type & length & cursor(0) & cursor(1) & text ' this is everything except the crc


Dim output(24) As Byte
output(0) = type
output(1) = length
output(2) = cursor(0)
output(3) = cursor(1)
Dim i As Integer = 0
Do Until i = text.Length
output(i + 4) = Asc(text.Chars(i))
i = i + 1
Loop


crc = Get_Crc(output, Len(subpacket))
packet = subpacket & crc.Lo & crc.Hi ' put crc bytes at end of data

mscomm1.Output = packet
mscomm1.PortOpen = False
 
... calculating the crc. it needs a byte array to be provided, in your example it is just a string...
Hmm, byte arrays and strings are pretty much the same thing in C, but like I said, I'm not a VB user. Sorry that your code still isn't working, but I don't think I can be of much further help with VB. Since I don't have one of these displays, I can't try much else either.

Are you sure that your serial port code is good; is your packet actually being transmitted? Are you sure that your crc calc function is working correctly?
 

ejf28

New member
Yes I have looked at that code, its been the one i've primarily been looking at. I guess it's possible that my lcd isn't even receiving anything. This is the code I have before the previous stuff I posted:
Dim mscomm1 As New MSCommLib.MSComm
mscomm1.CommPort = 3
mscomm1.Settings = "19200,n,8,1"
mscomm1.PortOpen = True

and after the stuff is all put into a packet i just say:

mscomm1.output = packet (have tried as string, byte array, and in a loop with individual bytes)

No errors are reported but it is possible that it's just not receiving it. My com port is 3, I even checked with the wintest, the settings seem to me correct, so I am unsure if there is any issue here. Also as a note, my visual basic .net 2003 didn't have the mscommlib already in it so i downloaded the "mscomm32.ocx" activex control, registered it properly like any other ocx file, then added it to my project.

I am beginning to feel dumb for having this much trouble with this, since from all examples it seems that it should be quite easy to send stuff to the module but I guess I'll continue with my stupidity until I get the word "test" to appear on my screen lol
 
I presume you have installed the Wintest application
http://www.crystalfontz.com/software/633WinTest
and that you are able to control the display, which would indicate that your hardware and wiring are OK.

Then you could use the Wintest packet debugger to see what is being sent to the display. Take those bytes from the debugger window, and use them in your VB code, to fill a packet and send it, and see if it works. If that works OK, then do the same except don't put in the crc bytes, and use your Get_Crc() function to see if it returns the same crc value.
 

ejf28

New member
Well I am really confused why it still doesn't work... I tried using the wintest to send the letter "a" to the first line and the debugger told me:
aC=7( 7 = LCD Line 1),L=16,D="a ",CRC=0xFA93

The data part has 15 spaces, but doesnt show up in the forum, so there is a valid 16 total

so then I wrote the code like this:

Dim mscomm1 As New MSCommLib.MSComm
mscomm1.CommPort = 3
mscomm1.Settings = "19200,N,8,1"
mscomm1.PortOpen = True

Dim packet As String


' command = 7
' length = 16
' data = "a "
' CRC=0xFA93
packet = "716a 0xFA93"
mscomm1.Output = packet

and still does not work... even from a direct copy and paste method, so guessing that the mscomm isn;t connecting to the unit, so now what?
 
First, it might be better if you put your code in a code box (use the "#" tool icon just above the edit compose window), so the tabs and spaces and special characters are preserved.

One reason that this latest code won't work is you are forgetting that the crc must be sent LSB first. So the crc bytes would need to be reversed 0x93, 0xFA.

Next, you are mixing decimal, hex, and ascii within quotes, with no separation, so it all appears as a character string to VB, with no numerical values. I.e., the "7" is interpreted as "0x37", and the "16" is treated as two bytes, 0x31,0x36, where it should only be one byte (0x10), and the crc is treated as 6 ascii bytes instead of 2 hex bytes.
Code:
aC=7( 7 = LCD Line 1),L=16,D="a               ",CRC=0xFA93

' command = 7
' length = 16
' data = "a               "
' CRC=0xFA93
packet = "716a               0xFA93"

should be:
packet = 7 & 16 & "a               " & 0x93 & 0xFA
See if this makes it work.
 

ejf28

New member
should be:
packet = 7 & 16 & "a " & 0x93 & 0xFA

I tried that but the hex stuff is underlined because the packet is looking just for a string input, should i be converting the 0x93 & 0xFA into text first or something?
 
USB LCD Displays - Graphic and Character LCDs with a Keypad
Maybe something like this:
Code:
packet = 7 & 16 & "a               " & "\x93" & "\xFA"
or
packet = Chr(7) & Chr(16) & "a               " & Chr(0x93) & Chr(0xFA)
This sort of thing is why I hate VB, and would never use it.
 

ejf28

New member
both didn't work.
in the end isnt a string just sent to the module? So i dont get why the programming language would matter in the end part since they'd all have to break it down to the same string in the end, at least in my mind. I also tried experimenting with vb 2008 because they have a serial control like the mscontrol but same problem, appears to work fine but nothing is sent. is it possible that my mscontrol isnt connecting?
 
You're right, it shouldn't matter what programming language is used. But opinions vary as to which languages are easier to use and which ones give the user more explicit control over what the code does.

Meanwhile, it sounds like you are not even sure that anything is being sent by your program. I guess without additional tools, like an oscilloscope or data analyzer or even a breakout box with LEDs, it would be hard to tell if serial data is being sent.

Another thing to try is to download this "try633.txt" file, which contains the 20 byte string, and use the Hyperterm utility to send it to the display. But I guess that would just be equivalent to using WinTest.
is it possible that my mscontrol isnt connecting?
Afterthought: I wonder if your comm object needs to be set for "no handshaking". Else it might just be waiting for the CTS signal, and that is not connected on a 3 wire cable. Or, you would need a cable with the handshaking signal looped-back. Just trying to think of reasons......
 

Attachments

ejf28

New member
I made a simple little program just now to capture my mscomm settings and allow me to change them from outside of visual basic itself and here are what my settings are by default (what I am using to connect) if that helps at all.


Also I tried loading the hyperterminal up using the correct com settings and such and went to send text file or whatever like you suggested and nothing changed on my display..
 

Attachments

Last edited:
A while back, you posted this:
Well I am really confused why it still doesn't work... I tried using the wintest to send the letter "a" to the first line and the debugger told me:
aC=7( 7 = LCD Line 1),L=16,D="a ",CRC=0xFA93
But I don't see anywhere in your postings that you were ever able to see characters on your display by using Wintest. So, that is the next question... have you ever been able to send data successfully to the 633 by any method, including Wintest?
 

ejf28

New member
lol yes I have, sorry for that
I have used wintest successfully and currently use LCD Smartie to run my current displays, which both work perfectly fine
 
Top