C# Serial Port Framing Error
Contents |
Libraries Question 0 Sign in to vote Hi there.I wrote a simple application in C#, using the SerialPort in the .Net Framework 2.0, which receives some data
C# Xonlimit
via the serial port. The data it receives is incorrect, though. I compared c# serial port example it to the data received by an Delphi app, which I received for testing purposes, and very basic VB6 app, c# serial port read example which I wrote using the MSComm control.Examples :Correct values (Received in Delphi & VB6 Apps) :91 01 01 03 48 48 50 69 66 51 70 55 52 93 (14 bytes)Incorrect values
Visual C# Serial Port
(Received in C# App) :91 241 254 252 242 146 42 201 51 70 55 52 93 (13 bytes)As you can see the first byte and the last five bytes correspond.Recently, I checked the ErrorReceived and PinChanged event of the SerialPort. For every DataReceivedevent an ErrorReceived event fires which stated that a framing error has occurred. The PinChanged event also fired numerous times for each DataReceived
C# Virtual Serial Port
event, but I would assume that that in itself does not indicate a problem.That leaves me with the question : why would the SerialPort class encounter a framing error while the other apps apparently did not ? Tuesday, October 07, 2008 5:16 PM Reply | Quote Answers 1 Sign in to vote Well, that's all fairly mysterious. Some embedded devices derive serial port chip power from the handshake lines. DTR is a popular choice. Lord knows what happens if it is off. Seeing RING jiggle that much is definitely not normal nor healthy. It will give the driver a pretty bad headache, for one. You'd better check the cabling, digging up a scope somewhere is highly recommended. Hans Passant. Marked as answer by Zhi-Xin Ye Monday, October 13, 2008 8:34 AM Wednesday, October 08, 2008 11:05 PM Reply | Quote Moderator All replies 1 Sign in to vote Seeing the PinChanged event fire a lot is definitely not normal. Could be SerialPinChanged.Break but you would have to have a really gross framing error to get that.Let's assume the Baudrate setting is in the ballpark, at least some bytes resemble each other. You are missi
has 1 Reply | 1 Follower inferno242 Bedford, UK Since 10/2/2005 Posts 334 Reputation 6,965 Reply Gareth Day (inferno242) Posted: 7/10/2007 8:58 AM java serial port rated by 0 users I have done serial port communication before but have
Visual Basic Serial Port
only just come across this error. Basically im communicating to a PLC and I have done this a few visual studio serial port times before and understand how it works. The problem is with my latests application. Everytime the plc communicates to my app, i get time out errors. So i added an serialport https://social.msdn.microsoft.com/Forums/vstudio/en-US/a45a079f-64b8-457e-a061-c327e7d8a1a5/serialport-framing-error?forum=netfxbcl error received event handler and now im getting error with a frame.What are framing errors?I have checked that all the baud speeds and that match. | Post Points: 20 betrl8thanever San Diego, CA Since 12/8/2003 Posts 7,097 Reputation 50,775 Reply betrl8thanever (betrl8thanever) replied on 7/20/2007 9:50 PM rated by 0 users Ok, how to explain this....Framing is basically how to connections http://vbcity.com/forums/t/143489.aspx talk to each other. One will say hey I can handle more data faster, the other will respond I'm going as fast as I can, or ok here it comes. And they both trottle to match each others send / receive speed. In that communication is also how many packets are being sent. Each packet has header information that says what's in it. A checksum of sorts. After that sequence of packets is sent the receiving machine checks the integrity of each packet. If it's TCP/IP and is missing a bit or bytes from a packet, it will send a request for those bits or bytes to be resent until it gets all of the packets in their entirety. With COM ports it's not tcp/ip so I'm assuming that the checksum for each frame (packet) is not matching what the requesting / receiving machine is expecting and therefore is throwing that error.A timeout would certainly explain that. betrl8thanever Former Microsoft MVP vbCity Team | Post Points: 5 < Previous Topic | Next Topic > Page 1 of 1 (2 items) | RSS Copyright 1998-2016 vbCity.com LLC
question and get tips & solutions from a community https://bytes.com/topic/net/answers/550762-serialport-c-handle-error of 418,461 IT Pros & Developers. It's quick & easy. SerialPort in C# Handle error P: 2 sranger When I try to use a System.IO.Ports.SerialPort object to read from a serial port, half of the time I have no problems. However, after I successfully read from the serial port, then serial port close the connection, either when re-opening it (in the same instance or a new instance of my program) I get either an IOException "The Handle is Invalid" exception or an ArgumentException "The portName is invalid. Now, I get the port name by doing this: Expand|Select|Wrap|Line Numbers String[]ports=SerialPort.GetPortNames(); So I know it c# serial port is a valid port and the portName shouldn't be invalid. As for the invalid handle, I open() and close() my streams before and after I read them. This is my SerialPort init section: Expand|Select|Wrap|Line Numbers sin=newSerialPort(); sin.PortName=comboBox1.SelectedItem.ToString(); sin.BaudRate=19200; sin.Parity=Parity.Odd; sin.DataBits=8; sin.StopBits=StopBits.One; sin.Handshake=Handshake.None; sin.ReadTimeout=500; which is all set from the specs of the device I am trying to read data from. comboBox1 is where I put my ports[] array for the user to choose which port. It is defaulted on the first entry (and I only have one installed so its always the first port) When I don't receive the error, the program runs fine, but when I press the Close Connection button or when I try to re-start the connection I get one of the two errors; more often than not it's the invalid handle error. ArgumentException.Message Expand|Select|Wrap|Line Numbers Thegivenportnameisinvalid.Itmaybeavalidport,butnotaserialport. Parametername:portName ArgumentException Stack Expand|Select|Wrap|Line Numbers atSystem.IO.Ports.SerialStream..ctor(StringportName,Int32baudRate,Parityparity,Int32dataBits,StopBitsstopBits,Int32readTimeout,Int32writeTi