rs232 SerialPort laptop problem

N

ndtang

Hi,

I am trying to convert a legacy rs232 application to vb2005. The
legacy app was written in pascal and runs in full DOS. I have
successfully rewrote the app to communicate with the device using
SerialPort component in .NET 2.0. It works wonderful with a desktop
PC.

When I installed the program to the laptop it fails, though the
original DOS app works in the same configuration. Somehow, the data is
all out of sync, updates are not registered to the device.

I had tried it on a few desktops and laptops. All the desktop works
fine but all the laptop fails. I even tried using a USB to serial
converter but to no avail.

The problem should not have anything to do with hardware, as the DOS
app is running fine within the same setup. The only difference is a
laptop and desktop.

I have been scratching my head for 2 weeks now trying to figure out
what happened. Please help.


Cheers,
Andy
 
D

Dick Grier

Hi,

I'd need more to go on. I have no trouble deploying my serial applications
to notebooks with USB serial adapters -- with one exception, which doesn't
enter the picture here (you can find more information on it under Downloads
on my homepage -- see DesktopSerialIO for VS 2005, which is free).
Somehow, the data is
all out of sync, updates are not registered to the device.
<<

What does this mean? Is your application "working," but the data seem to be
out of order? If so, then there is a coding problem. What that might be is
hard to guess -- you are the only one looking at the code.

We don't know how or what your program is supposed to do, so simply saying
that there is a problem is not very useful.

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.
 
N

ndtang

Hi,

I'd need more to go on. I have no trouble deploying my serial applications
to notebooks with USB serial adapters -- with one exception, which doesn't
enter the picture here (you can find more information on it under Downloads
on my homepage -- see DesktopSerialIO for VS 2005, which is free).



Somehow, the data is
all out of sync, updates are not registered to the device.
<<

What does this mean? Is your application "working," but the data seem to be
out of order? If so, then there is a coding problem. What that might be is
hard to guess -- you are the only one looking at the code.

We don't know how or what your program is supposed to do, so simply saying
that there is a problem is not very useful.

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.


Hi,

Thanks for the reply so soon. Perhaps I should elaborate more. The
program needs to update a device through a serial port, but the
updating method is a bit awkward. When running, the device will send a
series of bytes, 10 bytes in rotation continuously, signaling device
status.
e.g.


Byte 1 1F -->4 bit index with 4 bit data = 8 bits = 1 byte
Byte 2 2A
Byte 3 32
Byte 4 45
Byte 5 58
Byte 6 60
Byte 7 7E
Byte 8 8C
Byte 9 94
Byte 10 AB

Here comes the problem. In order to update the device, the app needs
to send a byte between byte 1 and byte 2.

Byte 1 1F
<------------------- Update byte must be here, before the
receipt of Byte 2
Byte 2 2A
Byte 3 32
Byte 4 45
Byte 5 58
Byte 6 60
Byte 7 7E
Byte 8 8C
Byte 9 94
Byte 10 AB

I admit it is a very peculiar method to update but the DOS app is
running fine whereas the Windows app fails miserably. Out of sync
means the bytes are not sent fast enough and once the update slot is
missed, update fails. To cut it short,


DOS Win
--------------------------------+---------------------
+---------------------
Desktop w/USB2Serial | - : OK
Desktop | OK :
OK
Laptop w/USB2Serial | - : FAIL
Laptop | OK :
FAIL
 
D

Dick Grier

Hi,

You still didn't show any code.

What I would do is to create two arrays of type Byte. The first array has
the "standard" data. The second array has the pattern required to insert
the update byte. For example,

Dim Standard(9) As Byte
Standard(0) = &H1F 'or, whatever
Standard(1) = &H2A
Standard(2) = &H32
Standard(3) = &H45
Standard(4) = &H58
Standard(5) = &H60
Standard(6) = &H7E
Standard(7) = &H8C
Standard(8) = &H94
Standard(9) = &HAB

Dim Update(10) As Byte
Update(0) = &H1F 'or, whatever
Update(2) = &H2A 'this leave array index 1 for the "update byte"
Update(3) = &H32
Update(4) = &H45
Update(5) = &H58
Update(6) = &H60
Update(7) = &H7E
Update(8) = &H8C
Update(9) = &H94
Update(10) = &HAB

Then, in your code (somewhere), pseudo:

If INeedToUpdate Then
Update(1) = updatebyte
SerialPort.Write(Update)
Else
SerialPort.Write(Standard)
End If

Of course, the actual logic will be more complex than this... And, what I've
written here assumes that I understand your protocol -- which may or may not
be true.

This code will send data in the correct order. Logically, nothing can get
out-of-sequence. It does assume that a complete "standard or update" packet
will be sent and cannot be interrupted.

One thing that may be an issue. DOS is a single-tasking environment. Thus,
timing between data sent and received can be maintained very closely. On
the other hand, Windows is multitasking and is far from real-time. In
addition, Visual Studio is multithreaded, which can add its own timing
constraints. I am not sure that you aren't seeing some sort of
command/response timing issue, rather than just something that requires that
data be sent in the correct order. If that is the problem, then the solution
would require a much deeper understanding of the requirements than I have.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top