Click here to Skip to main content
15,303,572 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an application that I need to disable parity checking for Serial or Com Ports in Windows XP, Vista, or Windows 7.
I am currently using The .NET Framework SerialPort class
the reason I ask is because I get framing errors because I am changing the parity
fairly quickly and looks to be occurring as bytes are being received by the com port.

NOTE: I have to emulate 9 data bits and the only way to do so with the SerialPort Class is to use mark or space parity.
None, even or odd parity will not work.

I think that using DCB to change fParity to false or 0 would be the best way to solve my issue.

I know my program basically works other than the parity errors that I see with a serial port monitoring program.

Example code segments.

C#
Private Poll1()
{
SerialPort1.Parity=Parity.Mark; // turn on wake up bit
SerialPort1.Write(GenPoll,0,2); // , sends the general poll bytes with wake up bit set
SerialPort1.Parity=Parity.Space; // turn off wake up bit 
int numbytes1 = SerialPort1.BytestoRead; // get the number of bytes to read
Byte[] readbuffer1 = new Byte[numbytes1]; creates a Byte array
SerialPort1.Read(readbuffer1,numbytes1); // read the data.
.......
// processing of received data occurs here. I am thinking about creating another sub // method or procedure to process the received data. 
} // end of Poll


example of sending a
command to the machine

C#
private SendCommand1(Byte[] Command)
{
  SerialPort1.Parity=Parity.Mark;
  SerialPort1.Write(Command,0,1); Address byte
  SerialPort1.Parity=Parity.Space;
  SerialPort1.Write(Command,1,Command.Length-1); command to the machine.
}


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 7-Jan-12 16:57pm
v4

1 solution

It is very unusual to play with the parity bit in any serial comms1 - normally it is set as Odd, Even or None and left at that. That you are getting parity errors does tend to confirm that your approach is wrong.

Instead, check your databits - are you using seven bit data and it should be eight? Some systems work this way, and use the top bit to indicate command / data. You may have better results using that.


1 By "very unusual" I mean I have never once heard of a system doing this, but I have only been doing serial comms since the late eighties so I might have missed it...
   
Comments
Foster2011 7-Jan-12 23:08pm
   
I forgot to say I am emulating 9 data bits and use mark parity to create a wake up bit on the bytes that are used as address bytes, otherwise it is space parity.
The only time the device asserts its wake up bit is when it does not see any polling from the host computer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900