Reading an Even Parity Byte Stream

I'm using a socket connection and, strangely enough, the data is being sent with an even parity byte.  This means there are 7 data bits and 1 parity bit.
If you haven't guessed by now, this means that both socket.readByte() and readUnsignedByte() both fail me, as that left most bit is actually just the parity setting.
So, I know that in c i could just trim the final bit with something like:
char letter = dataByte & 0x7F;
How on earth do I get my 7 bit ASCII decimal out of this byte in actionscript?
I thought maybe I could read it into a ByteArray and trim the unneeded bit, but honestly I'm grasping at straws here.

The issue I was having was that ActionScript has no way to read parity bits. So, when it saw 10101100 (44 with even parity bit flipped), it read that as -84. Now that may seem strange, as it did to me, so you'll want to read all about it on Wikipedia.
Now, to fix this strange issue, we simply need to be sure that if the parity bit is flipped to 1, we flip it back to zero. Doing this is simple, because ActionScript reads the parity bit as a negative byte.
var text:String = "";
var tmp:int = socket.readByte();
var charCode:int code;
if(tmp < 0)  //check to see if the parity bit was flipped to 1
     code=tmp & 0x7F;  //reset the parity bit to 0
else
     code=tmp;  //nothing to do if parity bit is 0
text+=String.fromCharCode(code);
Now, should ActionScript support the reading of parity bits?  I doubt that is in the cards.  Still, good to know that if you do find them they are easy to deal with.

Similar Messages

  • Specifying byte stream type for Read File with Type Descriptor

    Hi.
    I'm trying to write a VI that reads an image file format that can have
    different datatypes. What I have so far is that I open the file, read
    the header, and get the width, height, number of frames, and datatype.
    I calculate number of pixels by nrows*ncols*nframes with no problem,
    but I'm not sure how to tell Read File the correct datatype to read
    the data into.
    I tried using a Case structure where I have a Read File in each case
    with the correct type constant as input for that case. The problem is
    that the tunnel graduates the datatype to the highest representation.
    I found in Application Note 154 the discussion about Type Descriptors.
    Is there a way to generate a Type Descriptor and output it from a C
    ase
    structure? I tried just returning the value (e.g. 0x0402 for a Word),
    but Read File will just see that the byte stream type is a uint32.
    Is there any other way to do this?
    Thanks for any help.

    I converted the code to LabVIEW 6.1 for you and attached it below.
    Don't worry about being a newbie. We all start there. Keep asking this type of question and you won't stay there long.
    As you are discovering, being strictly typed means that you must rewrite code even for a simple data type change, or convert everything to the same data type first. For image data, conversion can result in a lot of extra space being wasted. Use a modified version of the GLV_WaveformBuffer.vi to hold your data. Use the array functions, which operate inline, to add to and delete the data wires in the buffer. This allows you to save several different data types. You will need several different inputs and outputs to handle these data types. I ha
    ve also attached a similar file created for exactly the problem you have - storing arrays of different data types (data from NI-SCOPE devices, in this case - can be float, I8, I16, or I32).
    Routines that take any type work in one of two ways. LabVIEW primitives, such as plus and minus operators, work by figuring out the type and doing the right thing in the C code layer of the LabVIEW environment. Users of LabVIEW can't do this. Users can make polymorphic VIs. Polymorphic VIs are actually a single VI for every data type that are referenced by a "wrapper", the polymorphic VI. Users still need to write a different VI for every data type they need.
    Take home message - if you need to work with different data types, you will need to rewrite your code for every data type or convert your data to a common data type. Polymorphic VIs and case statements are your friend.
    Let me know if you need more help.
    This account is no longer active. Contact ShadesOfGray for current posts and information.
    Attachments:
    GigaLabVIEW61.zip ‏362 KB
    sfpScpChan_Waveform_Buffer.zip ‏74 KB

  • Oops. Can I read my byte stream files with missing headers?

    My fault, I know, but I wrote out an 1D array of numbers to a file using the simple Write File vi, not realising that a header would have been a good idea at the time. Now I can't read them back in because LabVIEW doesn't know what they are, and trying to put the original array element (Dbl Precision Number) on the Byte Stream Type of Read File doesn't work.
    So, is there any way that I can insert an appropriate header back into the beginning of the file so that I can then read them in successfully?
    (No, unfortunately I can't regenerate the data. Believe me, I would if I could!)
    Thanks,
    Riggy

    I suppose you used the Write File function from the File I/O pallette since there is no Write File VI?
    If that is the case your file should be exactly 8*N bytes long, if the array had N elements of type DBL.
    You can simply read back you data with the 'Read characters from File' VI (from the File I/O pallette) and then typecast the read string to a 1D array of DBL. (typecast is the first icon in the 'Advanced--Data Manipulation' pallette.
    -Franz

  • Writing 7 data bits/even parity over sockets

    Hi, I'm having trouble finding information on this topic, even though several threads out there allude to the subject so hopefully someone can clarify this for me...take a simple case: I need to send a byte over a socket formatted as 7bits/even parity, say for example the character 4. So in ASCII this has the binary representation 00110100, I flip the parity bit to make it even and we get 10110100. But Java doesn't support unsigned chars and thus will not let me create a byte > 127. I've tried to send it as an int (180), short, hex(b4) but the conversions don't seem to address the underlying problem; most of the solutions posted to similar problems involved the next step up ie. 16bit short but doesn't this send a high byte and a low byte out over the socket which will be interpreted by the gateway expecting 8-bit unsigned bytes as 2 individual bytes?
    - Craig

    It turned out to be the wrong value once I coded it. The code for that and the correct one is below.
    byte b1 = (byte)(256 - '4');
    System.out.println("wrong b=" + (int)b1);
    System.out.println("wrong b=" + Integer.toHexString(b1));
    byte b2 = (byte)Integer.parseInt("1111111110110100", 2);
    System.out.println("right b=" + (int)b2);
    System.out.println("right b=" + Integer.toHexString(b2));

  • How to convert character streams to byte streams?

    Hi,
    I know InputStreamReader can convert byte streams to character streams? But how to convert the character streams back to byte streams? Is there a Java class for that?
    Thanks in advance.

    When do you have to do this? There's probably another way. If you just start out using only InputStreams you shouldn't have that problem.

  • Problems Reading SSL  server socket  data stream using readByte()

    Hi I'm trying to read an SSL server socket stream using readByte(). I need to use readByte() because my program acts an LDAP proxy (receives LDAP messages from an LDAP client then passes them onto an actual LDAP server. It works fine with normal LDAP data streams but once an SSL data stream is introduced, readByte just hangs! Here is my code.....
    help!!! anyone?... anyone?
    1. SSL Socket is first read into  " InputStream input"
    public void     run()
              Authorization     auth = new Authorization();
              try     {
                   InputStream     input     =     client.getInputStream();
                   while     (true)
                   {     StandLdapCommand command;
                        try
                             command = new StandLdapCommand(input);
                             Authorization     t = command.get_auth();
                             if (t != null )
                                  auth = t;
                        catch( SocketException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection closed: " + e );
                             close( e );
                             break;
                        catch( EOFException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection close: " + e );
                             close( e );
                             break;
                        catch( Exception e )
                             //Way too many of these to trace them!
                             Message.Error( "Command not processed due to exception");
                             close( e );
                                            break;
                                            //continue;
                        processor.processBefore(auth,     command);
                                    try
                                      Thread.sleep(40); //yield to other threads
                                    catch(InterruptedException ie) {}
              catch     (Exception e)
                   close(e);
    2 Then data is sent to an intermediate function 
    from this statement in the function above:   command = new StandLdapCommand(input);
         public StandLdapCommand(InputStream     in)     throws IOException
              message     =     LDAPMessage.receive(in);
              analyze();
    Then finally, the read function where it hangs at  "int tag = (int)din.readByte(); "
    public static LDAPMessage receive(InputStream is) throws IOException
        *  LDAP Message Format =
        *      1.  LBER_SEQUENCE                           --  1 byte
        *      2.  Length                                  --  variable length     = 3 + 4 + 5 ....
        *      3.  ID                                      --  variable length
        *      4.  LDAP_REQ_msg                            --  1 byte
        *      5.  Message specific structure              --  variable length
        DataInputStream din = new DataInputStream(is);
        int tag = public static LDAPMessage receive(InputStream is) throws IOException
        *  LDAP Message Format =
        *      1.  LBER_SEQUENCE                           --  1 byte
        *      2.  Length                                  --  variable length     = 3 + 4 + 5 ....
        *      3.  ID                                      --  variable length
        *      4.  LDAP_REQ_msg                            --  1 byte
        *      5.  Message specific structure              --  variable length
        DataInputStream din = new DataInputStream(is);
           int tag = (int)din.readByte();      // sequence tag// sequence tag
        ...

    I suspect you are actually getting an Exception and not tracing the cause properly and then doing a sleep and then getting another Exception. Never ever catch an exception without tracing what it actually is somewhere.
    Also I don't know what the sleep is supposed to be for. You will block in readByte() until something comes in, and that should be enough yielding for anybody. The sleep is just literally a waste of time.

  • Problem trying to read an SSL server socket stream using readByte().

    Hi I'm trying to read an SSL server socket stream using readByte(). I need to use readByte() because my program acts an LDAP proxy (receives LDAP messages from an LDAP client then passes them onto an actual LDAP server. It works fine with normal LDAP data streams but once an SSL data stream is introduced, readByte just hangs! Here is my code.....
    help!!! anyone?... anyone?
    1. SSL Socket is first read into  " InputStream input"
    public void     run()
              Authorization     auth = new Authorization();
              try     {
                   InputStream     input     =     client.getInputStream();
                   while     (true)
                   {     StandLdapCommand command;
                        try
                             command = new StandLdapCommand(input);
                             Authorization     t = command.get_auth();
                             if (t != null )
                                  auth = t;
                        catch( SocketException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection closed: " + e );
                             close( e );
                             break;
                        catch( EOFException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection close: " + e );
                             close( e );
                             break;
                        catch( Exception e )
                             //Way too many of these to trace them!
                             Message.Error( "Command not processed due to exception");
                             close( e );
                                            break;
                                            //continue;
                        processor.processBefore(auth,     command);
                                    try
                                      Thread.sleep(40); //yield to other threads
                                    catch(InterruptedException ie) {}
              catch     (Exception e)
                   close(e);
    2 Then data is sent to an intermediate function 
    from this statement in the function above:   command = new StandLdapCommand(input);
         public StandLdapCommand(InputStream     in)     throws IOException
              message     =     LDAPMessage.receive(in);
              analyze();
    Then finally, the read function where it hangs at  "int tag = (int)din.readByte(); "
    public static LDAPMessage receive(InputStream is) throws IOException
        *  LDAP Message Format =
        *      1.  LBER_SEQUENCE                           --  1 byte
        *      2.  Length                                  --  variable length     = 3 + 4 + 5 ....
        *      3.  ID                                      --  variable length
        *      4.  LDAP_REQ_msg                            --  1 byte
        *      5.  Message specific structure              --  variable length
        DataInputStream din = new DataInputStream(is);
           int tag = (int)din.readByte();      // sequence tag// sequence tag

    I suspect you are actually getting an Exception and not tracing the cause properly and then doing a sleep and then getting another Exception. Never ever catch an exception without tracing what it actually is somewhere.
    Also I don't know what the sleep is supposed to be for. You will block in readByte() until something comes in, and that should be enough yielding for anybody. The sleep is just literally a waste of time.

  • Data plug-in for binary data with byte streams of variable length

    Hi there,
    I would like to write a data plug-in to read binary data from file and I'm using DIAdem 10.1.
    Each data set in my file consists of binary data with a fixed structure (readable by using direct access channels) and of a byte stream of variable length. The variable length of each byte stream is coded in the fixed data part.
    Can anyone tell me how my data plug-in must look like to read such kind of data files?
    Many thanks in advance!
    Kind regards,
    Stefan

    Hi Brad,
    thank you for the very quick response!
    I forgot to mention, that the data in the byte stream can actually be ignored, it is no data to be evaluated in DIAdem (it is picture data and the picture size varies from data set to data set).
    So basically, of each data set I would like to read the fixed-structure data (which is the first part of the data set) and discard the variable byte stream (last part of the data set).
    Here is a logical (example) layout of my binary data file:
    | fixedSize-Value1 | fixedSize-Value2 | fixedSize-Value3 (=length of byte stream) | XXXXXXXXXXXXX (byte stream)
    | fixedSize-Value1 | fixedSize-Value2 | fixedSize-Value3 (=length of byte stream) | XXXXXX (byte stream)
    | fixedSize-Value1 | fixedSize-Value2 | fixedSize-Value3 (=length of byte stream) | XXXXXXXXXXXXXXXXXXXX (byte stream)
    What I would like to show in DIAdem is only fixedSize-Value1 and fixedSize-Value2.
    ´
    If I understood right, would it be possible to set the BlockLength of each data set by assigning Block.BlockLength = fixedSize-Value3 and to use Direct Access Channels for reading fixedSize-Value1 and fixedSize-Value2 ?
    Thank you!
    Kind regards,
    Stefan

  • Problems reading  an SSL server socket stream using readByte()

    Hi I'm trying to read an SSL server socket stream using readByte(). I need to use readByte() because my program acts an LDAP proxy (receives LDAP messages from an LDAP client then passes them onto an actual LDAP server. It works fine with normal LDAP data streams but once an SSL data stream is introduced, readByte just hangs! Here is my code.....
    help!!! anyone?... anyone?
    1. SSL Socket is first read into  " InputStream input"
    public void     run()
              Authorization     auth = new Authorization();
              try     {
                   InputStream     input     =     client.getInputStream();
                   while     (true)
                   {     StandLdapCommand command;
                        try
                             command = new StandLdapCommand(input);
                             Authorization     t = command.get_auth();
                             if (t != null )
                                  auth = t;
                        catch( SocketException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection closed: " + e );
                             close( e );
                             break;
                        catch( EOFException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection close: " + e );
                             close( e );
                             break;
                        catch( Exception e )
                             //Way too many of these to trace them!
                             Message.Error( "Command not processed due to exception");
                             close( e );
                                            break;
                                            //continue;
                        processor.processBefore(auth,     command);
                                    try
                                      Thread.sleep(40); //yield to other threads
                                    catch(InterruptedException ie) {}
              catch     (Exception e)
                   close(e);
    2 Then data is sent to an intermediate function 
    from this statement in the function above:   command = new StandLdapCommand(input);
         public StandLdapCommand(InputStream     in)     throws IOException
              message     =     LDAPMessage.receive(in);
              analyze();
    Then finally, the read function where it hangs at  "int tag = (int)din.readByte(); "
    public static LDAPMessage receive(InputStream is) throws IOException
        *  LDAP Message Format =
        *      1.  LBER_SEQUENCE                           --  1 byte
        *      2.  Length                                  --  variable length     = 3 + 4 + 5 ....
        *      3.  ID                                      --  variable length
        *      4.  LDAP_REQ_msg                            --  1 byte
        *      5.  Message specific structure              --  variable length
        DataInputStream din = new DataInputStream(is);
           int tag = (int)din.readByte();      // sequence tag// sequence tag

    I suspect you are actually getting an Exception and not tracing the cause properly and then doing a sleep and then getting another Exception. Never ever catch an exception without tracing what it actually is somewhere.
    Also I don't know what the sleep is supposed to be for. You will block in readByte() until something comes in, and that should be enough yielding for anybody. The sleep is just literally a waste of time.

  • I am having trouble saving a byte stream file refnum

    I am creating a .csv file using the File I/O->Open/Create/Replace file VI.  I am able to create a file at the file location that I gave it, but when I save the refnum to a byte stream refnum global, it will not save the refnum.  When I call on the global in a seperate VI, it reads "0".

    Oops, you posted while I was typing -
    "I am trying to create a csv file once a item has been scanned and started testing.  This filename will be attached to a file path and when VIs running certain tests are initiated, they are to look in a global information source for this file location and append the csv file."
    Ok, you want to look into the "Programming\File I/O\Configuration File pallette. Or better yet go to the OpenG site and get their tools for writing configuration files. Or use the spreadsheet file function to write the name-path pairs to a file and read them back in when needed, allowing you to populate a two dimensional array with one column being item name, the next being path to its file. Search the array to find the name entry, pull out the path.
    refnums are meaningless outside of the instance they were instantiated for, in other words, they won't point at a file that was created in a previous run of a vi, they only point to the file while the vi(s) that are manipulating it are running.
    As was asked before, what are you trying to do? It is relatively trivial to save a "filepath" (i.e. C:\Projects\Blah.csv) into a file to be used later to access Blah.csv
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • Need to create simple image as byte stream...

    I am looking for a simple and efficient mechanism (supported in Java 1.4.x and later) that would allow me to create a simple raster image byte stream (in .png, .gif or .jpeg encoding) given an RGB + Alpha value (Paint?) and x and y dimensions in pixels.
    I know it sounds unbelievably trivial, but I haven't played with the image stuff in Java in a long time and I am looking for an easy (read "handed to me on a silver platter") solution.
    TIA,
    Chuck

    I guess I should have looked for myself, but it being Friday and I being lazy I didn't want to bother...
    The answer to this question is best rendered in the Java Almanac: http://javaalmanac.com/egs/javax.imageio/Graphic2File.html

  • Coversion from byte stream to character & character to byte stream.

    This is a test program.
    import java.io.*;
    class Test
         public static void main(String[] args)
              System.out.println("Hello World!");
              try
                   BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("C:/javafiles/testing/Picture.jpg"))));
                   PrintWriter bw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File("C:/javafiles/testing/Copy.jpg"))));
                   String in = br.readLine();
                   while (in != null)
                        bw.println(in);
                        in = br.readLine();
                   br.close();
                   bw.close();
              catch (Exception e)
                   System.out.println("\n\n**********Exception Occured**************\n" + e);
    **First of all I read jpg file convert it into character stream from byte stream.
    **and copy it back and convert it back into byte steam from character stream.
    **The file copied back is corrupted.(getting open but display has fully scattered.)
    **That means data has been lost in conversion.
    **is it due to the encoding, I havn't specified while writing, or it always happens when we convert from byte stream to character and vice versa.
    **What encoding should I use while writing jpg files.
    please comment.

    **First of all I read jpg file convert it into
    character stream from byte stream.
    **and copy it back and convert it back into byte
    steam from character stream.First of all this operation is meaningless. A JPEG file doesn't contain anything that can be converted to characters. Delete the 'conversions' and all will be well.
    **What encoding should I use while writing jpg files.None. Don't use an encoding. Don't use Readers and Writers. Use InputStreams and OutputStreams only.

  • Reading unknown number of bytes !

    Hi all !
    I am trying to read unknown number of bytes from the socket.Meanwhile I need to process the bytes depending on the message type in the header.I get messages like this header,body,header,body header,body header,body.....the message type is specified in the header.Each message type has different body size.So depending on that I have to read the next few bytes from the socket....say 300 or 600 depending the on the message type in the header.I get the bytes continioulsy like this.Since I cannot read byte by byte due performance reason is there any other way to do that.....any help will appreciated
    sash

    A simple workaround is to use a java.io.PushbackInputStream
    Read enough bytes to get the header, parse the header bytes, and push the remainder back into the stream to be read as the body.

  • Error transmitting the request byte stream

    I got error message when I try to store archive file via ixos LEA9.6.0. The message text is
    "Job started
    Step 001 started (program RSARCH_STORE_FILE, variant , user name SAWANG)
    The archive file 000733-001MM_ACCTIT is being processed
    Error transmitting the requested byte stream
    Error occured when checking the stored archive file 000733-001MM_ACCTIT
    Job cancelled"
    Help me please.

    Hi...plz help me regarding this:
    Even i'm getting the error message : HTTP error: 500 Internal Server Error  3017when trying to archive files via IXOS.
    Could you please let me know why is this happening? what could be the possible reasons???
    Job started
    Step 001 started (program RSARCH_STORE_FILE, variant , user ID UNICENTR)
    Archive file 001748-001RV_LIKP is being processed
    HTTP error: 500 Internal Server Error  3017
    Archive file 001748-001RV_LIKP cannot be stored
    Job cancelled after system exception ERROR_MESSAGE
    Thanks a lot in advance..
    Shamim

  • 7 Data Bits, Even Parity, 1 Stop Bit over IP

    Hello,
    I have a service provider that required ALL transmission even over IP to be 7 Data Bits, Even Parity, 1 Stop Bit. Is this even possible?
    I have been going around and around with this dude. 7E1 is serial communications not IP communications right? Maybe I am wrong...
    Regards,
    -Jeff

    Hello,
    I have a service provider that required ALL
    transmission even over IP to be 7 Data Bits, Even
    Parity, 1 Stop Bit. Is this even possible?
    It is not possible. What you are talking about is serial protocol with involves more than 8 bits. A stop bit is used to frame the other bits and would lie outside the 8 bit boundary.
    Section 1.2 in the following works well enough in explaining this....
    http://www.freebsd.org/doc/en_US.ISO8859-1/articles/serial-uart/
    Although unlikely it is possible that the provider actually does require an encoded serial protocol (stop bit required.) If that is the case then the service provider needs to provide the specific encoding that they need. However I suspect that they don't require the stop bit. It is quite possible that they require the even parity however.
    I have been going around and around with this dude.
    7E1 is serial communications not IP communications
    right? Maybe I am wrong...That statement is probably incorrect presuming that in fact the actual word size is 8 bits. You use 7 bits for data. You then compute the eighth bit such that the bits in the word (all 8) are even. You can use a 128 size array to do a simple look up for this.
    IP of course takes 8 bits so this is no problem. The character set would be a 7 bit character set like ascii.

Maybe you are looking for

  • My credit card was charged instead of iTunes gift card?

    So I recently just got a $10 iTunes gift card. I redeemed it in the iTunes store, but when I went to buy a book for 8.99, I think it charged my credit card instead of the money on my iTunes card! It still says I have $10.00 left, what do I do?

  • Running OS 9 in Snow Leopard

    I am downloding shepshaver. Has anyone else had the need to run OS 9 or earlier? I have ben using Apple's since the early 80's and have a TON of Apple II and Mac software that I lost after buying my new Mac. I could use some help. John

  • T61 black screen

    Hello, I would be very glad to find out the reason for my working horse "damage": my T61 type 8892, Nvidia chip (Ubuntu Nvidia Setting Panel shows I have no problems with GPU temperature even after many hours of using PC) began to show only black scr

  • Create opportunity from an offer

    Would be cool if one could open an opportunity from an offer. Why? People call and ask for an offer. Sometimes it's an amopunt of 5 bucks the next could be 50.000 bucks. Well, the 5 bucks are not really an opportunity that you want to invest to much

  • Setting .jrxml in tomcat classpath

    Hi, I am using Jasper reports to build a HTML document. In my code i dont want to specify the absolute path of the .jrxml file for the tomcat server to recognize. Hence, in my code i want to use "contact.jrxml" instead of "c://contact.jrxml", similla