udaywali 0 Newbie Poster

Here is some code that will help you connect a LCD module to Parallel port of a computer.
Almost any 16x2 LCD module should work. It has complete VB6 code. It works on Windows XP very well. I have used hwinterface.ocx from Logix4u.net that provides basic Inport and OutPort functionality (Thanks to them, made the work lot more fun).

Requirements:
a) Parallel Port connector
b) LCD Module
c) Power supply (5V, 50mA should be ok)
d) hwinterface.ocx downloadable from the net, free. (Visit logix4u.net for more info)

You will have to connect the LCD to Parallel port. Pin map is given below. You can get this info from several other locations on the net.

LCD - ParallelPort
RS - Pin 17
R/W - Gnd
E - Pin 1
D7-D0 - Pin8-Pin2

Other connections to LCD include back lit and contrast control. See LCD manual for details.

Copy the hwinterface.ocx to c:\windows\System32
From start menu, click on Run
In the text box key in the following
regsvr32 c:\windows\system32\hwinterface.ocx
You should get a message saying registered successfully.

Create a new project in VB6. Add a form.
Add required controls (text1, text2, text3, command1 and command2)
Add the code snippet as appropriate.

LPT port is generally located at 0x378. However, it may be moved to other ports as well. For example, on my laptop, it is located on …

udaywali 0 Newbie Poster

Can any one help me in using WIALib in VB6. I want to capture images from within my application.

I tried to get some info on WIALib through object viewer, but could not figure out what is the argument to WIA.Create(Device). What is this device? I could not figure out. The C# application example shows no parameter passed to Create function.

Please let me know if any one worked on this.

udaywali 0 Newbie Poster

May be you are using a wrong DAO version. Please check if you are using DAO 3.6. (From VB project, use Project > References menu, select Microsoft DAO 3.6 Object Library)

You may be using ADO and DAO simultaneously. In such a case, set DAO to have a higher priority than ADO object library.

Get back to me if this does not solve the problem. I have seen that error message some time back and I could fix it immediately. If you have problems, please give some details on where you get that error message so that I can try to recreate the situation and suggest precise correction

Regards

Uday Wali

udaywali 0 Newbie Poster

Shefali,

Writing text on X axis is very simple.

picture1.currentx = 500
picture1.currenty = 10
picture1.print "1000"

will print on the x axis. Trick is writing on the y axis because you need to rotate text. If you need help on that, let me know. I have some ready code, I can share with all. It is big, so i have not included here.

Scrolling is also very difficult and slow in VB. You should have a structure to store the values in say, a collection. Collections maintain data in a linked list, so deleting and adding is easy but it is some what slow. Create a class with two values, one for x and one for y. You could use CPoint for example.

'class module CPoint
 
'declarations section
Public x as single
public y as single

Create a collection in your code to store instances of this class.

Public sub Timer_time()
 
static dataPts as collection
static cnt as integer
 
private p as CPoint
 
 
if dataPts is nothing then
   'on the first call, create a new collection
   set dataPts = new collection
   cnt = 0
end if
 
cnt = cnt + 1
set p = New CPoint
p.x = cnt
p.y = ReadPort()
 
dataPts.add p
 
if dataPts.count > 1000
   dataPts.remove 1
endif
 
'you have a max of 1000 points in a collection,
'which you may now display
DisplayValues dataPts
 
End sub
 
 
Private sub DisplayValues(c as collection)
   dim i as integer
   dim x0 as integer  'x …
udaywali 0 Newbie Poster

Shefali

Your data has a neat pattern and VB is just one of the best languages to handle that kind of stuff


say you have read one line of input

dim s as string
dim line as string
 
dim i as integer
dim p2 as string
dim v as integer
 
s = ""
 
s = s & comm1.input
do while (1)
 
'get one line
do while instr(s, chr(10)) > 0
   'get one line of data
   line = left(s, instr(s, chr(10)) -1)
   s = mid(s, len(s1)+1)  'remaing part of input
   
   'get first comma
   i = instr(s, ",")
   p2 = instr(i+1, s, ",")
   v = val(p2)
 
   addPoint2Plot v
 
loop
 
'append comm1 input to any remaining trailing chars of last input
s = s & comm1.input
 
'add some kind of exit code here.
 
loop

I assume addPoint2Plot will plot the data as I has explained in previous example.


Am I clear?

Uday Wali

udaywali 0 Newbie Poster

Connect property of data control can be set to 'Access 2000' instead of older 'Access'. Just this simple change will work.

udaywali 0 Newbie Poster

Try MSDN it self that comes bundled with Visual studio. that is the best guide.

You will need to add a comm control to your project.

Microsoft Comm control 6.0

in VB6.0, for example. .Net may have other similar controls.

See the example I gave to Sheffali few days back, in the same forum in a similar thread.

udaywali 0 Newbie Poster

Shefali,

Create a picture box on the form you are using. We will call it pic1.
Scale the picture box to the required coordinates. Say, your data has a range of -100 to 100, and you wish to display next 1000 readings, you can initialize the picture box in the form load event.

Also, place a command button named cmdRefresh. We will call the com control as comm1.

As you get more readings, you may simply change the x-axis scale. I am sure you will get it.

'declarations 
private count as integer
private lastValue as single
 
 
'event call backs
public sub form_load() 
 
  pic1.autoredraw = true  'you can set it in properties as well
  pic1.scale (0,100)-(1000,-100)
  drawGrid
 
  'rest of initialization code, like opening com port etc. can go here
 
end sub
 
public sub timer1_timer()
    
 
    dim i as integer
 
    i = val(comm1.input)
 
    'if you need a vertical bar use this
    pic1.line (count, 0)-(count, i)
 
    'if you need to draw line graph, use this
    pic1.line (count, lastvalue)-(count+1, i)
    lastvalue = i
    count = count + 1
 
end sub
 
private sub cmdRefresh_click()
 
    pic1.cls
    count = 0
    'no need to reset the last value.
 
end sub
 
private sub drawGrid()
 
   dim i as integer
 
   for i = 1 to 1000 step 100
       pic1.line (i, 100)-(i, -100)
   next
   for i = -100 to 100 step 25
       pic1.line (0, i)-(1000, i)
   next
 
end sub

Try this code. By the way, what is the end use of the program?

Regards


udaywali 0 Newbie Poster

Use a timer to poll the serial port. Read the port and if any data is available, you can process the data. Or else, just wait till you get data (on next timer interrupt)

If you have not used timer before, try this-

create a new project. On the form, add timer control. select and press F4 to get properties. Enable the timer. Set interval to 1000.
Double click on timer. In the event call back, write some code like printing a message or time of day.

Experiment. Get back if you need help.

udaywali 0 Newbie Poster

You are trying to connect a MSAccess database written in higher version than what the underlying data control is trying to access.

Select the data control and press F4 (properties). Look for Connect property. If is set to 'Access', make it 'Access 2000'. This works if your database is in MSOffice 2000. If your database is in MSOffice 95 or 97, 'Access' value is correct.

Check project references (Project > References menu in VB IDE).
Use the latest DAO version 3.6 (or higher).

This should fix your problem.

If not, repair the database and try to open in MSAccess itself.

If you can not, the database is irrepairable.

udaywali 0 Newbie Poster

The first thing you want to do is select data that needs to be included in the report. So, write a small function like this:

private function GetSQL() as string
 
   dim sql as string
 
   sql = "Select * from mytable"
   sql = sql & " Where myDate <= #" & txtFromDate & "#"
   sql = sql & " And myDate >= #" & txtToDate & "#"
 
   GetSQL = sql
 
end function

Of course, I am assuming that user will enter date in text fields txtFromDate and txtToDate.

Next thing you want to do is to print the data on to a form. Include a picturebox on the form. Print to that picturebox.

private sub printReport()
   dim rs as ADODB.Recordset
   dim curY as integer
   dim th as integer
 
   set rs = new ADODB.recordset
   rs.connnection = cnn 'assuming this is opened on form load, etc.
 
   rs.open GetSQL(), adopenstatic
 
   picture1.cls
 
   picture1.currentx = 1250
   picture1.currenty = 210
   picture1.fontname = "Arial"
   picture1.fontsize = 12
 
   th = picture1.textHeight("junk")
   picture1.print "Heading for Report"
 
   curY = 210 + th + 100 'border from header
 
   do while not rs.eof
        printFld 100, curY, rs.field(0)
        printFld  400, curY, rs.field(1)
        'so on for other fields
        rs.movenext
        curY = curY + th     
        if curY > picture1.height then
           exit do
   loop
   rs.close
 
end sub 
 
private sub printFld (x as integer, y as integer, s as string)
   picture1.currentx = x
   picture1.currenty = y
   picture1.print s;  'you may skip the semi colon
end sub

I have only given the skeleton of the report …

udaywali 0 Newbie Poster

VB supports reading and writing to files using 'Open', 'Put' and 'Get' calls. Try this.

dim v as integer
dim offset as long
 
Open PFileName For Binary Access Read As #10
 
offset = 57
get #10, offset, v

Note that offset is in bytes. You can write other logic as necessary. If you need more help, you may ask me.

udaywali 0 Newbie Poster

From the control panel, see the printer you have attached to the USB port. Right click and open the properties. Open the ports tab. You will probably see a list of ports, one of which will point to the device you are interested in using (For example LPT1, COM1,...DOT4_001 etc).

You can use the device name (DOT4... for USB) to send the file. If print command does not work, simply type abc.txt > DOT4_001 , etc.

Good luck

udaywali 0 Newbie Poster

Shefali,

Here is some code (live copy) from a small RS232 tester I use. To use it, create a form with all controls used in this code and associate the sub wit a command button. If you have problems, I can send the full app.

Private Sub Command1_Click()

    On Error Resume Next
    MousePointer = vbHourglass
    MSComm1.CommPort = Val(txtPortNumber)
    If Err > 0 Then
        MsgBox Err.Description & vbCrLf & "Try Again"
        MSComm1.PortOpen = False
        Exit Sub
    End If

    If Check1.Value = vbChecked Then
        MSComm1.Handshaking = comRTS
        MSComm1.RTSEnable = True
    Else
        MSComm1.Handshaking = comXOnXoff
        MSComm1.RTSEnable = False
    End If

    MSComm1.Settings = txtPortSetting
    If MSComm1.PortOpen Then
       MSComm1.PortOpen = False
    End If
    MSComm1.PortOpen = True
    If Err > 0 Then
        MsgBox Err.Description & vbCrLf & "Try Again"
        MSComm1.PortOpen = False
        Err.Clear
        MousePointer = vbDefault
        'txtRecieved = ""
        Exit Sub
    End If

    Dim s As String
    Dim i As Integer

    s = txtOutString
    txtSent = ""
    Do While s <> ""
       If Left(s, 1) = "%" Then
          i = Mid(s, 2, 3)
          MSComm1.Output = Chr(i)
          txtSent = txtSent & "<" & CStr(i) & ">"
          s = Right(s, Len(s) - 4)
       Else
          MSComm1.Output = Left(s, 1)
          txtSent = txtSent & Left(s, 1)
          s = Right(s, Len(s) - 1)
       End If
       DoEvents
    Loop

    Sleep Val(txtActivationDelay)

    s = ""
    i = 0
    Do While s = ""
        i = i + 1
        If i > 100 Then
            txtReceived = ""
            Exit Do
        End If
        s = MSComm1.Input
        DoEvents
        txtReceived = CStr(i)
    Loop

    Sleep Val(txtTransmissionDelay)
    DoEvents
    s = …