Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
Go Back  Xtreme Visual Basic Talk > > > Frequently Asked COMMUNICATION Questions....


Closed Thread
 
Thread Tools Display Modes
  #1  
Old 08-27-2002, 02:00 PM
BillSoo's Avatar
BillSooFrequently Asked COMMUNICATION Questions.... BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default Frequently Asked COMMUNICATION Questions....


1) Where can I find more info about the winsock control? - Try here:
winsockvb.com on archive.org

2) Where can I find more info about the Serial port? - This is a good place to start:
http://www.lvr.com/serport.htm

3) Where can I find more info about the Parallel port? - Try this site:
http://www.lvr.com/parport.htm

4) How can I control the individual lines of a serial/parallel port? - You need to use a 3rd party control that allows you to use INP and OUT commands (these commands are in QBasic but not VB). You can find INPOUT32.DLL at www.lvr.com which gives you access to these commands.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

Last edited by webbone; 07-07-2008 at 06:37 PM. Reason: Updated winsockvb.com link
  #2  
Old 11-29-2003, 08:23 AM
BillSoo's Avatar
BillSooFrequently Asked COMMUNICATION Questions.... BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

I've attached the INPOUT32.DLL zip from Logix4u. This zip contains the DLL, the source code, some examples, documentation etc. This should help get you going with writing directly to the parallel or serial ports.
Attached Files
File Type: zip inpout32.zip (264.8 KB, 871 views)
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
  #3  
Old 09-15-2004, 10:44 PM
BillSoo's Avatar
BillSooFrequently Asked COMMUNICATION Questions.... BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

Some links to Tutorial articles:
Serial Port communications
Basic Serial Port Communications
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
  #4  
Old 05-13-2005, 04:15 AM
BillSoo's Avatar
BillSooFrequently Asked COMMUNICATION Questions.... BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default Setting the Baud Rate directly with INPOUT32.dll

Sometimes you need to set a baudrate that mscomm does not support. If you are lucky, then you can use the API and use getCommState and setCommState to set the baud rate to one of the predefined rates in Windows. But if your baud rate is not on the list then what?

Well, you might be able to use INPOUT32.dll (or similar product) to give you the INP and OUT functions that used to be available in QBasic. With these functions, you can address the port directly and change its divisor value, thereby changing its baud rate.

First, you should understand what the divisor is. The comm port has a crystal that oscillates at 115200 hz. This means that the fastest possible clock speed you are going to get will be 115200. This means that it is firing evey tick of the clock. For any other baud rate, the comm port simply waits n ticks before it fires. So the next fastest baud rate is 57600 since that is 115200/2, then 115200/3 or 38400. The divisor is the integer by which the base clock rate (115200) is divided to get the baud rate.

OK. To talk to the port, we need to know it's address. Normally, the base address of COM1 is &H3F8 and COM2 is &H2F8 but this is not always the case. You can check this by using the System applet in the control Panel to check the resources used by your com ports. It will tell you the address ranges it uses. Whatever the base address is, we will call it BaseAddr.

Next, we need to get INPOUT32.dll. You can find this above in the FAQ. All you need to do is copy INPOUT32.dll to your system directory and then add the following function declarations to your code:
Code:
Private Declare Function Inp Lib "inpout32.dll" _ Alias "Inp32" (ByVal PortAddress As Integer) As Integer Private Declare Sub Out Lib "inpout32.dll" _ Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)

Now add the following code:
Code:
Public Sub SetBaudDirect(ByVal BaseAddr As Integer, ByVal BaudRate As Long) Dim divisor As Integer Dim oldLCR As Integer Dim LCRaddr As Integer Dim divisorMSBaddr As Integer Dim divisorLSBaddr As Integer Dim msb As Integer Dim lsb As Integer divisorLSBaddr = BaseAddr divisorMSBaddr = BaseAddr + 1 LCRaddr = BaseAddr + 3 divisor = 115200\BaudRate msb = divisor \ 256 lsb = divisor MOD 256 oldLCR = InP(LCRaddr) 'save the old latch register values Out LCRaddr, (oldLCR Or &H80) 'make dlab=1 Out divisorMSBaddr,msb 'set the MSB of the divisor Out divisorLSBaddr,lsb 'set the LSB of the divisor Out LCRaddr, oldLCR 'restore the old latch values End Sub

One final caveat....on some occasions I found that after setting the baudrate, Windows set it back automatically. This did not happen all the time, but it did happen sometimes. So basically, I got into the habit of setting the baud rate immediately before I needed to use the port.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
  #5  
Old 05-31-2005, 12:17 AM
BillSoo's Avatar
BillSooFrequently Asked COMMUNICATION Questions.... BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

It is not possible to "spy" on a serial or parallel port being used by another application with pure VB. I *suspect* that you could do it in another language, but not in VB...

On the other hand, you CAN build a cable that "copies" the data flow to a SECOND port and then simply read that.

webbone found this link that describes how such a cable can be built:
http://www.lammertbies.nl/comm/cable...y-monitor.html

Here are the main points:
1) you cannot read a port being used by another app
2) you can build a "Y" cable that splits the data and sends a copy of it to a 3rd port
3) you can read EITHER the Rx OR Tx data with a single port but not both at once
4) if you need to see both Rx and Tx data at the same time, you need another spy port
5) you could build a cable that can switch between Rx and Tx data via a simple toggle switch
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
  #6  
Old 07-17-2005, 02:08 AM
BillSoo's Avatar
BillSooFrequently Asked COMMUNICATION Questions.... BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default Update to Direct Baud Rate Setting

I got a message from mkaras that pointed out some errors in my above post about setting the baud rate directly. Rather than rewrite it, I've decided to copy his message here:

Quote:
BillSoo:

In your string of postings in the CommTutorials section you had a piece on the setting of the baud rate for the COMM port by direct means using the INPOUT32 dll.

In this article you stated that the UART baud rate crystal was 115200 Hz and thus the fastest baud rate was thus 115200 bps (bits per second).

This is not actually true. From early PC days legacy COMM ports have used a crystal or oscillator frequency of 1.8432 MHz. A typical UART, including the PC UART, uses a clock rate that is 16 times faster than the actual baud rate. The divisor register in the PC UART actually holds a count that is used to divide the 1.8432 MHz master input clock down to the 16x rate used internal to the UART. The 16x rate is particularly important for the receiver section of a UART so that it can oversample the incoming serial data stream and find start bits, estimate the data bits center position and setup the optimum time to clock in the actual serial data stream.

You are correct that the legacy UART configuration in a PC has a top end baud rate of 115200 bps. There are however many newer hardware sets that support higher baud rates including 230400 bps, 460800 bps and others. The most common place to find this capability today is in some motherboard computer chipsets and in todays very common USB to RS232 adapter cables. I have some cables with drivers that support baud rates above 1000000 bps! Most times the higher baud rate capabilites come into play when the actual UART hardware is "hidden" from programmers that typically work with the likes of VB6 under Windows. The details of the non-legacy behavior of the UART are buried inside the Windows device drivers and so there is no need to be aware of how the 16x clocking is derived.

Good Luck
Michael Karas
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

Last edited by BillSoo; 07-20-2005 at 05:51 AM.
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions.... Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
 
Frequently Asked COMMUNICATION Questions....
Frequently Asked COMMUNICATION Questions....
 
-->