Adding a 5ms delay in between sending bytes to a controller

  • Thread starter Thread starter cmdolcet69
  • Start date Start date
It looks like are attempting to use MSComm by late-binding. This really
isn't supported. If you want to use MSComm, add it to your toolbox and drop
it on the form. There are a few small syntax changes required.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardandsoftware.netfor details and contact information.

How do i do this in vb 2003
 
Just use the SerialPort control. Drop one on design surface.

With SerialPort1
.DTEnable = True
.RTSEnable = True
.BaudRate = 57600
.Parity = Parity.None
.DataBits = 8
.CommPort = PortName = "Com1"
End With

'then your code:

Dim i As Integer
Dim Packet(6) As Byte
Packet(0) = 42 'Hex 2A
Packet(1) = 6
Packet(2) = 7
Packet(3) = 28
Packet(4) = 45
Packet(5) = 48
Packet(6) = 130

For i = 0 To 6
Thread.Sleep(5)
SerialPort1.Write(Packet(i), 0, 1)
Next i

BTW, this also is "at the keyboard," so you will have to actually debug it.

Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardandsoftware.netfor details and contact information.

The problem is that all my previous code worked and i have mutiple
interface with this type of COM
There must be somthing missing in my comm1 properties setting
Public Sub SetupCOM(ByVal comPort As Integer)
'initialize the com if it has not been already
If IsNothing(comm1) Then
comm1 = New MSComm
End If
'set the properties of the com port
comm1.CommPort = comPort
comm1.Settings = "57600,n,8,1"
comm1.RTSEnable = True
comm1.DTREnable = True

'open the port and clear the buffer if it is not alread open
(which it better not be)
If Not comm1.PortOpen Then
comm1.PortOpen = True
comm1.InBufferCount = 0
System.Threading.Thread.CurrentThread.Sleep(100)
End If
End Sub


Public Sub GetIndicator_Info()

Dim Len As Byte = 6
Dim Cmd As Byte = 7
Dim loPass_byte As Byte = 28
Dim hiPass_byte As Byte = 45
Dim CRClo_byte As Byte = 48
Dim CRChi_byte As Byte = 130
Dim i As Integer

comm1.Output = BMS
Thread.Sleep(5)

Dim message(6) As Byte
message(0) = 6
message(1) = 7
message(2) = 28
message(3) = 45
message(4) = 130
message(5) = 48

For i = 0 To message.Length - 1
comm1.Output = message(i)
Thread.Sleep(5)
Next i

End Sub
 
Just use the SerialPort control. Drop one on design surface.

With SerialPort1
.DTEnable = True
.RTSEnable = True
.BaudRate = 57600
.Parity = Parity.None
.DataBits = 8
.CommPort = PortName = "Com1"
End With

'then your code:

Dim i As Integer
Dim Packet(6) As Byte
Packet(0) = 42 'Hex 2A
Packet(1) = 6
Packet(2) = 7
Packet(3) = 28
Packet(4) = 45
Packet(5) = 48
Packet(6) = 130

For i = 0 To 6
Thread.Sleep(5)
SerialPort1.Write(Packet(i), 0, 1)
Next i

BTW, this also is "at the keyboard," so you will have to actually debug it.

Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardandsoftware.netfor details and contact information.

a littl more information on this issue, when i set a braek point and
watch the value i get a comm1.ouput is not declared or the module
containg it is not loaded in the debuggin session. What does this mean
and how can i fix this?
 
Hi,

Download DesktopSerialIO.dll from my homepage. Use the Output method (it
has an overload for Byte arrays). The code would be quite similar to that
for the SerialPort object, though not exactly the same.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
Back
Top