K8055 usb hid test

Hi!

I wonder if there is any possibillity to get an explanation
of what the 9 bytes that the dll sends and recives between my K8055 consist of.

I’m playing around with usb hid communication and want to try to talk to the
card controller. Now I’m only able to read the 9 bytes from the card.
When i try to send data back to the card nothing happen’s so I’m guessing
you(Velleman) have som genius protocoll for communication with the device.

Best of regards /RamboHenke

The byte [0] is always 0.
The byte [1] is 1 to set the debounce time of counter 1.
The byte [1] is 2 to set the debounce time of counter 2.
The byte [1] is 3 to reset counter 1.
The byte [1] is 4 to reset counter 2.
The byte [1] is 5 to send other data to the K8055:
The byte [2] is the digital output byte.
The byte [3] is the analog channel 1 output byte.
The byte [4] is the analog channel 2 output byte.
The byte [7] is the debounce time of counter 1.
The byte [8] is the debounce time of counter 2.

Rx [0]
Rx [1] Digital input
Rx [2] Jumpers
Rx [3] AD 1
Rx [4] AD 2
Rx [5] counter 1 low byte
Rx [6] counter 1 high byte
Rx [7] counter 2 low byte
Rx [8] counter 2 high byte

I hope I read correctly these from the source code…
You may check these from the DLL source code: box.net/shared/dqjnhtjb2t
The source is for the original DLL.

Here a code snippet:

[code]procedure TFormScroll.DoWrite;
var
Written: Cardinal;
ToWrite: Cardinal;
begin
if (ListBox1.Items.Count > 0) then
begin
Buf_tx[0] := 0;
ToWrite := 9;
TheDev := DevList.Items[0];
Written := 0;
TheDev.WriteFile(Buf_tx, ToWrite, Written);
end;
end;

procedure TFormScroll.ReadWrite(k0,k1,k2: longint);
begin
case k0 of
1: begin
Buf_tx[2]:=k1; //digital out
Buf_tx[1]:=5;
dowrite;
end;
2: begin
Buf_tx[2]:=Buf_tx[2] or k1 ; //set bit
Buf_tx[1]:=5;
dowrite;
end;
3: begin
Buf_tx[2]:=Buf_tx[2] and k1 ; //clear bit
Buf_tx[1]:=5;
dowrite;
end;
4: begin
if k1>2 then k1:=2;
if k1<1 then k1:=1;
Buf_tx[2+k1]:=k2;
Buf_tx[1]:=5;
dowrite; //analog 1 or 2
end;
5: begin
Buf_tx[3]:=k1;
Buf_tx[4]:=k2;
Buf_tx[1]:=5;
dowrite; //analog 1 and 2
end;
6: begin
DoRead;
end;
7: begin
Buf_tx[1]:=2+k1;
dowrite; //reset counter
end;
8: begin
Buf_tx[1]:=k1;
if k1=1 then Buf_tx[7]:=k2;
if k1=2 then Buf_tx[8]:=k2;
dowrite; // debounce time
end;
end;
end;[/code]

[code]procedure OutputAnalogChannel(Channel: Longint; Data: Longint); stdcall;
begin
if form_on then FormScroll.ReadWrite(4,Channel,Data);
end;

procedure OutputAllAnalog(Data1: Longint; Data2: Longint); stdcall;
begin
if form_on then FormScroll.ReadWrite(5,Data1,Data2);
end;

procedure ClearAnalogChannel(Channel: Longint); stdcall;
begin
if form_on then FormScroll.ReadWrite(4,Channel,0);
end;

procedure ClearAllAnalog; stdcall;
begin
if form_on then FormScroll.ReadWrite(5,0,0);
end;

procedure SetAnalogChannel(Channel: Longint); stdcall;
begin
if form_on then FormScroll.ReadWrite(4,Channel,255);
end;

procedure SetAllAnalog; stdcall;
begin
if form_on then FormScroll.ReadWrite(5,255,255);
end;

procedure WriteAllDigital(Data: Longint); stdcall;
begin
if form_on then FormScroll.ReadWrite (1,Data,0);
end;

procedure ClearDigitalChannel(Channel: Longint); stdcall;
var k:longint;
begin
k:=255-round(Exp((Channel-1)*ln(2)));
if form_on then FormScroll.ReadWrite(3,k,0);
end;

procedure ClearAllDigital; stdcall;
begin
if form_on then FormScroll.ReadWrite(1,0,0);
end;

procedure SetDigitalChannel(Channel: Longint); stdcall;
var k:longint;
begin
k:=round(Exp((Channel-1)*ln(2)));
if form_on then FormScroll.ReadWrite (2,k,0);
end;

procedure SetAllDigital; stdcall;
begin
if form_on then FormScroll.ReadWrite(1,255,0);
end;

function ReadCounter(CounterNro: Longint): Longint; stdcall;
begin
if CounterNro<1 then CounterNro:=1;
if CounterNro>2 then CounterNro:=2;
if form_on then FormScroll.ReadWrite(6,0,0);
result:=(Buf_rx[3+CounterNro2] + 256Buf_rx[4+CounterNro*2]) and $ffff;
end;

procedure ResetCounter(CounterNro: Longint); stdcall;
begin
if CounterNro<1 then CounterNro:=1;
if CounterNro>2 then CounterNro:=2;
if form_on then FormScroll.ReadWrite(7,CounterNro,0);
end;

procedure SetCounterDebounceTime(CounterNro, DebounceTime:Longint); stdcall;
var t1:Longint;
begin
if CounterNro<1 then CounterNro:=1;
if CounterNro>2 then CounterNro:=2;
t1:= round(0.92.4541POWER(DebounceTime,0.5328));
if t1<1 then t1:=1;
if t1>255 then t1:=255;
if form_on then FormScroll.ReadWrite(8,CounterNro,t1);
end;

function ReadDigitalChannel(Channel: Longint): Boolean; stdcall;
var n1,k:longint;
begin
if form_on then FormScroll.ReadWrite(6,0,0);
n1:=Buf_rx[1];
k:=integer((n1 and 16)>0)*1+
integer((n1 and 32)>0)*2+
integer((n1 and 1)>0)*4+
integer((n1 and 64)>0)*8+
integer((n1 and 128)>0)*16;
if (k and round(Exp((Channel-1)*ln(2)))) > 0 then
result:=true else result:=false;
end;

function ReadAllDigital: Longint; stdcall;
var n1,k:longint;
begin
if form_on then FormScroll.ReadWrite(6,0,0);
n1:=Buf_rx[1];
k:=integer((n1 and 16)>0)*1+
integer((n1 and 32)>0)*2+
integer((n1 and 1)>0)*4+
integer((n1 and 64)>0)*8+
integer((n1 and 128)>0)*16;
result:=k;
end;[/code]

Thanks Vel255!

After further check the code I noted a mistake in the table.
Here a correct one:

[VEL448] Edited the original post

I was just looking at the code and wondered if it would be possible to add a function to the library that reads digital in 1 as serial data and digital in 2 as serial clock?

The problem is that the maximum polling interval in the USB communication is 10ms.
So, it is possible to check the status of the digital inputs every 10ms only.
If you have higher clock rate to the digital input, it can’t be read correctly.

If the clock is low frequency enough, then you may do this serial data read to the application soft as well…