1 Replies - 1099 Views - Last Post: 06 March 2013 - 07:06 AM Rate Topic: -----

#1 nisimYogev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-March 13

RS232 serial port reading error

Posted 05 March 2013 - 11:30 PM

Hi all,

I have a problem using the SerialPort.Read(byte[] arr, int offset, int bytesToRead) with a RS232 connector (and a USB converter).

It worked fine with a USB to RS485, but the project has changed a little and now we are using the USB to RS232 cable.

I managed to get it working with the DataRecivedHandler (just a test moving one byte) but it will cause me to change the whole project, and i don't want to waste me time doing this.

Any body knows if it make sense that the same code will work with RS485 and not RS232 ?


P.s

I am connected to my self and using a terminal of Termite.

Forgot to say,

While using the SerialPort.Read(..) i'm getting a TimeOut exception immediately.

Is This A Good Question/Topic? 0
  • +

Replies To: RS232 serial port reading error

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3183
  • View blog
  • Posts: 9,645
  • Joined: 05-May 12

Re: RS232 serial port reading error

Posted 06 March 2013 - 07:06 AM

If it's a matter of just slow transmission rate, change the timeout value on the port. It's a get/set property.

Personally, I would have setup the code so that I had an adapter class between my business logic and the data port. This is so that for testing my business logic, I replace the adapter class with a mock that can feed both good and bad data; and so that the switch from the Read() calls to using an event handler would have been transparent to the business logic.

Anyway, you didn't quite provide enough information above. What parameters are you passing to your SerialPort constructor? How many bytes are you trying to read from the serial port? How many bytes are actually transmitted to the port?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1