USB that is not a COMM port

For issues with communication ports, protocols, etc.
BrianKudsk
Posts: 24
Joined: Sep 08, 2010 20:27
Location: Florida

USB that is not a COMM port

Postby BrianKudsk » Sep 11, 2010 18:14

I have received help from phishguy on how to talk to a COMM port, however this latestdevice I am trying to talk to shows up as a HID. It apparently has a built in microcontroller. So now COMM, I would like to talk to it in FreeBasic and not get into C or any other program language if I can.
The device is a 24 bit DIO card from CyberReasearch. The UMDIO 24L
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Postby phishguy » Sep 11, 2010 21:55

From looking at the documentation and installing the driver files, there appears to be a Visual Basic example of using the CBW32.DLL file to communicate with this card. It doesn't look like it would be too difficult to convert this to work with Freebasic. The file name of the example function declarations CBW.BAS and there are numerous example files for communicating with different models of their cards.
BrianKudsk
Posts: 24
Joined: Sep 08, 2010 20:27
Location: Florida

USB that is not a COMM Port

Postby BrianKudsk » Sep 12, 2010 1:46

phishguy to the rescue. Did you get that from the CyberResearch web site?
I went there and downloaded the manual for the part but didn't see what you are talking about. Did I not dig deep enough?
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Postby phishguy » Sep 12, 2010 1:54

Here's the link to the downloads. I downloaded the universal driver library, which has the DLL and the example programs.

http://www.cyberresearch.com/store/download.aspx?prodid=5100
BrianKudsk
Posts: 24
Joined: Sep 08, 2010 20:27
Location: Florida

Postby BrianKudsk » Sep 12, 2010 2:06

Funny thoing , same area I downloaded the manual from. Got in a hurry to get running
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » Sep 12, 2010 4:17

I created an import library (even though using Lib “dllname” in the declaration will also work) and tested the DLL as well as I could without the actual hardware. The DLL has 6000+ exports and all but ~120 have what appear to be C++ decorated names, and CBW.BAS declares ~100 of these. Here are the batch files I used to create a module definition file and import library for the DLL (remember to delete the decorated names from the DEF file before creating the import library).

Code: Select all

@echo off
set basename="cbw32"
path=C:\MinGW\bin;%path%
@echo on
pexports %basename%.dll > %basename%.dll.def
pause

Code: Select all

@echo off
set basename="cbw32"
path=C:\Program Files\FreeBASIC\bin\win32;%path%
@echo on
dlltool -k -d %basename%.dll.def -l lib%basename%.dll.a
pause

And a test app that declares and calls two functions that should work without the hardware.

Code: Select all

#inclib "cbw32"

extern "windows-MS"

declare function cbGetRevision( _
              byref DLLRevNum as single, _
              byref VXDRevNum as single ) as integer

declare function cbCStatus( _
              byval BoardNum as longint, _
              byval CounterNum as longint , _
              byref StatusBits as longint ) as integer
end extern

dim as single drn, vrn
dim as longint statbits

print cbGetRevision( drn, vrn ), drn, vrn

print cbCStatus( 0, 0, statbits )

sleep


Code: Select all

 0             5             5
 126
BrianKudsk
Posts: 24
Joined: Sep 08, 2010 20:27
Location: Florida

Postby BrianKudsk » Sep 12, 2010 11:36

As I was looking through my old QB code I realized that the CyberReasearch cards that I used were ISA plug ins in I used the address to talk with them ; IE three 8 bit ports plus one or the configuration. They never were COMM ports. On this project I am doing most of the work and the final deployment on an XP based HP laptop. Hence all of the new issues. This new part (CyberReasearch) uses the same chip , a 8255 part ,24 bit IO .
I will try to understand and implement the latest post(code)
I am somewhat concerned in any Windows based app.
Thanks
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Postby phishguy » Sep 13, 2010 20:08

Since it is only a DIO interface, I believe the main fuctions that you would need to use are:

CbDConfigPort
CbDIn
CBDOut

So, since you aren't using all the functions in the universal driver, you would probly only need to declare these along with the status and revision functions that MichaelW posted.
BrianKudsk
Posts: 24
Joined: Sep 08, 2010 20:27
Location: Florida

Postby BrianKudsk » Sep 13, 2010 20:12

I am working on that now. Found the CBW file.
I think part of my struggle is I do not have the FB IDE setup correctly. It chokes on external stuff.
BrianKudsk
Posts: 24
Joined: Sep 08, 2010 20:27
Location: Florida

Postby BrianKudsk » Sep 13, 2010 20:28

Again I think that my IDE is not setup correctly. It chokes on MichaelW code.
The first choke is on line 3 set basename="cbw32".
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » Sep 13, 2010 20:36

Those are batch (.BAT) files.

http://en.wikipedia.org/wiki/Batch_file
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Postby phishguy » Sep 13, 2010 21:13

Instead of using an import library, you can declare the functions directly. Here is an example. I am not 100% sure if the declarations are correct and am unable to test without the hardware. But, it does compile.

Code: Select all

'/* Types of digital input ports */
#define DIGITALOUT       1
#define DIGITALIN        2

'define IO ports
#define AUXPORT          1
#define FIRSTPORTA       10
#define FIRSTPORTB       11
#define FIRSTPORTCL      12
#define FIRSTPORTC       12
#define FIRSTPORTCH      13
#define SECONDPORTA      14
#define SECONDPORTB      15
#define SECONDPORTCL     16
#define SECONDPORTCH     17
#define THIRDPORTA       18
#define THIRDPORTB       19
#define THIRDPORTCL      20
#define THIRDPORTCH      21
#define FOURTHPORTA      22
#define FOURTHPORTB      23
#define FOURTHPORTCL     24
#define FOURTHPORTCH     25
#define FIFTHPORTA       26
#define FIFTHPORTB       27
#define FIFTHPORTCL      28
#define FIFTHPORTCH      29
#define SIXTHPORTA       30
#define SIXTHPORTB       31
#define SIXTHPORTCL      32
#define SIXTHPORTCH      33
#define SEVENTHPORTA     34
#define SEVENTHPORTB     35
#define SEVENTHPORTCL    36
#define SEVENTHPORTCH    37
#define EIGHTHPORTA      38
#define EIGHTHPORTB      39
#define EIGHTHPORTCL     40
#define EIGHTHPORTCH     41
Extern "windows-MS"

Declare Function cbGetRevision Lib "cbw32"  ( _
Byref DLLRevNum As Single, _
Byref VXDRevNum As Single ) As Integer

Declare Function cbCStatus Lib "cbw32" ( _
Byval BoardNum As Longint, _
Byval CounterNum As Longint , _
Byref StatusBits As Longint ) As Integer

Declare Function cbDConfigPort Lib "cbw32" ( _
ByVal BoardNum as longint, _
ByVal PortNum as longint, _
ByVal Direction as longint) As Long

Declare Function cbDIn Lib "cbw32" ( _
Byval BoardNum As Longint, _
Byval PortNum As Longint, _
DataValue As Short) As Long   

Declare Function cbDOut Lib "cbw32" ( _
Byval BoardNum As Longint, _
Byval PortNum As Longint, _
Byval DataValue As Short) As Long

End Extern
Dim As Single drn, vrn
Dim As Longint statbits

Print cbGetRevision( drn, vrn ), drn, vrn

Print cbCStatus( 0,0, statbits )

'set firstporta to output
print cbDConFigPort(0,firstporta,digitalout)

'set all bits high
print cbDOut(0,firstporta,&hff)


Sleep





<edit>
The declaration for cbDIn isn't correct. I believe that it should be a pointer for the data value.
BrianKudsk
Posts: 24
Joined: Sep 08, 2010 20:27
Location: Florida

Postby BrianKudsk » Sep 14, 2010 0:57

Thanks guys.
I will try these first thing in the morning. I have to admit this is sort of trail by fire. Short deadline and much to learn.
I almost gave up and went back to an embedded 486 PC 104 . Comfort zone and all.
BrianKudsk
Posts: 24
Joined: Sep 08, 2010 20:27
Location: Florida

Postby BrianKudsk » Sep 14, 2010 17:53

Copied and pasted.
The IDE found and error with Extern "windows-MS"
I am using the IDE that bundled FB with it.
Perhaps I will try the command line compiler to see if it truly is a setup issue.
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Postby phishguy » Sep 14, 2010 18:08

What version of Freebasic are you using? The one bundled with FBIDE is quite old. The IDE itself would not give this problem. I used FBIDE and Freebasic version 0.21 and it compiles without problems.

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 1 guest