Source Code for K8055N dll (to create own dll)

hi,

I have currently used K8055N module and have used the K8055N dll,

I wish to know, if there is any listing of the source code for K8055N dll.

I am trying to write to the k8055 module, using Setup API c++

using this code

[code]
//global variables

HANDLE hdl_device;
HIDD_ATTRIBUTES hid_dev_attributes;
PSP_DEVICE_INTERFACE_DETAIL_DATA ptr_detail_data;
HDEVINFO hdl_dev_info;
GUID hid_guid;
HANDLE hdl_io_event;
OVERLAPPED overlap_io;
HidD_GetHidGuid(&hid_guid);

//get usb function
// Get enumerator handle for the specified ClassGuid
hdl_dev_info = SetupDiGetClassDevs(&hid_guid,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE );
if(hdl_dev_info)
{MessageBox(L"WORKING");
}

unsigned int interf_indexer = 0;
SP_DEVICE_INTERFACE_DATA dev_info_data;
dev_info_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

// populate theInterfaceData which contains device class information
SetupDiEnumDeviceInterfaces(hdl_dev_info,
0,
&hid_guid,
interf_indexer,
&dev_info_data);

DWORD length;

// This is normally used to obtain the device path information using theInterfaceData obtained above
SetupDiGetDeviceInterfaceDetail(
hdl_dev_info,
&dev_info_data,
NULL,
0,
&length,
0 );

ptr_detail_data = reinterpret_cast<PSP_DEVICE_INTERFACE_DETAIL_DATA>
(new unsigned char[length]);

ptr_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

bool result = SetupDiGetDeviceInterfaceDetail(hdl_dev_info,
&dev_info_data,
ptr_detail_data,
length,
NULL,
NULL );

if (!result)
{
DWORD last_err = GetLastError();
delete[] ptr_detail_data;
ptr_detail_data = 0;
SetupDiDestroyDeviceInfoList(hdl_dev_info);
hdl_dev_info = 0;
CloseHandle(hdl_io_event);
hdl_io_event = 0;

	}

hdl_device = CreateFile(
ptr_detail_data->DevicePath,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
if (hdl_device != INVALID_HANDLE_VALUE)
{MessageBox(L"WORKING!!");
}
int str = 3;
DWORD bytesWritten;

bool y=WriteFile(ptr_detail_data->DevicePath, (char *)str, sizeof(str), &bytesWritten, NULL);
if(y==false)
{MessageBox(L"write failed!");
}
[/code]

I got a handle to it, but write fails.
Just learn a bit of Setup API, and I would like to know, how to use Setup API or DeviceEntry()
to access and write to K8055N to do the same as

opendevice();
SetDigitalChannel(5);
ClearDigitalChannel(5);

Thanks inadvance

derek

I don’t recall if the code for the Version 5 of the DLL has been published anywhere.

There is a link to the Version 4.0.0.2 source code here: viewtopic.php?f=3&t=7405#p27681

Let me know if you have trouble reading Pascal. I have C code (MinGW) laying around that does the same.

That should get you started.

However, note that the K8055N together with the DLL version 5 switches to a different HID message protocol, that can read back the current output ports and communicates faster. You will need to know that new protocol if you want to use the full speed of the K8055N. If you use it with the protocol of the 4.0 DLL, it will be just as slow as the old K8055.

I never looked at that new protocol since I run my own firmware in PIC18F25(K)50 chips. It can do a few more tricks than the originals, but requires more complicated PC side communication, which is not ready for prime time yet. I currently have a “network server” written in Python that can run on Windows or Unix. The communication on the application side therefore is TCP/IP and text based, not binary USB. The server does all the translation. And it can run local or remote, so I can work with cards in another room.

Regards,
Jan

I think this will explain things:

hdl_device = CreateFile( ptr_detail_data->DevicePath, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); FILE_FLAG_OVERLAPPED: The file or device is being opened or created for asynchronous I/O.

WriteFile(ptr_detail_data->DevicePath, (char *)str, sizeof(str), &bytesWritten, NULL); WriteFile
Return value: If the function succeeds, the return value is nonzero (TRUE). If the function fails, or is completing asynchronously, the return value is zero (FALSE). To get extended error information, call the GetLastError function.

So either not use asynchronous IO, or perform an asynchronous write.

On a sidenote: You should use TRUE and FALSE when using the Windows API, not true and false

hi,

thank you jan and VEL448 for your answers,

If possible jan, C code version of the dll

yes I should use FALSE instead of false, but it works just as well,

I just found this web page

http://openprog.altervista.org/USB_firm_eng.html

and need to learn HID’s

am hoping, to make a small robot arm/hand, with OpenCV for vision and SpeechAPI 5.4 for Listening

Thank you again

derek

Derek,

jannicash.info/k8055/download/Wi … source.zip

In that archive is a file client\k8055io.c. At the bottom of that file are Windows and Unix versions of all the Device…() functions of the DLL, which perform the low level USB communication, one HID packet at a time. There is also a file k8055d.c, which implements a drop-in replacement of the 4.0 DLL on top of k8055io.c.

Regards,
Jan

[quote=“dwk”]and need to learn HID’s

am hoping, to make a small robot arm/hand, with OpenCV for vision and SpeechAPI 5.4 for Listening[/quote]

If you intend to actually control that robot arm with a K8055N, you should also take a look at the Open8055 firmware that I am creating. It uses a different HID message format than the original cards, but it already has the ability to control up to 8 standard hobby servos on the digital outputs. I have tested that function with a Futaba S3003 servo and it works very well. No erratic movement of the servo.

All you need to run that firmware is a PIC18F25K50 and a PICKIT-3 programmer to load the HID-bootloader or the firmware into it. No modifications to the K8055N board are necessary. That chip is a 100% compatible replacement. It also works on the original K8055 after removing resistor R35. It compiles with the free version of the Microchip C18 compiler.

If you already have a PIC programmer but an older model, the PIC18F25K50 might not be supported. In that case, a PIC18F2550 works on both boards as well, but on the old K8055 the crystal and its two capacitors need to be replaced. It still would be a zero-board modification upgrade on the K8055N.

I currently don’t have complete working PC libraries as I am moving with that to a TCP/IP client-server model for several reasons. I will post a full update in the Open8055 firmware thread when I have things a little more complete.

In any case, the servo control code in the Open8055 firmware is entirely interrupt based. Since it is open source under a BSD style license, you are very welcome to copy any code pieces, you find useful, into your own firmware.

thank you jan again,

the c++ source code of the k8055 dll will help

I have the PICKIT 1 and 2 and yes I will get kit 3 and download Open8055 firmware…

the plan is at first, to use k8055n board, and then use others,

I am currently using the PIC16 from PICKIT 1, and will soon write code to allow setup api to control the pic16 on its own breadboard

am hoping to create an new thread soon, where anyone can added k8055 pic16 and pic18 examples
like this page

http://www.waitingforfriday.com/index.php/Building_a_PIC18F_USB_device

k8055n can be used for so many project, there should be a thread, to show a list of all projects

thank you again jan, can’t wait to break down the dll code

derek

You are most welcome.

I have successfully programmed the HID bootloader as well as the Open8055 firmware into a PIC18F2550 with a really old “Serial PIC-PG2”. I know that this particular programmer does NOT work with the new PIC18F25K50. I think the PICKIT-3 supports all ICSP programmable PICs by design. Not sure about the PICKIT-2, but I would expect it to deal with a 2550.

I agree, there should be such a subforum or at least a sticky listing all the projects, users have done with the K8055. Let me see if I can do something in that direction.