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

Visual Basic 6 Example for CFA634-USB

borgc

New member
I looked all over this web site for an example written vb6 language. I found one, evidently written by a non-vb programmer (I got that out of the vb slams in his source code). So here is my contribution to the other vb6 developers out there. This is an application that simply writes out information to a CFA634 - USB device. It is actually a project group - an exe referencing to other dll projects. One project Idc Registry is an interface to the windows registry. The main work horse of the application is the IdcCrystalFontz dll project is the interface to the Crystal Fontz LCD device.



opens the registry and looks for information placed in by the Crystal Fontz USB Driver 1.0.2154.
It then extracts information out of the registry to load the LCD Devi
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

Attachments

borgc

New member
in addition

The Crystalfontz dll, then uses an API call to check and see if the com ports utilized by the USB deives is connects. If it is then the active device is placed in the LcdDisplays. This is all done then the LCDDisplays class in instantiated.

I then used an array of com controls which adds a new com control for each Crystal Fontz USB device which is on hte USB device(this is the reason for the hidden form (frmComms) in the dll). Each LcdDisplay is associated with it's own com control.

If you would like take a look at the code, use it as you want. I consider it open source. This code is not supported and is for example purposes only.

- another thing - the reference may get screwed up when you down load this project. So here is the references

CrystalFontzLcdController references IdcCrystalFontz

IcdCrystalFontz references IdcRegistry -

Hope this helps some one -
 

rmcleod

New member
Problem with VB Code

I've downloaded the IdcCrystalFontzLcdController example, but I'm having problem with the code. After properly referencing the two components - IdcCrystalFontz and Registry - when I fire up the application it reports: "Error 8002 - Invalid Port number".

Not sure what is wrong here. I could have sworn that I'd fired up the application previously without this error, but now I can't get it going.

Any ideas?


BTW, I can get the display to work fine with the 635wintest code. So it's not the display and that also indicates that the driver is working fine too.


Thanks,

mcleod
 

borgc

New member
Error 8002 - Invalid Port number

One of two things is probably happening here...

1. That Com port is being used by another device

2. The com port is number is outside the range excepted by the MSCOMM control

I believe the MSComm Control only supports port numbers 0-16.



Go to Device Manager -> Ports

Find the Comm port that you are referencing (It should be one labeled - CrystalFontz XXXXXX-USB)
1. Double click on it - Click the "Port Setting" Tab
2. Click the "Advanced" Button
3. Change the "COM Port Number" to a value 1-16 (make sure the port you are changing this to is not already in use.)

4. Click OK
5. Click OK
6. Right Click on POrts - Scan for Hardware Changes

Try it now
 

rmcleod

New member
Still Problems with VB Code

I did as you suggested, but still get the same result of an invalid port. The device manager showed that there was no other device using this port, and the port was COM5. So it's not out of range.

I even took the original .zip file and unpacked it in a different directory and rebuilt everything from the ground up including the references to Registry and IdcCrytstalFontz. Still the same result.

Curious...
 

borgc

New member
IdcCrystalFontz.LcdDisplay.Activate()

I am assuming you are getting the error in the IdcCrystalFontz.LcdDisplay.Activate() function.

The code goes to the following registry key SYSTEM\ControlSet001\Enum\FTDIBUS\ and gets the entries for the Crystal Fontz devices from there. Under this key there will be an entry for each Crystal Fontz device that was ever connected to your PC.

Under the key "000\Device Parameters" there is another key labeled "PortName" if you have multiple entries for the devices that use the same port number, one of the ports will generate this error.

You can delete the entries for devices that are no longer attached to your computer.


Change the function IdcCrystalFontz.LcdDisplay.Activate()

to look like this
Code:
'*****************************************
'          Activate
'*****************************************
Friend Sub Activate()
  Dim commSettings As String
  If Not mfrmComms Is Nothing Then
    If mfrmComms.MSComm.PortOpen Then mfrmComms.MSComm.PortOpen = False
    mfrmComms.MSComm.Break = True
  End If

  On Error GoTo Error_Handler
  Set mfrmComms = Nothing
  Set mfrmComms = New frmComms
  mfrmComms.MSComm.CommPort = miPort
  mfrmComms.MSComm.Settings = ("19200,n,8,1")
  mfrmComms.MSComm.DTREnable = True
  mfrmComms.MSComm.RTSEnable = True
  mfrmComms.MSComm.Handshaking = comXOnXoff
  If mfrmComms.MSComm.PortOpen Then mfrmComms.MSComm.PortOpen = False
  mfrmComms.MSComm.PortOpen = True
Exit Sub
Error_Handler:
 MsgBox "Unable to start Crystal Fonts Display connected to port " & CStr(miPort)
End Sub
Try this an post your results.
(Edit add code tags. -admin)
 

rmcleod

New member
Still having problems...

Different day, different results. Last week when I was trying this I was in an environment where I had other devices (not CrytstalFontz) plugged into my PC. This week I do not, and as a result, I am not getting the invalid port number error. I will spend some more time on Friday trying to duplicate this problem.

However, I went looking for the Activate function in the code so I could modify the code per your last posting and could not find it. I looked in the LcdDisplay module and just didn't see the Activate function. I searched through this project and could not find it.

I did search through both of the other projects - CrystalFontzLcdController and IdcRegistry and could not find an instance of "Activate" in these projects either.

So what am I missing here? I would add the function since it doesn't exist in the code I have, but how would it get called? Are we working from the same code base?

Now, even with the fact that I can run the app without getting the invalid port error, I am back where I was originally - where I can type in string values in the interface, and click on the write button and not see anything change. Seems there's a real disconnect here.


Thanks.
 

borgc

New member
VB Example

Sorry rmcleod -

I have changed this source code since I originally posted it, and I was referencing some of those changes. I have attached a new version of the source code which has more error checking and additional functionality.

The new version of the code supports messages; which have a static line and then an unlimited number of lines which will be scrolled. Plus it sends a heart beat to the display (causes the back light to pulse).
 

Attachments

borgc

New member
Changes to Original Code

If you just want to change the original code....Here is the change that needs to be made.

Or you can download the attached source code (origianl post) which has the changes in it.

In the project IdcCrystalFontz
- Locate the Class LCDDisplays
- modify the "AssignCommControls" so it looks like this.

'
Code:
*******************************************
'          AssignCommControls
'*******************************************
Private Sub AssignCommControls()
    Dim iCommControlsNeeded As Integer
    Dim iCnt As Integer
    Dim i As Integer
    Dim oLcd As LcdDisplay
    Dim iCurrCommControl As Integer
    

    iCurrCommControl = 0
    For i = 1 To mCol.Count
      On Error GoTo Skip_This_Comm
        Set oLcd = mCol(i)
        If Not oLcd Is Nothing Then
        
            If iCurrCommControl <> 0 Then
                Load gfrmComms.MSComm(iCurrCommControl)
            End If
            If gfrmComms.MSComm(iCurrCommControl).PortOpen Then gfrmComms.MSComm(iCurrCommControl).PortOpen = False
            gfrmComms.MSComm(iCurrCommControl).CommPort = oLcd.Port
            gfrmComms.MSComm(iCurrCommControl).Settings = ("19200,n,8,1")
            gfrmComms.MSComm(iCurrCommControl).DTREnable = True
            gfrmComms.MSComm(iCurrCommControl).RTSEnable = True
            oLcd.ComPortControl = iCurrCommControl
            iCurrCommControl = (iCurrCommControl + 1)
        End If
Skip_This_Comm:
      Err.Clear
      MsgBox "Unable to load device " & oLcd.Description & " connected to port " & oLcd.Port & "!"
    Next

End Sub
 

Attachments

Last edited:

rmcleod

New member
Cannot connect to device

borgc

I have tried both of the versions you posted recently. In both cases I am having problems making an initial connection to the CrystalFontz device.

With the updated version of the original application, I now get the following message when the application starts:

"Unable to load device Crystalfontz CFA635-USB connected to port 5!"

With the older version, I would not get such a message, but was unable to get the app to send any data to the display. With this new version, it is becoming clear that the app is not connecting properly to the device. So it's not surprising that I can't send any text to the display. But... the application does show that it knows about the device and the port it is connected to.

With the newer version of code (wow! a lot of changes) I get the following message when the app starts up:

"Marquee failed because there was an error writing to the CrystalFontz Device CF004645A"

But the app still opens. If I then click on the "Device Info" button, I get the following error:

"There was an error writing to the Crystal Fontz Device CF004645A"

So even with the new version of the app, it cannot make a connection to the device even though it does see that it is there. I'm assuming that there's something fundamental that is holding things up here.

While I am reasonably adept at debugging a single VB program, I've not had experience debugging an application where there are one or two VB-based DLL's. If you have some pointers on how to approach debugging in this environment, I'd appreciate it. I could probably figure out why it's having a problem connecting to my device.


mcleod
 

borgc

New member
rmcleod -

It is not the application that is unable to send information to the device. It is the MSComm Control used by the application.

I have not coded in VB6 in a number of years so my skills are a little rusty. I should have had the code in magenta in the example I provided to you (Original Old Project). This should now display the error message the MSComm control is generating.

The error you are seeing, has something to do with the MS Comm Controls inability to connect to your device. Either the device is open with some other software, the configuration on the device changed.

The application errors out on gfrmComms.MSComm(iCurrCommControl).Settings = ("19200,n,8,1") - which is then jumps down to the Skip_This_Comm:

If you have multiple LCD Dispalys, I would try to connect another one and see if you can connect to that one - or change the Comm port to a different port.

Debuggin Project Group (Solution) is very simular to debugging a single project. Place a break point on the line where you want the application (in any of the projects) to break and when the application breaks use F5to step through it or F8 to step into it. If you are unable to step into the code - it mean you are referencing a version of the compiled DLL and not the Project.

The reason the Device works fine with the 635wintest application probably is because they are using an API to connect to the device or they are querying the device using APIs to get the comm settings.

Code:
'*******************************************
'          AssignCommControls
'*******************************************
Private Sub AssignCommControls()
    Dim iCommControlsNeeded As Integer
    Dim iCnt As Integer
    Dim i As Integer
    Dim oLcd As LcdDisplay
    Dim iCurrCommControl As Integer
    

    iCurrCommControl = 0
    For i = 1 To mCol.Count
      On Error GoTo Skip_This_Comm
        Set oLcd = mCol(i)
        If Not oLcd Is Nothing Then
        
            If iCurrCommControl <> 0 Then
                Load gfrmComms.MSComm(iCurrCommControl)
            End If
            If gfrmComms.MSComm(iCurrCommControl).PortOpen Then gfrmComms.MSComm(iCurrCommControl).PortOpen = False
            gfrmComms.MSComm(iCurrCommControl).CommPort = oLcd.Port
            gfrmComms.MSComm(iCurrCommControl).Settings = ("19200,n,8,1")
            gfrmComms.MSComm(iCurrCommControl).DTREnable = True
            gfrmComms.MSComm(iCurrCommControl).RTSEnable = True
            oLcd.ComPortControl = iCurrCommControl
            iCurrCommControl = (iCurrCommControl + 1)
        End If
Skip_This_Comm:
[COLOR="Magenta"]      If Not Err.Number = 0 Then
        Err.Clear
        MsgBox "Unable to load device " & oLcd.Description & " connected to port " & oLcd.Port & "! due to the following error - " & Err.Description
      End If[/COLOR]
    Next

End Sub
 

Mak_Action

New member
Visual Basic 6 Example for CFA634 USB

Hi. I am developing an easier API to interface with the CFA635 LCD module. I got through the part of sending and receiving packets with the help of the neighbouring topic that deals with Visual Basic Express example.

I am having a problem of demystifying the art of bit mask reading. In the datasheet, for command to Read the Keypad in Polled Mode, it says that it returns a bit mask at data0, but from that, I have absolutely no idea to determine which key was pressed. I never worked with bitmasks. I searched about it but came to no avail.

Made a small function which is overloaded one is one-way, another returns the data
Code:byte response = SendPacketcommand, dataLength, data, 3;SendPacket returns a byte array of response. So the 0th place would be type, 1st the data length, and so on.
 

CF Tech

Administrator
CFA-635 Visual Basic Bitmask Operations

It looks like VB has bitmask operations supported:

http://www.nerdymusings.com/LPMArticle.asp?ID=17

Bit Flag Cheat Sheet

Sample Declarations:

00000000 00000001 Const conFlagOneTrue As Integer = 1
00000000 00000010 Const conFlagTwoTrue As Integer = 2
00000000 00000000 Dim intFlags As Integer

Initialize both flags to true:

intFlags = conFlagOneTrue Or conFlagTwoTrue

Set flag one to False without changing flag two:

intFlags = intFlags And (Not conFlagOneTrue)

Set flag one back to True without changing flag two:

intFlags = intFlags Or conFlagOneTrue

Test flag one for True:

If (intFlags And conFlagOneTrue) > 0 Then

Test flag one and flag two for True:

If (intFlags And (conFlagOneTrue Or conFlagTwoTrue)) > 0 Then
There is some other information here:

http://support.microsoft.com/kb/113476

Is that enough to get you going in the right direction?
 
Top