sjukheter Posted March 15, 2011 Report Share Posted March 15, 2011 Hi, I want to write a byte of data to serial device. Byte indicates (7 bits representing address and one bit representing read or write operation). So, I don't have any idea to write in manner to serial device. Now i am writing address 10(00001010) and 0 or 1 separately and it is totally wrong. Please some one suggest me how can I write this to write visa. Quote Link to comment
ned Posted March 15, 2011 Report Share Posted March 15, 2011 Hi, I want to write a byte of data to serial device. Byte indicates (7 bits representing address and one bit representing read or write operation). So, I don't have any idea to write in manner to serial device. Now i am writing address 10(00001010) and 0 or 1 separately and it is totally wrong. Please some one suggest me how can I write this to write visa. Easiest thing to do is create an array of 8 booleans, then use Boolean Array to Number, and convert the output of that to U8, which will give you a single byte with the bits arranged the same way they were in your boolean array. Quote Link to comment
crelf Posted March 15, 2011 Report Share Posted March 15, 2011 Now i am writing address 10(00001010) and 0 or 1 separately and it is totally wrong. Please some one suggest me how can I write this to write visa. Upload what you've already tried and we'll try to help. Quote Link to comment
sjukheter Posted March 15, 2011 Author Report Share Posted March 15, 2011 Upload what you've already tried and we'll try to help. Now i am doing totally wrong and you can see in the attached VI. I have one more doubt that i am using virtuval comport USB to my PIC. I don't know the basic communication ruls. What type of communication am i using. USART or UART? rajnew.vi Quote Link to comment
crelf Posted March 15, 2011 Report Share Posted March 15, 2011 Now i am doing totally wrong and you can see in the attached VI. I can't really see what you're doing from the example you gave - maybe try to break it down to just the area where the problem is. Here's an example of a couple of ways to write a byte to the serial port. Write Byte to Serial Port.vi Quote Link to comment
sjukheter Posted March 16, 2011 Author Report Share Posted March 16, 2011 I can't really see what you're doing from the example you gave - maybe try to break it down to just the area where the problem is. Here's an example of a couple of ways to write a byte to the serial port. No, its difficult for me make it in expexted way. You can see in my code, first event case, I am writing all the addresses to serial device from 0 to 127 because it represents 7 bit address and the LSB bit should be read bit or write bit whicjh i did not sending now. I am sending all the addresses as 8 bit ans its totally wrong. Also you can see in other event cases i am using local variable of selected address but ther also i am adding read bit bit and write bit. Its totally wrong because it is considering both as two bytes. so i want to add these write bit and read bit in all cases. More I want to block the controls(from 3rd event case on wards) with some range values i.e. User can enter values.only between in those ranges. Hope you can suggest me. Quote Link to comment
jgcode Posted March 16, 2011 Report Share Posted March 16, 2011 More I want to block the controls(from 3rd event case on wards) with some range values i.e. User can enter values.only between in those ranges. Hope you can suggest me. Hi Sjukheter For any Control, you can pop-up (right click) on it and select Data Range... This will load the Properties Dialog to that tab. From here uncheck Use Default Range and then enter your own parameters. A good tip is anytime you are looking to do things try popping up on stuff - there is heaps of functionality available there. Cheers -JG Quote Link to comment
sjukheter Posted March 16, 2011 Author Report Share Posted March 16, 2011 Hi Sjukheter For any Control, you can pop-up (right click) on it and select Data Range... This will load the Properties Dialog to that tab. From here uncheck Use Default Range and then enter your own parameters. A good tip is anytime you are looking to do things try popping up on stuff - there is heaps of functionality available there. Cheers -JG nice option and i will do it immediatlly but the i want display a message to user in the case of limit exceeds dy displaying the popup message. For that i will take user dailogue Vis and implementation is bit unknown for me. Quote Link to comment
jgcode Posted March 16, 2011 Report Share Posted March 16, 2011 nice option and i will do it immediatlly but the i want display a message to user in the case of limit exceeds dy displaying the popup message. For that i will take user dailogue Vis and implementation is bit unknown for me. Well then you will have to precheck the input by performing your own logic, correct the response if invalid, then prompt the user with a dialog. This seems like a lot of extra work and possibly intrusive from a User Interface point of view (repeatedly having to click on a dialog). You may find taking advantage of the built in coercion couple with for example, a tip strip\help may be a more graceful response or something similar to this. Depends on your requirements I guess. Cheers -JG Quote Link to comment
ShaunR Posted March 16, 2011 Report Share Posted March 16, 2011 (edited) No, its difficult for me make it in expexted way. You can see in my code, first event case, I am writing all the addresses to serial device from 0 to 127 because it represents 7 bit address and the LSB bit should be read bit or write bit whicjh i did not sending now. Like this? Edited March 16, 2011 by ShaunR Quote Link to comment
sjukheter Posted March 16, 2011 Author Report Share Posted March 16, 2011 Like this? Please, repost the last example VI in 8.5 version. So that i can see the given example.. Quote Link to comment
ShaunR Posted March 16, 2011 Report Share Posted March 16, 2011 Please, repost the last example VI in 8.5 version. So that i can see the given example.. Well. It's the same as the image ....but Quote Link to comment
sjukheter Posted March 17, 2011 Author Report Share Posted March 17, 2011 Well. It's the same as the image ....but Hi, I supposed to say that the given logic wold not work. I did not check with the device though i would like to send always addresses from 0 to 127. After the logic shift this value is chnaging to some other value and i guess this make some difference. You can see in the below attchment for packet structure. LSB isalwyas for indicating Read/write operation. Why really logic shift is there in the given example. I did not undestand. weather it acts like what i ecpected.. Doc1.doc Quote Link to comment
ShaunR Posted March 17, 2011 Report Share Posted March 17, 2011 Hi, I supposed to say that the given logic wold not work. I did not check with the device though i would like to send always addresses from 0 to 127. After the logic shift this value is chnaging to some other value and i guess this make some difference. You can see in the below attchment for packet structure. LSB isalwyas for indicating Read/write operation. Why really logic shift is there in the given example. I did not undestand. weather it acts like what i ecpected.. When you manipulate an integer it is always based from bit 0 i.e integer 1 = 00000001 (2^8 = 256 possible addresses). But that bit (LSB , bit 0)is used as a read/write flag. So Address 1 = 00000010 (integer 2 for a read) or 00000011 (Integer 3 for a write). Therefore the address is shifted by 1 bit and you are only using the top 7 bits (2^7 = 128 possible addresses) You can then OR your read/write flag into bit 0. If you were to send a U8 with the value of 1, you would in fact saying "write to Address 0". Sending. Integer 2 would be "read from address 1". and Integer 3 would be "write to address 1 etc. U8 (0) = 0000000 0 = read from address 0 U8 (1) = 0000000 1 = write to address 0 U8 (2) = 0000001 0 = read from address 1 U9 (3) = 0000001 1 = write to address 1 Quote Link to comment
sjukheter Posted March 18, 2011 Author Report Share Posted March 18, 2011 When you manipulate an integer it is always based from bit 0 i.e integer 1 = 00000001 (2^8 = 256 possible addresses). But that bit (LSB , bit 0)is used as a read/write flag. So Address 1 = 00000010 (integer 2 for a read) or 00000011 (Integer 3 for a write). Therefore the address is shifted by 1 bit and you are only using the top 7 bits (2^7 = 128 possible addresses) You can then OR your read/write flag into bit 0. If you were to send a U8 with the value of 1, you would in fact saying "write to Address 0". Sending. Integer 2 would be "read from address 1". and Integer 3 would be "write to address 1 etc. U8 (0) = 0000000 0 = read from address 0 U8 (1) = 0000000 1 = write to address 0 U8 (2) = 0000001 0 = read from address 1 U9 (3) = 0000001 1 = write to address 1 thanks for your kind information though i would not clear my self. Before, i did not check with the real device at the moment and i am just checking with 32 bit microcontroller. SO, I am just making address search and displaying then all in dropdownlist. As you said, if i send 0 to 127 then shift makes the difference and change these all values to some other values. I am guessing that device address will be in range between 0 to 127 but after the shift values are changing to some others. Is it ok to continue? Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.