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

Programming LCD screen with VB

Knight

New member
After looking for examples, and fumbling with VB to get it to work with the display, I stumbled upon the following method after a brief call to CF tech support he informed me that I must send it in a byte format.....

This is a small example of how to program the display with VB. It should be compatible with all versions, assuming you have the MSComm control (Only Enterprise And Professional, I Think) added to the current project and it's called "MSComm".

Code:
Private Sub Form_Load()

'Make RTS high, these lines power the LCD.
MSComm1.RTSEnable = True

'Make DTR high, these lines power the LCD.
MSComm1.DTREnable = True

'Set the settings for the port. 19200 baud, No parity, 8 data bits, 1 Stop bit.
MSComm1.Settings = "19200,n,8,1"

'Open the port.
MSComm1.PortOpen = True

'Send the cursor home.
MSComm1.Output = Chr(1)

'Change cursor type to Underline.
MSComm1.Output = Chr(5)

'Change Contrast to 55%
MSComm1.Output = Chr(15) & Chr(55)

MSComm1.Output = "Hello World!"

End Sub

Now does anyone have any clue of how to blank the screen?... Destructively remove all charectors from teh screen?... without having to go to each charector and delete it. Possibly a code sent directory to the controler would do this?
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

CF Tech

Administrator
Thanks for your Visual Basic example code.

This will destructively clear the screen, and put the cursor at 0,0:

MSComm1.Output = Chr(12)

Alternatively you could use the non-destructive "hide display" Chr(2) and its counterpart, "restore display" Chr(3)
 

Knight

New member
Yeah, I saw that code in the manual for the 634 almost 5 minutes after I posted the message, it confuzed me because it was called a Form Feed, but then I saw in parenthesis that it clears the screen, I was looking for just the command, "Clear screen", so taht's where I messed up. :) Thanx though.
 

webmatrix

New member
Thanks for your example but it is not working for me. I used the 631 usb on virtual com port 3. I have closed CC and the display is dark. when i start the VB Projekt it will nothing happend. What commands i must sent to switch it on ? Have erveryone an example ?

Thank for your help
Webmatrix
 

Knight

New member
webmatrix said:
Thanks for your example but it is not working for me. I used the 631 usb on virtual com port 3. I have closed CC and the display is dark. when i start the VB Projekt it will nothing happend. What commands i must sent to switch it on ? Have erveryone an example ?

Thank for your help
Webmatrix
When you say it's "dark" does that mean that the area where the charactor's are supposed to be are black and completely filled with blackness, or does it mean that the screen is clear/blank?

If the screen is dark, then try to change the setting fo the contrast to a lower range. Say to something like 35% or 45%. The contrast setting is in the command line:

MSComm1.Output = Chr(15) & Chr(55)

To change the contrast to 35% the following line works:

MSComm1.Output = Chr(15) & Chr(35)

To change the contrast to 45% the following ling works:

MSComm1.Output = Chr(15) & Chr(45)

Try these things, if that doesn't fix it let me know and I'll try to help you out. There's a couple other possibilities.

Knight.
 

CF Tech

Administrator
There might be some confusion in this thread.

The CFA-632 and CFA-634 series modules use the same command set.

The CFA-631 and CFA-633 use an entirely different command set that requires a packet (which includes a CRC).

I am seeing a lot of CFA-632/CFA-634 commands and talk of the CFA-631 in the same thread so I am thinking that a lot of these examples are not going to work.
 

webmatrix

New member
Yes i have seen some posts about the crc checksum but i search for a little example to comunicate with the cfa 631. Is there no example for the cfa 631 in Visual Basic 6 ? I think this is question that have many people here. The (best) software like JALCD dont work with the CFA 631. I would to write my own Software.

When you have a example please post it here
Thanks
 

Knight

New member
CF Tech said:
There might be some confusion in this thread.

The CFA-632 and CFA-634 series modules use the same command set.

The CFA-631 and CFA-633 use an entirely different command set that requires a packet (which includes a CRC).

I am seeing a lot of CFA-632/CFA-634 commands and talk of the CFA-631 in the same thread so I am thinking that a lot of these examples are not going to work.
Correct.... those examples won't work. I hadn't realized that the 631 was a packet based setup.

For the question of a example for on the 631 with a CRC through VB. I have a post somewhere on here mentioning how to do it. It's still kinda shotty, but I don't use the display anymore.

Server no longer needed support for VB. I was looking for server usage for the 633 on Linux, but couldn't find it, and said screw it. Anyways, it's there. Lemme see if I can find teh post for you.

Knight.
 

akweb

New member
Using Command 31 on CFA-631

Could someone generate an example on how to use 'command 31' on the CFA-631? I basically just need the packet setup as it would be in VB or C. Using the Packet Debugger, I can see how part of it is generated, but I can't seem to see where to put in the 'row,col' values within the packet. I basically want to just put a string like 'Hello World' anywhere on the display using command 31.

Any help would be greatly appreciated!

Thanks,

-AK
 

Knight

New member
Re: Using Command 31 on CFA-631

akweb said:
Could someone generate an example on how to use 'command 31' on the CFA-631? I basically just need the packet setup as it would be in VB or C. Using the Packet Debugger, I can see how part of it is generated, but I can't seem to see where to put in the 'row,col' values within the packet. I basically want to just put a string like 'Hello World' anywhere on the display using command 31.

Any help would be greatly appreciated!

Thanks,

-AK
I haven't done this in a long time but I think it would be the following in Visual Basic:

mscomm1.output = chr(31) & chr(14) & chr(0) & chr(0) & "Hello World!" & crc

I didn't generate a CRC for that string, but you get the basic idea, right? :)

Knight.
 

akweb

New member
Thanks for the post Knight.

I've actually tried that exact packet. I think the problem lies in the 'CHR(0) & CHR(0)' part of it. In the packet debugger, it's shown as '\000\000', but not sure how to translate that into hex or ascii, or whatever it needs to be. Any further thoughts?

Thanks,

-AK
 

akweb

New member
CF Tech,

I've tried some experimenting in VB with the 631. I've looked over your VB code for examples using command 31, but am still having no luck.

Could you take a look at my code below (specifically the command 31 section) and see if you can find what's wrong?

------------------

Private Sub Form_Load()

'Open port
MSComm1.CommPort = 3
MSComm1.Settings = "115200,n,8,1"
MSComm1.PortOpen = True

'Clear Screen - works fine
Cmd = Chr(&H6) 'command 6
Length = Chr(&H0) 'length 0
crc1 = Chr(&H97) 'crc1 (from Packet Debugger)
crc2 = Chr(&H5B) 'crc2 (from Packet Debugger)
Packet = Cmd & Length & crc1 & crc2
MSComm1.Output = Packet


'Setup packet using command 7 - works fine
Cmd = Chr(&H7) 'command 7
Length = Chr(&H10) 'length 16
Text2 = "1234567890123456"
crc1 = Chr(&HF3) 'crc1 (from Packet Debugger)
crc2 = Chr(&H59) 'crc2 (from Packet Debugger)
Packet = Cmd & Length & Text2 & crc1 & crc2
MSComm1.Output = Packet


'Setup packet using command 31 - doesn't work
Cmd = Chr(&H31) 'command 31
Length = Chr(&H16) 'length 22
LCDRow = Chr(&H0) 'row 0 is this right?
LCDCol = Chr(&H0) 'col 0 is this right?
Text = "12345678901234567890"
crc1 = Chr(&H59) 'crc1 (from Packet Debugger)
crc2 = Chr(&HC0) 'crc2 (from Packet Debugger)
Packet = Cmd & Length & LCDRow & LCDCol & Text & crc1 & crc2
MSComm1.Output = Packet


End Sub

----------------------

Thanks,

AK
 

Knight

New member
akweb said:
Thanks for the post Knight.

I've actually tried that exact packet. I think the problem lies in the 'CHR(0) & CHR(0)' part of it. In the packet debugger, it's shown as '\000\000', but not sure how to translate that into hex or ascii, or whatever it needs to be. Any further thoughts?

Thanks,

-AK

Now that you mention it, I know exactly what the problem is/was.

I stopped messing with the 633 becuase of that problem. I could never generate a correct CRC whenever I inserted a 0 into the packet. That's why it was causing problems, it didn't have the correct CRC and your 631 ignored it.

But it looks like CF has made the source to how to make the CRC available to the VB programmers, something that wasn't there when I was messing with it. This just might make me go back to programming in VB for the 633. :)

Knight.
 

CF Tech

Administrator
akweb said:
CF Tech,

I've tried some experimenting in VB with the 631. I've looked over your VB code for examples using command 31, but am still having no luck.

. . .
Code:
'Setup packet using command 31 - doesn't work
Cmd = Chr(&H31)             'command 31
Length = Chr(&H16)          'length 22
LCDRow = Chr(&H0)           'row 0    is this right?
LCDCol = Chr(&H0)           'col 0    is this right?
Text = "12345678901234567890"
[b]crc1 = Chr(&H59)            'crc1  (from Packet Debugger)
crc2 = Chr(&HC0)            'crc2  (from Packet Debugger)
Packet = Cmd & Length & LCDRow & LCDCol & Text & crc1 & crc2
MSComm1.Output = Packet[/b]
Instead of the stuff above in bold, you need to use the send packet subroutine and the structure. VB is not going to assemble the packet correctly using the "&" operator (This was coded in the forum, not compiled or tested):

Code:
Private Sub Send_Packet_Button_Click()
  Dim outgoing_packet As PACKET_STRUCT
  Dim Index As Integer
  outgoing_packet.command = 31       'Command
  outgoing_packet.data_length = 22   'Length
  outgoing_packet.data(0) = Asc("0") 'row
  outgoing_packet.data(1) = Asc("0") 'col
  Text = "12345678901234567890"
  [b]For Index = 0 To 19
    outgoing_packet.data(2 + Index) = Asc(Mid$(Text, Index + 1, 1))
  Next Index
  'Calculate the CRC, and kick the whole thing out the port
  Call Send_Packet(outgoing_packet)[/b]
End Sub
 

akweb

New member
Programming 631 keys in VB

Anyone have an example in VB on how to use the keys on the 631?

Thanks!

-AK
 

CF Tech

Administrator
Mmmm. I was afraid you might ask that :)

I'll have to take a look at it. Properly receiving packets is quite a bit harder than sending them.
 

Knight

New member
Recieving packets are the easiest.


Assuming the communications on the 633 and 631 are the same the following subroutine will do it.

Code:
Public Sub PacketAnalyzer(Packet)
Dim SplitPacket() As String
SplitPacket = Split(Packet, " ")
If SplitPacket(0) = "128" Then
    Select Case SplitPacket(2)
        Case "1"
            'Key Up Pressed
            Call ScreenManager(vbUpPress)
        Case "2"
            'Key Down Pressed
            Call ScreenManager(vbDownPress)
        Case "3"
            'Key Left Pressed
            Call ScreenManager(vbLeftPress)
        Case "4"
            'Key Right Pressed
            Call ScreenManager(vbRightPress)
        Case "5"
            'Key Enter Pressed
            Call ScreenManager(vbEnterPress)
        Case "6"
            'Key Cancel Pressed
            Call ScreenManager(vbCancelPress)
        Case "7"
            'Key Up Released
            Call ScreenManager(vbUpRelease)
        Case "8"
            'Key Down released
            Call ScreenManager(vbDownRelease)
        Case "9"
            'Key left released
            Call ScreenManager(vbLeftRelease)
        Case "10"
            'Key right released
            Call ScreenManager(vbRightRelease)
        Case "11"
            'Key Enter released
            Call ScreenManager(vbEnterRelease)
        Case "12"
            'Key Cancel released
            Call ScreenManager(vbCancelRelease)
    End Select
End If
This code only recieves the button presses. 'Course this doesn't matter that that's all it does for you since hte 631 doesn't do fan reporting.

Just make sure you call that subroutine from your ms_oncomm subroutine and send it the packet.

Doing things with the incomming packet is harder. :)

Knight.
 
Top