Click here to Skip to main content
16,005,038 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Shared Class Members Pin
Luke R4-Oct-06 12:57
Luke R4-Oct-06 12:57 
GeneralRe: Shared Class Members Pin
Christian Graus4-Oct-06 13:04
protectorChristian Graus4-Oct-06 13:04 
GeneralRe: Shared Class Members Pin
Luke R4-Oct-06 13:07
Luke R4-Oct-06 13:07 
GeneralRe: Shared Class Members Pin
Guffa4-Oct-06 12:25
Guffa4-Oct-06 12:25 
QuestionError - NonComVisible Base Class Pin
eatwork4-Oct-06 9:59
eatwork4-Oct-06 9:59 
QuestionUsing ADODC in VB6 Pin
Tomic4-Oct-06 7:02
Tomic4-Oct-06 7:02 
AnswerRe: Using ADODC in VB6 Pin
Guffa4-Oct-06 12:13
Guffa4-Oct-06 12:13 
Question[VB.NET] Need help with serial port communication Pin
belowzero4-Oct-06 5:05
belowzero4-Oct-06 5:05 
hi there,

i`m really new to .Net and need help with a problem.

i have to send commands to the serial port to which a rfid-card-reader is connected. depending on the command, the card-reader send the answer back to the serial port. my problem is that the first 3 or sometimes 4 commands are working but the following end up in incorrect answers.
the problem has to stuck somewhere in my program because the reader is working fine with another program and the commands are correct.

the connection i build up with the following code

<br />
Private Sub connection()<br />
<br />
mySerial = New SerialPort("COM9", 9600, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One)<br />
mySerial.Encoding = System.Text.Encoding.GetEncoding(1252)<br />
mySerial.Open()<br />
            <br />
End Sub


in my main program i write the command in an byte array.

example:

<br />
Dim buffer1 As Byte() = {&H2, &HB0, &HB2}<br />
sending(buffer1)


before i use the function sending to send the bytes to the serial port

<br />
Private Sub sending(ByVal buffer As Byte())<br />
<br />
Dim i As Integer<br />
<br />
Dim count = buffer(0)    'buffer(0) includes the number of the following bytes<br />
          <br />
'Here i want to write byte by byte to the com port<br />
<br />
For i = 0 To count             <br />
   mySerial.Write(Chr(buffer(i)))<br />
Next<br />
<br />
End Sub


after this i use a threading.thread.sleep() in my main program before i use the following function to read from the com-port

<br />
Private Function reading() As Byte()<br />
<br />
Dim readbuffer As Byte() = {}<br />
<br />
'setting the readbuffer to the size of bytes it has to read from the port<br />
<br />
ReDim readbuffer(mySerial.BytesToRead() - 1)        <br />
<br />
'read bytes from the serial port<br />
<br />
mySerial.Read(readbuffer, 0, mySerial.BytesToRead)  <br />
<br />
reading = readbuffer<br />
<br />
End Function



As i said the first read / write attemps work fine but after a few times i get wrong answers but the command is definitly correct.

is there something i make wrong while opening the connection or do i have to send the bytes an other way?

thanks for your help

michael
AnswerRe: [VB.NET] Need help with serial port communication Pin
Dave Kreskowiak4-Oct-06 6:27
mveDave Kreskowiak4-Oct-06 6:27 
GeneralRe: [VB.NET] Need help with serial port communication Pin
belowzero4-Oct-06 8:23
belowzero4-Oct-06 8:23 
GeneralRe: [VB.NET] Need help with serial port communication Pin
Dave Kreskowiak4-Oct-06 9:31
mveDave Kreskowiak4-Oct-06 9:31 
GeneralRe: [VB.NET] Need help with serial port communication Pin
belowzero4-Oct-06 19:39
belowzero4-Oct-06 19:39 
GeneralRe: [VB.NET] Need help with serial port communication Pin
belowzero5-Oct-06 6:43
belowzero5-Oct-06 6:43 
QuestionTableLayoutPanel Question Pin
Like2Byte4-Oct-06 5:05
Like2Byte4-Oct-06 5:05 
AnswerRe: TableLayoutPanel Question Pin
Dave Kreskowiak4-Oct-06 5:37
mveDave Kreskowiak4-Oct-06 5:37 
GeneralRe: TableLayoutPanel Question Pin
Like2Byte4-Oct-06 5:41
Like2Byte4-Oct-06 5:41 
Question.NET Delegate [modified] Pin
nlindley74-Oct-06 4:32
nlindley74-Oct-06 4:32 
AnswerRe: .NET Delegate Pin
Dave Kreskowiak4-Oct-06 5:20
mveDave Kreskowiak4-Oct-06 5:20 
GeneralRe: .NET Delegate Pin
nlindley74-Oct-06 6:28
nlindley74-Oct-06 6:28 
GeneralRe: .NET Delegate Pin
Dave Kreskowiak4-Oct-06 6:47
mveDave Kreskowiak4-Oct-06 6:47 
GeneralRe: .NET Delegate Pin
nlindley74-Oct-06 7:19
nlindley74-Oct-06 7:19 
GeneralRe: .NET Delegate Pin
Dave Kreskowiak4-Oct-06 7:32
mveDave Kreskowiak4-Oct-06 7:32 
GeneralRe: .NET Delegate Pin
nlindley74-Oct-06 8:07
nlindley74-Oct-06 8:07 
GeneralRe: .NET Delegate Pin
Dave Kreskowiak4-Oct-06 9:26
mveDave Kreskowiak4-Oct-06 9:26 
QuestionWebBrowser proxy server Pin
winmedia4-Oct-06 4:08
winmedia4-Oct-06 4:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.