pgmfi.org

Hacking up Honda's ECU
It is currently Fri Mar 29, 2024 8:48 am

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Mar 12, 2009 9:05 am 
Offline

Joined: Thu Jan 31, 2008 12:18 am
Posts: 118
I just found out my VB course is not even going to touch the subject of serial or usb communication. is there some info or books that you guis coild point me to?.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2009 10:56 am 
Offline

Joined: Tue Jul 27, 2004 2:29 am
Posts: 474
Location: Baton Rouge, LA
I've actually found lots of good information on the internet.

Are you hell bent on learning VB? Personally, I prefer C# since my roots are in C, and C is a way more respected language than Basic or Visual Basic for that matter...

The point I'm trying to make is that I can post some serial port communication code for C# that can literally be implemented in 4 lines of code.

(Of course I'm utilizing the not yet universally supported .NET framework) but Microsoft actually does a fairly decent job of pushing these frameworks via windows update, so my experience in recent time has been good)

Nowadays, Microsoft has information on their knowledgebase with examples written in Visual Basic and C# so I'm sure that if you're more confortable with Basic, you can do it just as easily.

In the .NET framework, there is a SerialPort class, so writing to a serial port (and I don't have my code in front of me, so don't try this verbatim) is done something like this:

Code:
using System.Ports.IO

SerialPort DarrensPort = new SerialPort();
byte tempByte;

DarrensPort.BaudRate = 9600;
DarrensPort.StopBits = StopBits.One; //The number of stopbits is an enumerated data type, its pretty clean actually.
DarrensPort.Parity = Parity.None; //Parity is also enumerated

DarrensPort.Open();

DarrensPort.Write("Hello"); //While you can write a string to the serial port like this, keep in mind that strings in C# have the length of the string as the first character and that will get sent down the port.

DarrensPort.Write(0x55);

tempByte = DarrensPort.ReadByte();

char[] charArray = new char[DarrensPort.bytestoRead];

charArray = DarrensPort.ReadExisting();


I can post up real code when I have it in front of me, but that's basically how it goes.

I'm just now getting into doing native USB stuff, so as soon as I have that figured out I can post some information. From what I understand, USB is A LOT different. Every device has an address, and each device has a certain number of "Endpoints" and you can have multiple channels of data within those endpoints. I haven't dug too deep but I can easily see why it is a preferable method of communication since you can have one channel designated as a data channel with the other being a command channel, rather than having to find clever ways to mix the two like on a serial port.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2009 11:18 am 
Offline

Joined: Wed Mar 23, 2005 10:15 pm
Posts: 108
Location: Baton Rouge, LA
Type-GS-R-Turbo wrote:
I've actually found lots of good information on the internet.

Are you hell bent on learning VB? Personally, I prefer C# since my roots are in C, and C is a way more respected language than Basic or Visual Basic for that matter...

The point I'm trying to make is that I can post some serial port communication code for C# that can literally be implemented in 4 lines of code.

(Of course I'm utilizing the not yet universally supported .NET framework) but Microsoft actually does a fairly decent job of pushing these frameworks via windows update, so my experience in recent time has been good)

Nowadays, Microsoft has information on their knowledgebase with examples written in Visual Basic and C# so I'm sure that if you're more confortable with Basic, you can do it just as easily.

In the .NET framework, there is a SerialPort class, so writing to a serial port (and I don't have my code in front of me, so don't try this verbatim) is done something like this:

Code:
using System.Ports.IO

SerialPort DarrensPort = new SerialPort();
byte tempByte;

DarrensPort.BaudRate = 9600;
DarrensPort.StopBits = StopBits.One; //The number of stopbits is an enumerated data type, its pretty clean actually.
DarrensPort.Parity = Parity.None; //Parity is also enumerated

DarrensPort.Open();

DarrensPort.Write("Hello"); //While you can write a string to the serial port like this, keep in mind that strings in C# have the length of the string as the first character and that will get sent down the port.

DarrensPort.Write(0x55);

tempByte = DarrensPort.ReadByte();

char[] charArray = new char[DarrensPort.bytestoRead];

charArray = DarrensPort.ReadExisting();


I can post up real code when I have it in front of me, but that's basically how it goes.

I'm just now getting into doing native USB stuff, so as soon as I have that figured out I can post some information. From what I understand, USB is A LOT different. Every device has an address, and each device has a certain number of "Endpoints" and you can have multiple channels of data within those endpoints. I haven't dug too deep but I can easily see why it is a preferable method of communication since you can have one channel designated as a data channel with the other being a command channel, rather than having to find clever ways to mix the two like on a serial port.

are you kidding VB6.0 ftw.. lol

j/k


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2009 11:25 am 
Offline

Joined: Tue Jul 27, 2004 2:29 am
Posts: 474
Location: Baton Rouge, LA
*slaps head*


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2009 9:16 pm 
Offline

Joined: Thu Jan 31, 2008 12:18 am
Posts: 118
I'm on an intro to visual basic course now,we use VB8. In september I'll take the advance course fallowed by two C++ semesters. I'm on an electronic engineer course so i definitely need a way to communicate with my devices.

is usb supported by the serial port class?


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2009 10:38 pm 
Offline

Joined: Tue Jul 27, 2004 2:29 am
Posts: 474
Location: Baton Rouge, LA
Quote:
is usb supported by the serial port class?


Yes and no. In the straightforward hardcore USB sense, no. A USB port and a serial port are completely different animals. However there are lots of pieces of hardware out there (Moates, hondata, EFILive I think) to name a few that use a chip by the company FTDI. (http://www.ftdichip.com)

This chip, when connected to a USB port, creates a serial port on your computer. This serial port can be interfaced just like the standard issue serial ports we all used to know and love.

This makes it easy to have a "USB" device since coding for a serial port is a stroll in the park.

This is why when you plug an Ostrich into your computer it shows up under Ports (COM and LPT) in your Device Manager.

While it is easy to code and requires little setup on your microcontroller, the downside is performance. You'll never hit the 480Mbps that USB 2.0 claims to attain. This is because on the output of the FTDI chip, you are still sending serial data at the baud rate you specified in your code. When you code for 9600bps, on your best day you'll see less than 1KB/sec.

The questions you have to ask yourself is whether speed is what you need and otherwise, are you trying to impress anyone with the project.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group