|
-
Apr 28th, 2010, 10:40 AM
#1
Thread Starter
PowerPoster
Not serial...USB
I have this bit of code that displays what is coming through the serial port. Now, the company has bought a box that connects via USB. So, the question becomes: "what has to be changed to monitor the USB port"?
Code:
Option Explicit
Private Sub Command1_Click()
With MSComm1
'make sure the serial port is open
If .PortOpen = False Then .PortOpen = True
'send the data (including a tailing carriage return as often needed)
.Output = Text2.Text & vbCr
End With 'MSComm1
With Text2
'place the focus back to the textbox
.SetFocus
'select the current text to be overwritten
.SelStart = 0
.SelLength = Len(.Text)
End With 'Text1
End Sub
Private Sub Form_Load()
With MSComm1
'make sure the serial port is not open (by this program)
If .PortOpen Then .PortOpen = False
'set the active serial port
.CommPort = 1
'set the badurate,parity,databits,stopbits for the connection
.Settings = "19200,N,8,1"
'set the DRT and RTS flags
.DTREnable = True
.RTSEnable = True
'enable the oncomm event for every reveived character
.RThreshold = 1
'disable the oncomm event for send characters
.SThreshold = 0
'open the serial port
.PortOpen = True
End With 'MSComm1
With Text1
'set the properties for the displaying textbox
.BackColor = vbCyan
.Locked = True
.Text = ""
End With 'Text1
With Text2
'set the properties for the 'send' textbox
.TabIndex = 0
.Text = ""
End With 'Text2
With Command1
'set the properties for the 'send' command button
.Caption = "&Send"
.Default = True
.TabIndex = 1
End With 'Command1
End Sub
Private Sub Form_Resize()
Dim sngWidth As Single, sngHeight As Single
Dim sngDisplayHeight As Single
Dim sngTxtWidth As Single
Dim sngCmdWidth As Single, sngCmdHeight As Single
'calculate the inner size of the form
sngWidth = ScaleWidth
sngHeight = ScaleHeight
With Command1
'resize and reposition the command button
sngCmdHeight = .Height
sngCmdWidth = .Width
sngDisplayHeight = sngHeight - sngCmdHeight
sngTxtWidth = sngWidth - sngCmdWidth
.Move sngTxtWidth, sngDisplayHeight, sngCmdWidth, sngCmdHeight
End With 'Command1
'resize and reposition the label
Text1.Move 0, 0, sngWidth, sngDisplayHeight
'resize and reposition the textbox
Text2.Move 0, sngDisplayHeight, sngTxtWidth, sngCmdHeight
End Sub
Private Sub Form_Unload(Cancel As Integer)
MsgBox Text1.Text
End Sub
Private Sub MSComm1_OnComm()
Dim strInput As String
With MSComm1
'test for incoming event
Select Case .CommEvent
Case comEvReceive
'display incoming event data to displaying textbox
strInput = Asc(.Input)
Text1.SelText = strInput
End Select
End With 'MSComm1
End Sub
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Apr 28th, 2010, 11:21 AM
#2
Re: Not serial...USB
Does this MSDN page help? Sounds like it may not be doable if the page applies. However, reading other threads and some googling, it appears whether it works or not is up to the driver that comes with USB device? I'd recommend doing some more searching; this is not in my realm of experience.
-
Apr 28th, 2010, 11:31 AM
#3
Thread Starter
PowerPoster
Re: Not serial...USB
Thanks for the reply. More research is definitely called for.
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Apr 28th, 2010, 11:35 AM
#4
Re: Not serial...USB
 Originally Posted by Pasvorto
Thanks for the reply. More research is definitely called for.
My google search terms were: mscomm usb serial
-
Apr 28th, 2010, 11:44 AM
#5
Thread Starter
PowerPoster
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Apr 28th, 2010, 12:18 PM
#6
Fanatic Member
Re: Not serial...USB
If the 'box' just exposes more 'com ports' like this:-

Then you shouldn't need to do much at all. Once the device driver for the box is installed then you'll just have more com ports.
Is that type of box you're talking about ?
I've used this box before - on the back is the USB connection - it comes with a 1 meter usb cable, plug one end of the cable into the box and the other into a USB port on the computer - install the drivers and suddenly you have 4 more com ports.
-
Apr 28th, 2010, 12:34 PM
#7
Thread Starter
PowerPoster
Re: Not serial...USB
Maybe. I have not seen the box yet.
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Apr 28th, 2010, 12:47 PM
#8
Fanatic Member
Re: Not serial...USB
 Originally Posted by Pasvorto
Now, the company has bought a box that connects via USB.
 Originally Posted by Pasvorto
Haven't seen the box yet
If "The Company" expects you to make physical connections with the same external peripherals/devices then I guess it's likely a USB-to-RS232 box in which case you probably won't need to do much - maybe just change the port numbers (The new ports may be numbered 5, 6, 7 and 8)
-
Apr 28th, 2010, 01:10 PM
#9
Thread Starter
PowerPoster
Re: Not serial...USB
It will be interesting, for sure. It is not expected to be attached for a few days.
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Apr 28th, 2010, 01:27 PM
#10
Re: Not serial...USB
From what I read, mscomm only supports ports 1-16. If your USB reports ports in a range higher than that, there is a ocx hack that appears to work. Here is something worth bookmarking until you know for sure either way.
-
Apr 28th, 2010, 01:40 PM
#11
Thread Starter
PowerPoster
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Apr 30th, 2010, 01:21 PM
#12
Fanatic Member
Re: Not serial...USB
If the USB interface is a USB serial adapter (Virtual Serial Port), then your code shouldn't have to change. On occasion USB VSPs assign port number higher than 16, thus you would need a modified version of MSComm32.ocx to use these higher port numbers. I provide the detail for this in my book, along with the modified ocx. If you send me email, I will send you the actual control.
Dick
Richard Grier, Consultant, Hard & Software
Microsoft MVP (Visual Basic)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|