Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Dec 13, 2019 10:14 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Example code for USB port?
PostPosted: Tue Jun 09, 2009 6:15 am 
Offline

Joined: Fri Sep 30, 2005 5:54 pm
Posts: 2055
Location: Great Falls, Montana USA
Does any one have a example of how to connect to USB? I know it is a serial port, but I need just a good example of how to connect to a USB port.

I want to connect a PIC18F2550 chip to my PC via USB. I want to code it in RB, so I need an example on how to connect to the USB port.

Since the code will be sending Serial information, either Serial or USB should work without much trouble. A LPT port (Printer Port) on the other hand, would mean I would have to have two different code methods to send data, one for Serial and one for Parallel. I want to stick with one code as it will be hard enough with one, two would drive me crazy :shock:

Can anyone help me on this one?

_________________
Jonathon Bevar
REALDevelopment: http://www.semielectronics.com/realdevelopment
SemiElectronics http://www.semielectronics.com

RB2005 R4 Pro for Windows XP Pro/SP2
RB2010 R2.1 Studio Enterprise Edition


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Tue Jun 09, 2009 8:23 am 
Offline
User avatar

Joined: Thu Mar 05, 2009 1:03 pm
Posts: 1786
Location: USA
The Serial object might work for that... I doubt it, though, as it only appears to work for Serial ports and I don't think USB ports count. You might need API calls... I will research this later today and see what I can turn up.

_________________
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip! :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Tue Jun 09, 2009 8:27 am 
Offline
User avatar

Joined: Thu Mar 05, 2009 1:03 pm
Posts: 1786
Location: USA
Wow. I am really stunned right now... Serial should work.

http://www.control.com/thread/1026244534
says it all...

I have *got* to try this on my laptop - 2 USB ports there... will post my results once I get them.

_________________
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip! :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Tue Jun 09, 2009 12:16 pm 
Offline
User avatar

Joined: Thu Mar 05, 2009 1:03 pm
Posts: 1786
Location: USA
System.SerialPortCount=1 on my 2-USB port laptop, and the port it was looking at was COM3, not even a USB port. Serial appears to be out of luck here... I guess it's going to have to be API calls? Even the LR doesn't mention USB ports... :(

_________________
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip! :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Tue Jun 09, 2009 12:19 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
CF, USB is complex. You need something plugged in and a driver to talk to. Serial is fine as long as the device you plug in represents itself as a serial port.


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Tue Jun 09, 2009 2:06 pm 
Offline
User avatar

Joined: Thu Mar 05, 2009 1:03 pm
Posts: 1786
Location: USA
timhare wrote:
You need something plugged in and a driver to talk to.

Stuck in a U3 flash drive that works like a charm for me, then ran my code snippet again. System.SerialPortCount persistently ignored the flash drive...
timhare wrote:
Serial is fine as long as the device you plug in represents itself as a serial port.

Apparently this one didn't... and I suspect Jonathon is looking for a fool-proof solution, not a solution that only works for certain devices. Back to API calls... :(

_________________
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip! :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Tue Jun 09, 2009 2:12 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
If the device is connected and a driver installed such that the device shows up as a COM port, then RB's Serial control is perfect for the job. Most usb devices do not represent themselves as a serial port, this one appears to do so, at least from what I have seen on the web.

Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Tue Jun 09, 2009 6:35 pm 
Offline

Joined: Fri Sep 30, 2005 5:54 pm
Posts: 2055
Location: Great Falls, Montana USA
CF and Tim,

It would be nice so that all devise connected would show up. But in my case I am using a 18F25550 PIC chip that has built in USB. But I am not sure if it has the FDI chip so the USB will show as Serfiel on computers.

Although it must as most of the schematics I have read from others on the 18F2550 it is driect connected and the program codes (mostly C++) us the seriel port commands, like RB does.

CF, did you find a usb RB code to start with?

_________________
Jonathon Bevar
REALDevelopment: http://www.semielectronics.com/realdevelopment
SemiElectronics http://www.semielectronics.com

RB2005 R4 Pro for Windows XP Pro/SP2
RB2010 R2.1 Studio Enterprise Edition


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Tue Jun 09, 2009 7:50 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
computerfreaker wrote:
Stuck in a U3 flash drive that works like a charm for me, then ran my code snippet again. System.SerialPortCount persistently ignored the flash drive...

Makes perfect sense
I'd bet you have a new volume (or hard drive) being reported though

USB, is "serial" only in that's how it sends data
For 99.9% of the rest of the usage it depends on the driver how you interact with it
If the USB device happens to be an HD (or flash drive) it will never show up as a "serial device" - it's a hard drive that happen to use USB
Same for a keyboard or mouse. They'll show up as other kinds of human interaction devices
IF your USB device IS really a serial device (like the modem I have for my MacBook is or the Keyspan serial port device I have is) then it will show up in the Serial devices

And, for nearly every other USB device if it has no driver you wont be able to talk to it at all
Some are built in to the OS (like mass storage or hard drives, keyboards, mice and many other very common ones)

USB is NOT like "serial ports" in the old days
With those you could actually flip lines hi and lo and YOU control physical hardware
USB is NOT like that at all unless you write a driver

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Tue Jun 09, 2009 7:57 pm 
Offline

Joined: Fri Sep 30, 2005 5:54 pm
Posts: 2055
Location: Great Falls, Montana USA
So I need a USB Driver then? Is there such a thing for RB as an example code that has a USB driver with it? There has to be someone out there that has done this already?

_________________
Jonathon Bevar
REALDevelopment: http://www.semielectronics.com/realdevelopment
SemiElectronics http://www.semielectronics.com

RB2005 R4 Pro for Windows XP Pro/SP2
RB2010 R2.1 Studio Enterprise Edition


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Wed Jun 10, 2009 12:39 am 
Offline
User avatar

Joined: Tue Mar 17, 2009 8:53 am
Posts: 751
Jonathon wrote:
So I need a USB Driver then?

If the chip in question does not present itself as a serial port then you might need to consult its specs to figure out exactly how you're supposed to drive its USB.

It might be that you only need an adaptor that lets you plug a USB plug into a serial port. You can probably get one from Maplins or Radio Shack or whatever.

Writing a driver would be hard. That's not to say you shouldn't do it - (I have no idea of your level of expertise) - but a driver for XP will likely not work on XP64, and Win7 won't let you install it anyway unless it's been signed by Microsoft.

_________________
No thanks, I don't want to buy any plugins.


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Wed Jun 10, 2009 6:47 am 
Offline

Joined: Fri Sep 30, 2005 5:54 pm
Posts: 2055
Location: Great Falls, Montana USA
Well, from the information I got from Microchip, the PIC18F2550 and PIC18F4550 chips have all the Serial to USB coded into the chips aready so all one needs is a normal USB cable from the PIC device to the PC.

Ok, we got that confirmed!

Now what I am asking is there any USB to Serial (or Serial to USB) code created already that works in RB? I am not looking for the complete code written for me , I just want to know how to talk to the serial port to find the pic device and then read/write to it.

Anyone have any clues to this?

_________________
Jonathon Bevar
REALDevelopment: http://www.semielectronics.com/realdevelopment
SemiElectronics http://www.semielectronics.com

RB2005 R4 Pro for Windows XP Pro/SP2
RB2010 R2.1 Studio Enterprise Edition


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Wed Jun 10, 2009 6:54 am 
Offline
User avatar

Joined: Thu Mar 05, 2009 1:03 pm
Posts: 1786
Location: USA
npalardy wrote:
Makes perfect sense
I'd bet you have a new volume (or hard drive) being reported though

Yes, that is the case.
npalardy wrote:
If the USB device happens to be an HD (or flash drive) it will never show up as a "serial device" - it's a hard drive that happen to use USB
Same for a keyboard or mouse. They'll show up as other kinds of human interaction devices
IF your USB device IS really a serial device (like the modem I have for my MacBook is or the Keyspan serial port device I have is) then it will show up in the Serial devices

And, for nearly every other USB device if it has no driver you wont be able to talk to it at all

That's apparently what happened here...

Jonathon wrote:
CF, did you find a usb RB code to start with?

Unfortunately, no. I did find some VB6 code, though... http://www.control.com/thread/1026215375
Regrettably, the guy who has the code wants e-mail addresses to send the code to, as he apparently has no intention of putting it on the webpage... and it looks like that might not be a solution anyway, judging from the other posts on this thread.

Bessie wrote:
If the chip in question does not present itself as a serial port then you might need to consult its specs to figure out exactly how you're supposed to drive its USB.

It might be that you only need an adaptor that lets you plug a USB plug into a serial port. You can probably get one from Maplins or Radio Shack or whatever.

Writing a driver would be hard. That's not to say you shouldn't do it - (I have no idea of your level of expertise) - but a driver for XP will likely not work on XP64, and Win7 won't let you install it anyway unless it's been signed by Microsoft.

So, in summary, here's what I'm seeing in this.
If you want to talk to a USB device, you'll need to either A. figure out how to interact with the built-in driver (if there is one) or B. write your own driver. And if you write your own driver, you'll need about a million different drivers to support all the USB devices out there; then you'll need to figure out how to get them to work on Windows, Mac & Linux, and then you'll need to figure out how to port those drivers so they'll work with other OS versions. Finally, you'll need to get M$ to digitally sign your Windows USB drivers so you can use it on Windows 7...
I'm no expert with USB stuff, but I'd say my analysis, grim as it is, is probably somewhere near the truth... although API calls could be more helpful? Unfortunately, though, I have no idea what API's you'd need... :oops: :cry:
The situation would be simpler, though, if you only need support for one USB device (which I think is what you're saying, but idk for sure) or type of USB device; the situation would also be simpler if you only need support for 1 or 2 OS's. Can you toss us a few more details?

computerfreaker

_________________
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip! :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Wed Jun 10, 2009 6:58 am 
Offline
User avatar

Joined: Thu Mar 05, 2009 1:03 pm
Posts: 1786
Location: USA
Looks like Jonathon beat me to the post... lol

Jonathon wrote:
Well, from the information I got from Microchip, the PIC18F2550 and PIC18F4550 chips have all the Serial to USB coded into the chips aready so all one needs is a normal USB cable from the PIC device to the PC.

That's hopeful! :)
Try this code snippet with and without the USB device connected; if the message is different with the USB device plugged in than it is with the USB device unplugged, you're good to go.
'Window1.Open
MsgBox str(System.SerialPortCount)


Jonathon wrote:
Now what I am asking is there any USB to Serial (or Serial to USB) code created already that works in RB? I am not looking for the complete code written for me , I just want to know how to talk to the serial port to find the pic device and then read/write to it.

If the USB device does in fact support serial communications (which the above snippet should tell you), you should be able to use a standard Serial object... if not, then idk what to do.

_________________
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip! :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Example code for USB port?
PostPosted: Wed Jun 10, 2009 7:01 am 
Offline
User avatar

Joined: Tue Mar 17, 2009 8:53 am
Posts: 751
Jonathon wrote:
Well, from the information I got from Microchip, the PIC18F2550 and PIC18F4550 chips have all the Serial to USB coded into the chips aready so all one needs is a normal USB cable from the PIC device to the PC.

I assume that means that the chip presents itself as a serial port? If so, the built-in Serial class ought to just work. Is that not the case?

_________________
No thanks, I don't want to buy any plugins.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group