How can i add a 5ms delay between bytes i send over to a controller?
I have to send 6 bytes in total however in between each byte i need to
have a 5ms delay. 23 6878
cmdolcet69 wrote:
How can i add a 5ms delay between bytes i send over to a controller?
I have to send 6 bytes in total however in between each byte i need to
have a 5ms delay.
I think you can just use Thread.Sleep (5).
So you're code would look like:
SendByteOne()
Thread.Sleep (5)
SendByteTwo()
Thread.Sleep (5)
SendByteThree()
Thread.Sleep (5)
etc...
See http://msdn2.microsoft.com/en-us/lib...ead.sleep.aspx
Cheers,
RB.
On Sep 20, 10:55 am, RB <owmdkbqziki...@mailinator.comwrote:
cmdolcet69 wrote:
How can i add a 5ms delay between bytes i send over to a controller?
I have to send 6 bytes in total however in between each byte i need to
have a 5ms delay.
I think you can just use Thread.Sleep (5).
So you're code would look like:
SendByteOne()
Thread.Sleep (5)
SendByteTwo()
Thread.Sleep (5)
SendByteThree()
Thread.Sleep (5)
etc...
Seehttp://msdn2.microsoft.com/en-us/library/system.threading.thread.slee...
Cheers,
RB.
RB, I was on the right path in thinking. I have been reading however
that it may be sloppy coding.....anyways.... how can i write it were i
use this delay with each byte i send across from a com.ouput command
example: com.output= (byte(1) + thead.sleep(5) + byte(2)+.......
?????
cmdolcet69 wrote:
On Sep 20, 10:55 am, RB <owmdkbqziki...@mailinator.comwrote:
>cmdolcet69 wrote:
>>How can i add a 5ms delay between bytes i send over to a controller? I have to send 6 bytes in total however in between each byte i need to have a 5ms delay.
I think you can just use Thread.Sleep (5).
So you're code would look like:
SendByteOne() Thread.Sleep (5) SendByteTwo() Thread.Sleep (5) SendByteThree() Thread.Sleep (5)
etc...
Seehttp://msdn2.microsoft.com/en-us/library/system.threading.thread.slee...
Cheers,
RB.
RB, I was on the right path in thinking. I have been reading however
that it may be sloppy coding.....anyways.... how can i write it were i
use this delay with each byte i send across from a com.ouput command
example: com.output= (byte(1) + thead.sleep(5) + byte(2)+.......
?????
You could use something similar to :
Dim i as integer
For i = 1 to 6
com.output = byte(i)
Thread.Sleep(5)
Next i
Be aware that this will cause AT LEAST a 5 ms delay per byte sending. It
may be longer - would this cause an issue?
Cheers,
RB.
On Sep 20, 11:05 am, RB <owmdkbqziki...@mailinator.comwrote:
cmdolcet69 wrote:
On Sep 20, 10:55 am, RB <owmdkbqziki...@mailinator.comwrote:
cmdolcet69 wrote: How can i add a 5ms delay between bytes i send over to a controller? I have to send 6 bytes in total however in between each byte i need to have a 5ms delay.
I think you can just use Thread.Sleep (5).
So you're code would look like:
SendByteOne()
Thread.Sleep (5)
SendByteTwo()
Thread.Sleep (5)
SendByteThree()
Thread.Sleep (5)
etc...
Seehttp://msdn2.microsoft.com/en-us/library/system.threading.thread.slee...
Cheers,
RB.
RB, I was on the right path in thinking. I have been reading however
that it may be sloppy coding.....anyways.... how can i write it were i
use this delay with each byte i send across from a com.ouput command
example: com.output= (byte(1) + thead.sleep(5) + byte(2)+.......
?????
You could use something similar to :
Dim i as integer
For i = 1 to 6
com.output = byte(i)
Thread.Sleep(5)
Next i
Be aware that this will cause AT LEAST a 5 ms delay per byte sending. It
may be longer - would this cause an issue?
Cheers,
RB.- Hide quoted text -
- Show quoted text -
RB how can i do the for loop with these bytes
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
On Sep 20, 11:12 am, cmdolcet69 <colin_dolce...@hotmail.comwrote:
On Sep 20, 11:05 am, RB <owmdkbqziki...@mailinator.comwrote:
cmdolcet69 wrote:
On Sep 20, 10:55 am, RB <owmdkbqziki...@mailinator.comwrote:
>cmdolcet69 wrote:
>>How can i add a 5ms delay between bytes i send over to a controller?
>>I have to send 6 bytes in total however in between each byte i need to
>>have a 5ms delay.
>I think you can just use Thread.Sleep (5).
>So you're code would look like:
>SendByteOne()
>Thread.Sleep (5)
>SendByteTwo()
>Thread.Sleep (5)
>SendByteThree()
>Thread.Sleep (5)
>etc...
>Seehttp://msdn2.microsoft.com/en-us/library/system.threading.thread.slee...
>Cheers,
>RB.
RB, I was on the right path in thinking. I have been reading however
that it may be sloppy coding.....anyways.... how can i write it were i
use this delay with each byte i send across from a com.ouput command
example: com.output= (byte(1) + thead.sleep(5) + byte(2)+.......
?????
You could use something similar to :
Dim i as integer
For i = 1 to 6
com.output = byte(i)
Thread.Sleep(5)
Next i
Be aware that this will cause AT LEAST a 5 ms delay per byte sending. It
may be longer - would this cause an issue?
Cheers,
RB.- Hide quoted text -
- Show quoted text -
RB how can i do the for loop with these bytes
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
Dump them into an array, collection, list, etc and then do the for
each loop.
Thanks,
Seth Rowe
Use an array of Type byte. E.g.,
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
Then use a loop. Arrays of type Byte are standard for this. For example,
the SerialPort object Write method has an overload for a Byte array (if you
wanted to send all "back-to-back, with no delay).
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.
On Sep 20, 1:46 pm, "Dick Grier" <dick_grierNOSPAM@.msn.comwrote:
Use an array of Type byte. E.g.,
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
Then use a loop. Arrays of type Byte are standard for this. For example,
the SerialPort object Write method has an overload for a Byte array (if you
wanted to send all "back-to-back, with no delay).
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.
when i do the following loop and code for the initial loop it will
break and give me an error saying "property value is not valid"
Dim i As Integer
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
cmdolcet69 wrote:
On Sep 20, 1:46 pm, "Dick Grier" <dick_grierNOSPAM@.msn.comwrote:
>Use an array of Type byte. E.g.,
Dim Packet(5) As Byte Packet(0) = 6 Packet(1) = 7 Packet(2) = 28 Packet(3) = 45 Packet(4) = 48 Packet(5) = 130
Then use a loop. Arrays of type Byte are standard for this. For example, the SerialPort object Write method has an overload for a Byte array (if you wanted to send all "back-to-back, with no delay).
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.
when i do the following loop and code for the initial loop it will
break and give me an error saying "property value is not valid"
Dim i As Integer
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
You have 6 elements in your array, but you've only declared it as having
5 elements.
Dim Packet(6) As Byte 'THIS IS THE LINE OF CODE I CHANGED.
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
"RB" <ow************@mailinator.comschrieb
when i do the following loop and code for the initial loop it will
break and give me an error saying "property value is not valid"
Dim i As Integer
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
You have 6 elements in your array, but you've only declared it as
having 5 elements.
No, his array has 6 elements, indexes 0, 1, 2, 3, 4, 5.
Dim Packet(6) As Byte 'THIS IS THE LINE OF CODE I CHANGED.
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
Your array can contain 7 items. You don't fill Packet(6).
Armin
Armin Zingler wrote:
"RB" <ow************@mailinator.comschrieb
when i do the following loop and code for the initial loop it will
break and give me an error saying "property value is not valid"
Dim i As Integer
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
You have 6 elements in your array, but you've only declared it as having 5 elements.
No, his array has 6 elements, indexes 0, 1, 2, 3, 4, 5.
> Dim Packet(6) As Byte 'THIS IS THE LINE OF CODE I CHANGED. Packet(0) = 6 Packet(1) = 7 Packet(2) = 28 Packet(3) = 45 Packet(4) = 48 Packet(5) = 130
For i = 0 To 5 comm1.Output = Packet(i) Thread.Sleep(5) Next i
Your array can contain 7 items. You don't fill Packet(6).
Armin
Sorry, you're totally right. "Property value not valid" would be an
unusual error to receive from an array out of bounds anyway!!
I suppose the most likely line to be throwing the error is "comm1.output
= Packet(i)" - but without knowing the details of the comm1 object, I
can't really help any further...
Cheers,
RB.
"cmdolcet69" <co************@hotmail.comschrieb
when i do the following loop and code for the initial loop it will
break and give me an error saying "property value is not valid"
Dim i As Integer
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
Is comm1 the COM component for the serial port? If so, I guess you must
either assign a string or an array of bytes to the output property, but I'm
not sure because I can't test it here. Otherwise, using VB 2005, you should
consider using the System.IO.Ports.SerialPort class instead.
Armin
On Sep 21, 5:32 am, RB <owmdkbqziki...@mailinator.comwrote:
Armin Zingler wrote:
"RB" <owmdkbqziki...@mailinator.comschrieb
when i do the following loop and code for the initial loop it will
break and give me an error saying "property value is not valid"
Dim i As Integer
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
You have 6 elements in your array, but you've only declared it as
having 5 elements.
No, his array has 6 elements, indexes 0, 1, 2, 3, 4, 5.
Dim Packet(6) As Byte 'THIS IS THE LINE OF CODE I CHANGED.
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
Your array can contain 7 items. You don't fill Packet(6).
Armin
Sorry, you're totally right. "Property value not valid" would be an
unusual error to receive from an array out of bounds anyway!!
I suppose the most likely line to be throwing the error is "comm1.output
= Packet(i)" - but without knowing the details of the comm1 object, I
can't really help any further...
Cheers,
RB.- Hide quoted text -
- Show quoted text -
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 = "9600,n,8,1"
'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
On Sep 21, 5:28 am, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
when i do the following loop and code for the initial loop it will
break and give me an error saying "property value is not valid"
Dim i As Integer
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
Is comm1 the COM component for the serial port? If so, I guess you must
either assign a string or an array of bytes to the output property, but I'm
not sure because I can't test it here. Otherwise, using VB 2005, you should
consider using the System.IO.Ports.SerialPort class instead.
Armin- Hide quoted text -
- Show quoted text -
Armin comm1 is the com component for the serial port. I can;t assign a
string or an array because i need to have a thread.sleep(5) so that i
give time for the micro to crunch the readings. All this code is in vb
2003 (1.1 Framework) because the program was orinigally developed in
that language.
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
comm1.InBufferCount = 0
comm1.InputLen = 0
comm1.InputMode = InputModeConstants.comInputModeBinary
Dim i As Integer
Dim Packet(6) As Byte
Packet(0) = 42
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)
comm1.Output = Packet(i)
Next i
End Sub
in any event this code should work. Now if i pass a complete string of
byte like you say....
comm1.ouput= packet(0)& packet(1) & packet(2)&........
is will accept that hwoever te micro cannot process this....
"cmdolcet69" <co************@hotmail.comschrieb
Is comm1 the COM component for the serial port? If so, I guess you
must either assign a string or an array of bytes to the output
property, but I'm not sure because I can't test it here.
Otherwise, using VB 2005, you should consider using the
System.IO.Ports.SerialPort class instead.
Armin- Hide quoted text -
- Show quoted text -
Armin comm1 is the com component for the serial port. I can;t assign
a string or an array because i need to have a thread.sleep(5) so
that i give time for the micro to crunch the readings. All this code
is in vb 2003 (1.1 Framework) because the program was orinigally
developed in that language.
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
comm1.InBufferCount = 0
comm1.InputLen = 0
comm1.InputMode = InputModeConstants.comInputModeBinary
Dim i As Integer
Dim Packet(6) As Byte
Packet(0) = 42
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)
comm1.Output = Packet(i)
Next i
End Sub
in any event this code should work. Now if i pass a complete string
of byte like you say....
comm1.ouput= packet(0)& packet(1) & packet(2)&........
is will accept that hwoever te micro cannot process this....
Yes, because you don't know what you are doing here. If you concatenate the
values, you get "4267284548130". These are 13 bytes. But you don't want to
send 13 bytes. The bytes are: 52, 50, 54, 55, 50, 56, .... Why? These are
the codes of the characters in the string. Because "0" has character code
48, "1" has code 49, and so on.
Maybe
comm1.Output = Chr(Packet(i))
works. I don't know. I have no serial ports enable in BIOS - and no device
attached.
Are you sure you have to write a 5ms delay? Doesn't the serial port have a
(small) out buffer? If it's full, doesn't the code wait til more data can be
sent? You are already setting the port speed (9600). Isn't it sufficient?
Armin
On Sep 21, 5:28 am, "Armin Zingler" <az.nos...@freenet.dewrote:
"cmdolcet69" <colin_dolce...@hotmail.comschrieb
when i do the following loop and code for the initial loop it will
break and give me an error saying "property value is not valid"
Dim i As Integer
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130
For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
Is comm1 the COM component for the serial port? If so, I guess you must
either assign a string or an array of bytes to the output property, but I'm
not sure because I can't test it here. Otherwise, using VB 2005, you should
consider using the System.IO.Ports.SerialPort class instead.
Armin- Hide quoted text -
- Show quoted text -
Yes, comm1 is the COM component for the serial port. Here is all the
code which is assocaited with this object.
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"
'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
comm1.InBufferCount = 0
comm1.InputLen = 0
comm1.InputMode = InputModeConstants.comInputModeText
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)
comm1.Output = Packet(i)
Next i
End Sub
Hi,
I wrote my suggestion "at the keyboard," not in the IDE. You actually have
to debug the code to see where it goes wrong. The most likely thing is that
your loop is sending a byte that does not exist.
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.
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.
See www.hardandsoftware.net for details and contact information.
Hi,
What is the Output method? The SerialPort object uses Write, not Output.
It looks like you are using MSComm? There is no good reason to do this.
Use the built-in SerialPort control.
--
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.
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.
See www.hardandsoftware.net for details and contact information.
On Sep 21, 12:14 pm, "Dick Grier" <dick_grierNOSPAM@.msn.comwrote:
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
On Sep 21, 12:23 pm, "Dick Grier" <dick_grierNOSPAM@.msn.comwrote:
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
On Sep 21, 12:23 pm, "Dick Grier" <dick_grierNOSPAM@.msn.comwrote:
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: johnny.karlsson |
last post by:
Hi, I'm working on a project were a need to be able to upload firmware
to a microcontroller based Ethernet device. But because of the memory
constraints the controller can only handle packages of...
|
by: mfeingold |
last post by:
I am working on a system, which among other things includes a server and a
..net control sitting in an html page and connected to the server. I ran into
a couple of problems, you guys might have...
|
by: Max |
last post by:
Hi,
I am newbie developing a MailList program in asp.net c#.
To avoid be considered as a span, a would like to process some messages,
stops, process some messages, stops......
What do you...
|
by: Jochen Müller |
last post by:
Just a short question: With a network sniffer and a hex editor I looked at
the pages coming from my ASP.NET environment and I saw some strange bytes
between header and the page content:
0d 0a 0d...
|
by: WhatHappend |
last post by:
I have converted a .Net 1.0 application to .Net 2.0 and the web service
invocations have delay of around 10seconds on each intial access. After the
first access subsequent access are fast (After a...
|
by: D. Patrick |
last post by:
I need to duplicate the functionality of a java applet, and how it connects
to a remote server. But, I don't have the protocol information or the java
source code which was written years ago. ...
|
by: clemrock |
last post by:
Help w/ errors.add_to_base between controller and model
Hello,
I'm having trouble in routing some errors between model and
controller. The errors produced in the controller...
|
by: danfan46 |
last post by:
Hi!
I have a previous post on the subject that connect takes a long time.
I uninstalled db2 completely.
Installed V9.5
Installed fixpack 1
created das
created an instance
installed...
|
by: Markgoldin |
last post by:
I am sending an XML data from not dontnet process to a .Net via socket
listener.
Here is a data sample:
<VFPData>
<serverdata>
<coderun>updateFloor</coderun>
<area>MD2</area>...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |