K8055 control by excel

Looking for help, just purchased the k8055 and we are trying to control the outputs using excel.
I have the sample excel code i downloaded from Velleman with the timers controlling the output time.
We are looking to control the outputs after reading data from a serial barcode.
Any help would be appreciated.

thanks,
dave

[quote]We are looking to control the outputs after reading data from a serial barcode.[/quote]If you can’t use the timer, can you use a button on the Excel sheet to control the K8055 outputs?
Do you want to control the K8055 outputs automatically every time the new barcode data is read from the serial reader to Excel?

Yes we want the outptus to energize when the scanner reads a barcode.
I am using Advanced Serial data Logger software to create a log file when a barcode is received.
We can use keystrokes to send a command to excel when a new barcode is recieved.
We want to keep the output on until a switch will be made at input 1.
this would clear the outputs.

thanks,
dave

I think the following code will do the job.
You may use the downloaded Excel demo as a starting point.
While in Excel, right click on the Worksheet name tab and choose View Code.
Put this code to the VBA editor for Sheet1:

Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long) Private Declare Sub SetAllDigital Lib "k8055d.dll" () Private Sub Worksheet_Change(ByVal Target As Range) 'If Target.Address = "$A$1" Then If Target.Column = 1 Then SetDigitalChannel 1 End If End Sub
In the Project Explorer double click the Module 1 and replace the existing example code with this one:

[code]Option Explicit
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Sub ClearDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub ClearAllDigital Lib “k8055d.dll” ()
Private Declare Function ReadDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long) As Boolean
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Long
Private Declare Function SetTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Dim TimerID As Long
Dim TimerSeconds As Single

Sub Button1_Click()
Dim h As Long
h = OpenDevice(0)
If h = 0 Then
ActiveSheet.Cells(1, 4) = “Card 0 Connected”
TimerSeconds = 0.1 ’ the timer interval is now .1 sec.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
Else
ActiveSheet.Cells(1, 4) = “Card 0 Not Found”
End If

End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
On Error Resume Next
If ReadAllDigital = 1 Then
ClearDigitalChannel 1
End If
End Sub

Sub Button3_Click()
KillTimer 0&, TimerID
CloseDevice
ActiveSheet.Cells(1, 4) = “Card 0 Closed”
End Sub[/code]

Now the K8055 digital output 1 is activated if any data in column 1 is changed.
The output 1 is cleared if button 1 is pressed.
The timer interval for checking the button status is 100ms in this example.

We are able to send our barcode data which contains 10 characters, which contains numbers and letters to a specific cell in an excel sheet.
The next step is turning on the outputs if the excel cell has any value in the contents.

The input 1 will turn off the outputs.

Can you assist with modifying that part of the excel sheet?

thanks,
dave

Here is a link to download the Excel workbook demo containing the VBA code I posted:
box.net/shared/g0yda0b4q4

Connect the K8055 card with both of the address jumpers SK5 and SK6 set.
Open the Excel workbook and enable the macro.
Click the “Open” button.
A text “Card 0 Connected” should appear to cell D1.

Now enter any value to the column A.
The digital output 1 of the K8055 should go on.

Press the K8055 input button 1 to reset the output.
I think this should work also if the barcode data is sent to column A.

If you can’t get the macro opened, you have to select in Excel menu: Tools -> Options
Select the Security tab.
Select Macro Security… button.
Set the security level to Medium.
Then try again to open the document.

The excel workbook works great.

the only 2 changes would be to activate all 8 outputs and check to see we have received 10 characters from the bar code reader.

thanks,
dave

Here are the 2 modifications made:

Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 1 Then If Len(ActiveSheet.Cells(1, 1)) = 10 Then SetAllDigital End If End If End Sub

You have to enter the barcode data to cell A1.
If the length is 10 characters, all the K8055 outputs are activated.
I updated also the download: box.net/shared/g0yda0b4q4

how would i turn off all of the outputs?

thanks,
dave

You can use ClearAllDigital.

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long) On Error Resume Next If ReadAllDigital = 1 Then ClearAllDigital End If End Sub

The download is now updated.

Using this code you can enter the data (10 characters) to any cell of column A:

Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 1 Then If Len(Target) = 10 Then SetAllDigital End If End If End Sub

working great,
thanks for your time and knowledge.

dave

can I monitor the expression bar instead of a cell in excel and determine if we have 10 characters to turn on the outputs?

thanks,
dave

[quote]can I monitor the expression bar instead of a cell in excel and determine if we have 10 characters to turn on the outputs?[/quote]I think this is not possible. The Excel will “process” the value only when complete.

is it possible to choose anywhere on sheet 2 of the work book?

thanks

Yes, it is possible.

While in Excel on Sheet2, right click on the Worksheet name tab and choose View Code.
Put this code to the VBA editor for Sheet2:

Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 1 Then If Len(Target) = 10 Then SetAllDigital End If End If End Sub
Using this code you can enter the data (10 characters) to any cell of column A on Sheet2:

Is it possible to add a 1 second time delay before the outputs are turned off after input 1 is activated?

thanks

Feel so fortunate that I can find this thread via my browser, the discussions here helped me so much on my [color=#323D4F]barcode software[/color] and [color=#323D4F]excel barcode add-in[/color] issues. Seems that I came to the right place to learn the various problems with the computer things.