Jump to content

writing one byte to serial device


Recommended Posts

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.

Link to comment

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.

Link to comment

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.

Link to comment

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.

post-10325-0-11177700-1300262998_thumb.p

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

Link to comment

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.

post-10325-0-11177700-1300262998_thumb.p

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.

Link to comment

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

Link to comment

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 by ShaunR
Link to comment

Well. It's the same as the image shifty.gif....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

Link to comment

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

Link to comment

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?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.