|
|
View previous topic :: View next topic |
Author |
Message |
just4ho Guest
|
bulk usb demo |
Posted: Sun Mar 25, 2007 11:04 pm |
|
|
Hi everybody
I'm writing a PC software for the CCS bulk usb driver. I want to know the driver link name for the API call CreateFile.
(driver link name, _
GENERIC_READ, _
0, 0, _
OPEN_EXISTING, _
FILE_ATTRIBUTE_NORMAL, 0&)
does anybody has an Idea? |
|
|
embcoder
Joined: 13 Jun 2007 Posts: 2 Location: Maryland
|
usb bulk demo MS Visual C++ 6.0 code |
Posted: Wed Jun 13, 2007 7:20 am |
|
|
I don't know Pascal (their source code) as used in the Oscope program.
I'm trying to communicate using the following two sets of code. Although both appear to work at the PC end, the PIC says no go. Its been some time since you posted, so perhaps you've figured this all out and can help me.
Les
Code: | // usb.cpp : Defines the entry point for the console application.
//
#include <stdafx.h>
#include <windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
FILE* fpointer;
HANDLE hCmdInterface;
char data[512];
int count;
char db[2];
ULONG iRet;
BOOL fRet;
db[0] = 22;
db[1] = 0;
// METHOD ONE
hCmdInterface = NULL;
hCmdInterface = CreateFile ("CCS USB Demo", // Pointer to the name of the port
GENERIC_READ | GENERIC_WRITE, // Access (read-write) mode
FILE_SHARE_READ | FILE_SHARE_WRITE, // Share mode
NULL, // Pointer to the security attribute
OPEN_EXISTING,// How to open the serial port
0, // Port attributes
NULL); // Handle to port with attribute
fRet = WriteFile(hCmdInterface, db, 2, (ULONG*)&iRet, NULL);
fRet = ReadFile(hCmdInterface, data, 256, (ULONG*)&iRet, NULL);
CloseHandle(hCmdInterface);
// METHOD TWO
fpointer = fopen("CCS USB Demo", "w+");
count = fwrite (db, 1, 2, fpointer);
count = fread(data, 1, 256, fpointer);
fclose (fpointer);
//printf("Hello World!\n");
return 0;
} |
|
|
|
embcoder
Joined: 13 Jun 2007 Posts: 2 Location: Maryland
|
Bulk Demo working with MS Visual C++ |
Posted: Thu Jun 14, 2007 10:05 am |
|
|
I spoke with Mark in Tech support this morning. The correct name for the USB bulk driver is in the following code:
Code: | // t1.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <stdafx.h>
#include <windows.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hCmdInterface;
char data[512];
char db[2];
ULONG iRet;
BOOL fRet;
db[0] = 22;
db[1] = 0;
memset(data, 0, sizeof(data)); // zero out the data space
hCmdInterface = NULL;
/*
// ASCII form
hCmdInterface = CreateFileA ("\\\\.\\BulkUsbDemoDevice0", // Pointer to the name of the port
GENERIC_READ | GENERIC_WRITE, // Access (read-write) mode
FILE_SHARE_READ | FILE_SHARE_WRITE, // Share mode
NULL, // Pointer to the security attribute
OPEN_EXISTING,// How to open the serial port
0, // Port attributes
NULL); // Handle to port with attribute
*/
// UNICODE form
hCmdInterface = CreateFile (TEXT("\\\\.\\BulkUsbDemoDevice0"), // Pointer to the name of the port
GENERIC_READ | GENERIC_WRITE, // Access (read-write) mode
FILE_SHARE_READ | FILE_SHARE_WRITE, // Share mode
NULL, // Pointer to the security attribute
OPEN_EXISTING,// How to open the serial port
0, // Port attributes
NULL); // Handle to port with attribute
fRet = WriteFile(hCmdInterface, db, 2, (ULONG*)&iRet, NULL); // must write the two bytes first!
fRet = ReadFile(hCmdInterface, data, 256, (ULONG*)&iRet, NULL);
CloseHandle(hCmdInterface);
return 0;
}
|
This code was written using MS Visual Studio 2005. Mark used the Delphi debugger to step through the CreateFile function in the Oscope program provided with the USB demo kit. Please note that the number of backslash characters is double what was showing in the Delphi code. It's just a 'C' thing. |
|
|
just4ho Guest
|
I have made Visual Basic version of Oscope software |
Posted: Wed Jun 27, 2007 9:23 pm |
|
|
I have solved the createfile issue for Visual Basic API and created an application. it's Visual Basic version of Oscope software. I'm sure many people were waiting for Visual Basic version of Oscope software. So I'll make it available for them.
Create a form and include 1 picturebox, 4 command button, 1 textbox and 1timer.
Then copy following code.
It works with ex_usb_scope.c
Code: |
Option Explicit
Private Const GENERIC_WRITE = &H40000000
Private Const GENERIC_READ As Long = &H80000000
Private Const INVALID_HANDLE_VALUE As Long = -1
Private Const OPEN_EXISTING As Long = 3
Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
Private Const MAX_PATH As Long = 260
Private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, _
lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, _
lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function WriteFile Lib "kernel32" ( _
ByVal hFile As Long, lpBuffer As Any, _
ByVal nNumberOfBytesToWrite As Long, _
lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hFile As Long) As Long
Dim hFile As Long
Dim bytArr(513) As Byte
Dim outArr(8) As Byte
Private Sub Command1_Click()
hFile = CreateFile("\\.\BulkUSBDemoDevice0", _
GENERIC_WRITE Or GENERIC_READ, _
0, 0, _
OPEN_EXISTING, _
FILE_ATTRIBUTE_NORMAL, 0&)
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
CloseHandle hFile
End Sub
Private Sub send_data()
Dim lSuccess As Long
Dim lBytesToWrite As Long
Dim lBytesWritten As Long
lBytesToWrite = 8
lSuccess = WriteFile(hFile, outArr(0), _
lBytesToWrite, lBytesWritten, 0)
End Sub
Private Sub Command3_Click()
If outArr(1) > 1 Then
If outArr(1) <128> 1 Then
outArr(1) = outArr(1) / 2
End If
send_data
End Sub
Private Sub Form_Load()
outArr(1) = 1
hFile = CreateFile("\\.\BulkUSBDemoDevice0", _
GENERIC_WRITE Or GENERIC_READ, _
0, 0, _
OPEN_EXISTING, _
FILE_ATTRIBUTE_NORMAL, 0&)
If hFile = -1 Then MsgBox "Could not connect to USB driver"
End Sub
Private Sub Timer1_Timer()
Dim sc As Long
Dim i As Long
Dim lSuccess As Long
Dim lBytesRead As Long
Dim lBytestoRead As Long
Text1.Text = outArr(1)
lBytestoRead = 512
lSuccess = ReadFile(hFile, bytArr(0), _
lBytestoRead, lBytesRead, 0)
sc = 511
Picture1.Cls
Picture1.Scale (8, 255)-(sc, 0)
Picture1.DrawWidth = 1
For i = 8 To sc Step 1
Picture1.Line (i, bytArr(i))-(i + 1, bytArr(i + 1)), &H80FF&
Next i
End Sub
|
|
|
|
kalle Guest
|
|
Posted: Sat Mar 15, 2008 3:43 pm |
|
|
Hi @ll,
could anybody please send me the usbdemo.sys driver? I searched the whole day, but did not find find it ...
Thank you very much in advance.
Email: e-techniker80@gmx.de
Best regards from Germany
P.S. Your VB6 Example is not working properly. There is a "End If" missing ... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|