Search Results

Search found 3923 results on 157 pages for 'binary'.

Page 9/157 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Binary data from a serial port in linux using c

    - by user1680393
    I am reading binary data from a serial port on Phidget sbc using Linux to get a command from an application running on a PC. I wrote a test program in VB to read the data into a byte array and convert it to decimal to use it but can’t figure out how to do it in c. I am unable to come up with anything with the research I have done on the internet. Command sent from PC is 0x0F. To check if I am getting correct data I read the data and send it back. Here is what I get back. Returned data has a carriage return added to it. Hex Display 0F00 0000 0D ‘\’ Display \0F\00\00\00\r Normal display just display a strange character. This tells me that the data is there that I can use, but can’t figure out to extract the value 0F or 15. How can I convert the incoming data to use it? I tried converting the received data using strtol, but it returns 0. I also tried setting the port to raw but it did not make any difference. unsigned char buffer1[1]; int ReadPort1() { int result; result = read(file1, &buffer1,1); if(result > 0) { WritePort1(buffer1); sprintf(tempstr, "Port1 data %s %d", buffer1, result); DisplayText(2,tempstr); } return result; } Port Open/Setup void OpenPort1() { //file1 = open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NONBLOCK); file1 = open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NODELAY); if(file1 < 0) printf("Error opening serial port1.\n"); else { SetPort(file1, 115200, 8, 1, 0, 1); port1open = 1; } } void SetPort(int fd, int Baud_Rate, int Data_Bits, int Stop_Bits, int Parity, int raw) { long BAUD; // derived baud rate from command line long DATABITS; long STOPBITS; long PARITYON; long PARITY; struct termios newtio; switch (Baud_Rate) { case 115200: BAUD = B115200; break; case 38400: BAUD = B38400; break; case 19200: BAUD = B19200; break; case 9600: BAUD = B9600; break; } //end of switch baud_rate switch (Data_Bits) { case 8: default: DATABITS = CS8; break; case 7: DATABITS = CS7; break; case 6: DATABITS = CS6; break; case 5: DATABITS = CS5; break; } //end of switch data_bits switch (Stop_Bits) { case 1: default: STOPBITS = 0; break; case 2: STOPBITS = CSTOPB; break; } //end of switch stop bits switch (Parity) { case 0: default: //none PARITYON = 0; PARITY = 0; break; case 1: //odd PARITYON = PARENB; PARITY = PARODD; break; case 2: //even PARITYON = PARENB; PARITY = 0; break; } //end of switch parity newtio.c_cflag = BAUD | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD; newtio.c_iflag = IGNPAR; if(raw == 1) { newtio.c_oflag &= ~OPOST; newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); } else { newtio.c_lflag = 0; //ICANON; newtio.c_oflag = 0; } newtio.c_cc[VMIN]=1; newtio.c_cc[VTIME]=0; tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); }

    Read the article

  • adding nodes to a binary search tree randomly deletes nodes

    - by SDLFunTimes
    Hi, stack. I've got a binary tree of type TYPE (TYPE is a typedef of data*) that can add and remove elements. However for some reason certain values added will overwrite previous elements. Here's my code with examples of it inserting without overwriting elements and it not overwriting elements. the data I'm storing: struct data { int number; char *name; }; typedef struct data data; # ifndef TYPE # define TYPE data* # define TYPE_SIZE sizeof(data*) # endif The tree struct: struct Node { TYPE val; struct Node *left; struct Node *rght; }; struct BSTree { struct Node *root; int cnt; }; The comparator for the data. int compare(TYPE left, TYPE right) { int left_len; int right_len; int shortest_string; /* find longest string */ left_len = strlen(left->name); right_len = strlen(right->name); if(right_len < left_len) { shortest_string = right_len; } else { shortest_string = left_len; } /* compare strings */ if(strncmp(left->name, right->name, shortest_string) > 1) { return 1; } else if(strncmp(left->name, right->name, shortest_string) < 1) { return -1; } else { /* strings are equal */ if(left->number > right->number) { return 1; } else if(left->number < right->number) { return -1; } else { return 0; } } } And the add method struct Node* _addNode(struct Node* cur, TYPE val) { if(cur == NULL) { /* no root has been made */ cur = _createNode(val); return cur; } else { int cmp; cmp = compare(cur->val, val); if(cmp == -1) { /* go left */ if(cur->left == NULL) { printf("adding on left node val %d\n", cur->val->number); cur->left = _createNode(val); } else { return _addNode(cur->left, val); } } else if(cmp >= 0) { /* go right */ if(cur->rght == NULL) { printf("adding on right node val %d\n", cur->val->number); cur->rght = _createNode(val); } else { return _addNode(cur->rght, val); } } return cur; } } void addBSTree(struct BSTree *tree, TYPE val) { tree->root = _addNode(tree->root, val); tree->cnt++; } The function to print the tree: void printTree(struct Node *cur) { if (cur == 0) { printf("\n"); } else { printf("("); printTree(cur->left); printf(" %s, %d ", cur->val->name, cur->val->number); printTree(cur->rght); printf(")\n"); } } Here's an example of some data that will overwrite previous elements: struct BSTree myTree; struct data myData1, myData2, myData3; myData1.number = 5; myData1.name = "rooty"; myData2.number = 1; myData2.name = "lefty"; myData3.number = 10; myData3.name = "righty"; initBSTree(&myTree); addBSTree(&myTree, &myData1); addBSTree(&myTree, &myData2); addBSTree(&myTree, &myData3); printTree(myTree.root); Which will print: (( righty, 10 ) lefty, 1 ) Finally here's some test data that will go in the exact same spot as the previous data, but this time no data is overwritten: struct BSTree myTree; struct data myData1, myData2, myData3; myData1.number = 5; myData1.name = "i"; myData2.number = 5; myData2.name = "h"; myData3.number = 5; myData3.name = "j"; initBSTree(&myTree); addBSTree(&myTree, &myData1); addBSTree(&myTree, &myData2); addBSTree(&myTree, &myData3); printTree(myTree.root); Which prints: (( j, 5 ) i, 5 ( h, 5 ) ) Does anyone know what might be going wrong? Sorry if this post was kind of long.

    Read the article

  • Why do we need a format for binary executable files

    - by user3671483
    When binary files (i.e. executables) are saved they usually have a format (e.g. ELF or .out) where we have a header containing pointers to where data or code is stored inside the file. But why don't we store the binary files directly in the form of sequence of machine instructions.Why do we need to store data separately from the code?Secondly when the assembler creates a binary file is the file is among the above formats?

    Read the article

  • Custom Text and Binary Payloads using WebSocket (TOTD #186)

    - by arungupta
    TOTD #185 explained how to process text and binary payloads in a WebSocket endpoint. In summary, a text payload may be received as public void receiveTextMessage(String message) {    . . . } And binary payload may be received as: public void recieveBinaryMessage(ByteBuffer message) {    . . .} As you realize, both of these methods receive the text and binary data in raw format. However you may like to receive and send the data using a POJO. This marshaling and unmarshaling can be done in the method implementation but JSR 356 API provides a cleaner way. For encoding and decoding text payload into POJO, Decoder.Text (for inbound payload) and Encoder.Text (for outbound payload) interfaces need to be implemented. A sample implementation below shows how text payload consisting of JSON structures can be encoded and decoded. public class MyMessage implements Decoder.Text<MyMessage>, Encoder.Text<MyMessage> {     private JsonObject jsonObject;    @Override    public MyMessage decode(String string) throws DecodeException {        this.jsonObject = new JsonReader(new StringReader(string)).readObject();               return this;    }     @Override    public boolean willDecode(String string) {        return true;    }     @Override    public String encode(MyMessage myMessage) throws EncodeException {        return myMessage.jsonObject.toString();    } public JsonObject getObject() { return jsonObject; }} In this implementation, the decode method decodes incoming text payload to MyMessage, the encode method encodes MyMessage for the outgoing text payload, and the willDecode method returns true or false if the message can be decoded. The encoder and decoder implementation classes need to be specified in the WebSocket endpoint as: @WebSocketEndpoint(value="/endpoint", encoders={MyMessage.class}, decoders={MyMessage.class}) public class MyEndpoint { public MyMessage receiveMessage(MyMessage message) { . . . } } Notice the updated method signature where the application is working with MyMessage instead of the raw string. Note that the encoder and decoder implementations just illustrate the point and provide no validation or exception handling. Similarly Encooder.Binary and Decoder.Binary interfaces need to be implemented for encoding and decoding binary payload. Here are some references for you: JSR 356: Java API for WebSocket - Specification (Early Draft) and Implementation (already integrated in GlassFish 4 promoted builds) TOTD #183 - Getting Started with WebSocket in GlassFish TOTD #184 - Logging WebSocket Frames using Chrome Developer Tools, Net-internals and Wireshark TOTD #185: Processing Text and Binary (Blob, ArrayBuffer, ArrayBufferView) Payload in WebSocket Subsequent blogs will discuss the following topics (not necessary in that order) ... Error handling Interface-driven WebSocket endpoint Java client API Client and Server configuration Security Subprotocols Extensions Other topics from the API

    Read the article

  • Binary to Ascii and back again

    - by rross
    I'm trying to interface with a hardware device via the serial port. When I use software like Portmon to see the messages they look like this: 42 21 21 21 21 41 45 21 26 21 29 21 26 59 5F 41 30 21 2B 21 27 42 21 21 21 21 41 47 21 27 21 28 21 27 59 5D 41 32 21 2A 21 28 When I run them thru a hex to ascii converter the commands don't make sense. Are these messages in fact something different than hex? My hope was to see the messages the device is passing and emulate them using c#. What can I do to find out exactly what the messages are?

    Read the article

  • binary search tree recursive subtree in java

    - by Art Peterson
    Can anyone point me to a code example (java preferably) or psuedocode that uses recursion to return a subtree that contains all nodes with keys between fromKey and toKey. So if I was to call Tree.subtree(5,10) it should return all nodes in the BST that have keys between 5 and 10 inclusive - but I can't use loops or helper methods...only recursive calls to the subtree method, which takes fromKey and toKey as parameters. Thanks!

    Read the article

  • Versioning freindly, extendible binary file format

    - by Bas Bossink
    In the project I'm currently working on there is a need to save a sizeable data structure to disk. Being in optimist I thought their must be a standard solution for such a problem however upto now I haven't found a solution that satisfies the following requirements: .net 2.0 support, preferably with a foss implementation version friendly (this should be interpreted as reading an old version of the format should be relatively simple if the changes in the underlying data structure are simple, say adding/dropping fields) ability to do some form of random access where part of the data can be extended after initial creation (think of this as extending intermediate results) space and time efficient (xml has been excluded as option given this requierement) Options considered so far: Protocol Buffers : was turned down by verdict of the documentation about Large Data Sets since this comment suggest adding another layer on top, this would call for additional complexity which I wish to have handled by the file format itself. HDF5,EXI : do not seem to have .net implementations SQLite : the data structure at hand would result in a pretty complex table structure that seems to heavyweight for the intended use BSON : does not appear to support requirement 3. Fast Infoset : only seems to have buyware .net implementations Any recommendations or pointers are greatly appreciated. Furthermore if you believe any of the information above is not true please provide pointers/examples to proove me wrong.

    Read the article

  • Binary Trees in Scheme

    - by Javier
    Consider the following BNF defining trees of numbers. Notice that a tree can either be a leaf, a node-1 with one subtrees, or a node-2 with two subtrees. tree ::= (’leaf number) | (’node-1 tree) | (’node-2 tree tree) a. Write a template for recursive procedures on these trees. b. Define the procedure (leaf-count t) that returns the number of leaves in t > (leaf-count ’(leaf 5)) 1 > (leaf-count ’(node-2 (leaf 25) (leaf 17))) 2 > (leaf-count ’(node-1 (node-2 (leaf 4) (node-2 (leaf 2) (leaf 3))))) 3 Here's what I have so far: ;define what a leaf, node-1, and node-2 is (define leaf list) (define node-1 list) (define node-2 list) ;procedure to decide if a list is a leaf or a node (define (leaf? tree) (number? (car tree))) (define (node? tree) (pair? (car tree))) (define (leaf-count tree) (cond ((null? tree) 0) ((number? tree) 0) ((leaf? tree) 1) (else (+ (leaf-count (car tree)) (leaf-count (cdr tree)))))) It looks like it should run just fine, but when I try to run it using a simple test case like (leaf-count '(leaf 5)) I get the following error message: car: expects argument of type pair; given leaf What does this error message mean? I am defining a leaf as a list. But for some reason, it's not seeing that and gives me that error message.

    Read the article

  • Effects of changing a node in a binary tree

    - by eSKay
    Suppose I want to change the orange node in the following tree. So, the only other change I'll need to make is in the left pointer of the green node. The blue node will remain the same. Am I wrong somewhere? Because according to this article (that explains zippers), even the blue node needs to be changed. Similarly, in this picture (recolored) from the same article, why do we change the orange nodes at all (when we change x)?

    Read the article

  • Versioning friendly, extendible binary file format

    - by Bas Bossink
    In the project I'm currently working on there is a need to save a sizable data structure to disk (edit: think dozens of MB's). Being an optimist, I thought that there must be a standard solution for such a problem; however, up to now I haven't found a solution that satisfies the following requirements: .NET 2.0 support, preferably with a FOSS implementation Version friendly (this should be interpreted as: reading an old version of the format should be relatively simple if the changes in the underlying data structure are simple, say adding/dropping fields) Ability to do some form of random access where part of the data can be extended after initial creation (think of this as extending intermediate results) Space and time efficient (XML has been excluded as option given this requirement) Options considered so far: Protocol Buffers: was turned down by verdict of the documentation about Large Data Sets - since this comment suggested adding another layer on top, this would call for additional complexity which I wish to have handled by the file format itself. HDF5,EXI: do not seem to have .net implementations SQLite/SQL Server Compact edition: the data structure at hand would result in a pretty complex table structure that seems too heavyweight for the intended use BSON: does not appear to support requirement 3. Fast Infoset: only seems to have paid .NET implementations. Any recommendations or pointers are greatly appreciated. Furthermore if you believe any of the information above is not true, please provide pointers/examples to prove me wrong.

    Read the article

  • Working with bytes and binary data in Python

    - by ignoramus
    Four consecutive bytes in a byte string together specify some value. However, only 7 bits in each byte are used; the most significant bit is ignored (that makes 28 bits altogether). So... b"\x00\x00\x02\x01" would be 000 0000 000 0000 000 0010 000 0001. Or, for the sake of legibility, 10 000 0001. That's the value the four bytes represent. But I want a decimal, so I do this: >>> 0b100000001 257 I can work all that out myself, but how would I incorporate it into a program?

    Read the article

  • Reading Binary data from a Serial Port.

    - by rross
    I previously have been reading NMEA data from a GPS via a serial port using C#. Now I'm doing something similar, but instead of GPS from a serial. I'm attempting to read a KISS Statement from a TNC. I'm using this event handler. comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived); Here is port_DataReceived. private void port_DataReceived(object sender, SerialDataReceivedEventArgs e) { string data = comport.ReadExisting(); sBuffer = data; try { this.Invoke(new EventHandler(delegate { ProcessBuffer(sBuffer); })); } catch { } } The problem I'm having is that the method is being called several times per statement. So the ProcessBuffer method is being called with only a partial statment. How can I read the whole statement?

    Read the article

  • latest Xemacs on Windows binary download

    - by anjanb
    I'm trying to get an updated version for Windows vista. I previously got 21.4.22 but it's been a year since that release. The linux versions should be 22.x. I'm wondering if anyone else builds stable binaries for Windows ? 21.4.22 has several bugs and I cannot figure out how to fix them. I know Xemacs is not as active as GNU emacs but still aren't there any Xemacs users on windows who build their own copies even if the official site doesn't ? I would like to be able to compare buffers, files and directories apart from being able to edit any file : java, javascript, ruby, .bat, .sh, .xml, etc.

    Read the article

  • Getting Image size of JPEG from its binary

    - by rajeshsr
    Hi I have a lot of jpeg files with varying image size. For instance, here is the first 640 bytes as given by hexdump of an image of size 256*384(pixels): 0000000: ffd8 ffe0 0010 4a46 4946 0001 0101 0048 ......JFIF.....H 0000010: 0048 0000 ffdb 0043 0003 0202 0302 0203 .H.....C........ 0000020: 0303 0304 0303 0405 0805 0504 0405 0a07 ................ 0000030: 0706 080c 0a0c 0c0b 0a0b 0b0d 0e12 100d ................ I guess the size information mus be within these lines. But am unable to see which bytes give the sizes correctly. Can anyone help me find the fields that contains the size information?

    Read the article

  • C++ string array binary search

    - by Jose Vega
    string Haystack[] = { "Alabama", "Alaska", "American Samoa", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Guam", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Northern Mariana Islands", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Puerto Rico", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "US Virgin Islands", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"}; string Needle = "Virginia"; if(std::binary_search(Haystack, Haystack+56, Needle)) cout<<"Found"; If I also wanted to find the location of the needle in the string array, is there an "easy" way to find out?

    Read the article

  • Need algorithm to add Node in binary tree

    - by m.qayyum
    •if your new element is less or equal than the current node, you go to the left subtree, otherwise to the right subtree and continue traversing •if you arrived at a node, where you can not go any deeper, because there is no subtree, this is the place to insert your new element (5)Root (3)-------^--------(7) (2)---^----(5) ^-----(8) (5)--^ i want to add this last node with data 5...but i can't figure it out...I need a algorithm to do that or in java language

    Read the article

  • Help With Lisp Code for a Binary Tree

    - by iulia
    I have (setq l2 '(1 (2 b (c 1 b))(a (1 2) d))) ( defun drumuri (l3) ( cond ( (atom l3) ( cons l3 nil)) ( t ( append ( cons ( car l3 ) nil) ( drumuri ( cadr l3)) (cons (car l3)nil) ( drumuri ( caddr l3)) )))) ( drumuri l2) and it gives me: Break 2 [4]> DRUMURI Break 2 [4]> (1 2 B 2 C 1 C B 1 A 1 2 1 NIL A D) but i need: ((1 2 B)(1 2 C 1)(1 2 C B)(1 A 1 2)(1 A D))

    Read the article

  • Recursive Binary Search Tree Insert

    - by Nick Sinklier
    So this is my first java program, but I've done c++ for a few years. I wrote what I think should work, but in fact it does not. So I had a stipulation of having to write a method for this call: tree.insertNode(value); where value is an int. I wanted to write it recursively, for obvious reasons, so I had to do a work around: public void insertNode(int key) { Node temp = new Node(key); if(root == null) root = temp; else insertNode(temp); } public void insertNode(Node temp) { if(root == null) root = temp; else if(temp.getKey() <= root.getKey()) insertNode(root.getLeft()); else insertNode(root.getRight()); } Thanks for any advice.

    Read the article

  • Nicely printing/showing a binary tree in Haskell

    - by nicole
    I have a tree data type: data Tree a b = Branch b (Tree a b) (Tree a b) | Leaf a ...and I need to make it an instance of Show, without using deriving. I have found that nicely displaying a little branch with two leaves is easy: instance (Show a, Show b) => Show (Tree a b) where show (Leaf x) = show x show (Branch val l r) = " " ++ show val ++ "\n" ++ show l ++ " " ++ show r But how can I extend a nice structure to a tree of arbitrary size? It seems like determining the spacing would require me to know just how many leaves will be at the very bottom (or maybe just how many leaves there are in total) so that I can allocate all the space I need there and just work 'up.' I would probably need to call a size function. I can see this being workable, but is that making it harder than it is?

    Read the article

  • A balanced binary search tree which is also a heap

    - by saeedn
    I'm looking for a data structure where each element in it has two keys. With one of them the structure is a BST and looking at the other one, data structure is a heap. With a little search, I found a structure called Treap. It uses the heap property with a random distribution on heap keys to make the BST balanced! What I want is a Balanced BST, which can be also a heap. The BST in Treap could be unbalanced if I insert elements with heap Key in the order of my choice. Is there such a data structure?

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >