problem using serialPort

  • Thread starter Thread starter Mr. X.
  • Start date Start date
M

Mr. X.

Hello.
I am using the VS 2005, and using serialPort to connect to RS232.
(Handshake is on ...)

When getting a response, I get the message :
Cross thread operation not valid :
Control() 'MySerialPortCtl' accessed from a thread other than the thread is
was created on.

What should I do in order to solve the problem ?

Thanks :)
 
Thanks.
Works fine.

A little problem :
The serialPort object reaches ErrorReceived event.
On the event. the second parameter is :
e as system.IO.Ports.SerialErrorReceivedEventArgs.
How can I resolve the error message string ?
(Besides when I resolve the string that recieved, I get some misunderstood
garbage, which don't stand at the protocol standard of the machine, I
recieve the information).

Thanks :)
 
A frame error might indicate incorrect baud rate or word size/stop bits etc.
This can also happen if the port is opened in the middle of data
tramsmission, or if the transmission is corrupted.

If the decoded data does not match what you expect to receive then that
indicates the data subject to frame error. Does this occur randomly on
individual characters, or in blocks of characters? Can you confirm from
some other data reveive device that the transmission is not being corrupted?
Have you checked the baud rate, word size, stop bits etc?
 
The problem comes from trying to display data from the DataReceived event,
which executes as a background thread. You need to use a Delegate for this
(or poll, instead of using the DataReceived event). I have example code on
my website, and more detailed information in my book (see below).

Dick

--
Richard Grier (Microsoft MVP - Visual Basic) Hard & Software 12962 West
Louisiana Avenue Lakewood, CO 80228 303-986-2179 (voice) Homepage:
www.hardandsoftware.net Author of Visual Basic Programmer's Guide to Serial
Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July
2004, Revised July 2006.
 
If you have a framing error, the cause is, almost certainly, an incorrect
BaudRate setting. Occasionally, this can be caused by the connected
equipment changing serial speeds (some modems may do this after connecting).
If you are using a modem, make sure that it is initialized to maintain a
fixed serial speed after connect.

Dick

--
Richard Grier (Microsoft MVP - Visual Basic) Hard & Software 12962 West
Louisiana Avenue Lakewood, CO 80228 303-986-2179 (voice) Homepage:
www.hardandsoftware.net Author of Visual Basic Programmer's Guide to Serial
Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July
2004, Revised July 2006.
 
Hello.
What I have configured on SerialPort is :
PortName = "COM1"
ReceivedBytesThreshold = 1 (? is it right ?)
BaudRate = 4800
Parity = Even
DataBits = 7
StopBits = one
RTSEnabled = false
Handshake = XOnXOff
WriteBufferSize = 512 (I couldn't have exact buffer size from the machine,
so I put 512 - is it right ?).

.... other parameters are not configured, and stay as the defaults.

The following I didn't configured
(Was on comm32 object on VB 6. What are the equivalent for VB.NET).
InputMode = ?
OutBufferCount = ?
SThreshold = ?
InputBufferCount = ?

Thanks :)
 
Back
Top