How can I handle stick parity in VB.NET 2005 without built-in functions?

  • Thread starter ionlylooklazy
  • Start date
  • Tags
    Parity
In summary, the conversation is about trying to communicate with a RS232 device utilizing stick parity, a parity scheme where the first byte of a packet has its parity bit set to 1 and all proceeding bytes have their parity bit set to 0. The discussion includes difficulties with handling parity errors and suggestions to disable insertion of specified values and use Windows API functions. It is suggested to use Parity.None and create a custom StickParity function to properly format the data for the device.
  • #1
ionlylooklazy
30
0
Hello all,

Im trying to communicate with a RS232 device utilizing stick parity. This is defined as the first byte of a packet having its parity bit set to one, while all proceeding bytes have their parity bit set to 0. This was meant to be used to determine the start of a new packet.

However, there is no built in function to handle stick parity and I am generating all sorts of parity errors, which makes processing the data dificult.

AFAIK, when a parity error is detected, it inserts a specified value into the input stream, but when I read the stream the byte that was supposed to have generated the parity error still appears. is there anyway to disable this insertion?

I tried setting up an error event that would read the inserted byte out of the stream , but sometimes two or more bytes are inserted, and it seems to only remove one. here is my error event

Code:
Private Sub Data_Error(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialErrorReceivedEventArgs) Handles SerialPort.ErrorReceived
    
    Dim x As Integer
      
    x = SerialPort.ReadByte

    End Sub


I also tried setting the parity to space (parity bit always = 0). This way, I thought that when a parity error is generated, that would signal the start of a new packet, but strangely the error does not always occur.


Does any have any experience with stick parity, or have any suggestions?

Thanks,
IOLL
 
Technology news on Phys.org
  • #2
Take a look at http://www.freevbcode.com/ShowCode.asp?ID=4666. It uses api functions and probably has what you need.
 
  • #3
hmm, I don't see anything I don't already have, but what exactly is an API function?


I don't have a problem setting up rs232 communication, its just using this strange parity scheme. if the parity was any of the standard values it would be npnp
 
  • #4
I mean Windows API (formerly Win32 API) functions. Perhaps you already use them. I thought perhaps you could simply disable parity.
 
  • #5
I assume you're using the class SerialPort which has an enumerated property "Parity":
Code:
SerialPort sp = new SerialPort();
sp.Parity = Parity.Even
sp.Parity = Parity.Mark
sp.Parity = Parity.None
sp.Parity = Parity.Odd
sp.Parity = Parity.Space
Mark parity being High Stick Parity where the parity bit is always set to 1, and space Parity where the parity bit is always set to 0.

So if i understand what's happening, you're communicating with an RS232 device which implements stick parity. Since the SerialPort class doesn't support the stick parity your device uses, the data you send using any of the available parities generates a parity error on the device. Is this what's happening?

I think that, using the SerialPort class, and assuming the Stick Parity your device uses is neither High nor Low stick parity, but some other format, then what you might have to do is set Parity to Parity.None. Then, you create your own StickParity function. This function receives a packet and processes the bytes according to your stick parity, which you then send to the device. Since Parity is set to Parity.None, the SerialPort class won't mess up your data and it should reach your device properly formatted.
 
Last edited:

1. What is stick parity?

Stick parity is a way of checking for errors in data transmission. It involves adding an extra bit to a data byte to ensure that the total number of 1s in the byte is either even or odd. This can help detect and correct errors in the transmitted data.

2. How does stick parity work?

In stick parity, an extra bit is added to a data byte based on the total number of 1s in the byte. If the total number of 1s is already even, the extra bit added will make the total number of 1s odd, and vice versa. This way, if an error occurs during transmission, the receiver will know because the total number of 1s will not match the expected even or odd parity.

3. What is vb.net 2005?

VB.NET 2005 is a programming language created by Microsoft. It is an object-oriented programming language that is commonly used for developing Windows applications. It is based on the Visual Basic programming language and is used in conjunction with the .NET Framework.

4. What are the benefits of using stick parity?

Stick parity helps to detect and correct errors in data transmission, ensuring the accuracy of the data. It also helps to improve the reliability of the data transmission process, as errors can be identified and corrected in real-time. Additionally, stick parity is a simple and efficient method for error checking, making it a popular choice in data communication protocols.

5. Is vb.net 2005 still used today?

Yes, while newer versions of VB.NET have been released, VB.NET 2005 is still widely used today. Many legacy applications and systems are built using VB.NET 2005, and developers may also choose to continue using this version for personal preference or compatibility reasons.

Back
Top