Jump to content

LabVIEW direct command using VISA


Buglish

Recommended Posts

Hi,

I have created a button interface in LabVIEW that when pressed it will write a string into the VISA port directly using a serial connection of my blue tooth connection. This is after the NXT block is paired.

I am having trouble understanding the packet format that has to be sent in hex.

Other forums show they created a array then convert it to string again to send using VISA in the Fantom SDK.

I am bypassing that by creating the connection beforehand.

From what I understand I can start the program using a array which is converted to hex. But that format I am not sure I am implementing correctly.

Start of program : (0x00,0x00,Spike Remote 0xA,0x02,0x00,StatusByte)

Send Integer value of 1 : (0x00,0x09,1,1,2-10)

When Converted its

3078 3030 2C30 7830 392C 312C 322C 31

Perhaps I should remove the commas and send this hex >3078 3030 2030 7830 3920 3120 3120 32

But the NXT block is not responding...what should the format be?

Do I have to convert it to hex before sending?

What format do I have to use since ',' = 392C . Do I have to include the commas?

Thanks

Link to comment
...Send Integer value of 1 : (0x00,0x09,1,1,2-10)

When Converted its

3078 3030 2C30 7830 392C 312C 322C 31

Perhaps I should remove the commas and send this hex >3078 3030 2030 7830 3920 3120 3120 32

I don't think you should convert the ASCII values to hex, but rather the values contained in the string.

Your output "3078 3030 2C30 7830 392C 312C 322C 31" is the hex representation of the ASCII sequence "0x00,0x09,1,2,1".

If you are going to send this sequence as hex, I would guess that your program expects the following hex representation

"0009010201".

So if you have a U8-array with the values [00, 09, 01, 02, 01], feed this array into the "Byte Array To String" function (or a typecast node), and the output will be the string to send. Or enter the values manually in a string control that is set to display strings as hex values, then just send this string.

/J

Link to comment
I don't think you should convert the ASCII values to hex, but rather the values contained in the string.

Your output "3078 3030 2C30 7830 392C 312C 322C 31" is the hex representation of the ASCII sequence "0x00,0x09,1,2,1".

If you are going to send this sequence as hex, I would guess that your program expects the following hex representation

"0009010201".

So if you have a U8-array with the values [00, 09, 01, 02, 01], feed this array into the "Byte Array To String" function (or a typecast node), and the output will be the string to send. Or enter the values manually in a string control that is set to display strings as hex values, then just send this string.

/J

Hi JFM,

Well all I want to do is send an integer between 0-5 to the NXT block.

What would the message format be?

Link to comment
What would the message format be?

It would be easier if you could show some code.

I also think I slipped when I said

So if you have a U8-array with the values [00, 09, 01, 02, 01], feed this array into the "Byte Array To String" function (or a typecast node), and the output will be the string to send. Or enter the values manually in a string control that is set to display strings as hex values, then just send this string.

sorry for that.

/J

Link to comment
Hi

I have tried this method though the NXT block is not responding.

Just ignore the web cam controls on the bottom.

Just some quick notes:

1. your program are using I32 constants instead of U8 (doesn't really matter)

2. you could implement this with an event structure, to get more direct user response

3. I personally prefer to open/close VISA sessions explicitly

Do you get any errors? If so what errors do you get?

/J

Link to comment
Just some quick notes:

1. your program are using I32 constants instead of U8 (doesn't really matter)

2. you could implement this with an event structure, to get more direct user response

3. I personally prefer to open/close VISA sessions explicitly

Do you get any errors? If so what errors do you get?

/J

:throwpc:

The return count of the VISA prints out 8.

So the connection works since data is sent to the NXT block but the response is a bit off :/

I am not sure how to control the data bit.

If you do a format and precision on the number inputs you will see its hex

-----------------

Ok I have a response of an error

Possible reason(s):

LabVIEW: File permission error.

---

NI-488: DMA hardware error detected.

Ok whats this?

Link to comment

I have started from scratch and now I am using the Fantom SDK. Though compiling the arrays of hex commands is kind of difficult.

The vi I am including searches for the NXT block then pairs up.

The problem is starting the application I need.

I have converted "spike remote" to the hex"5370 696B 6520 5265 6D6F 7465 " to start the application.

And sending messages to mail box 1 with the data of a number between 1-6 is not working :/

Please help me create the packets.

Regards Bug

Download File:post-5518-1163576324.vi

Link to comment
Hi All,

I have figured it out. See the pics :P

Well done :thumbup:

I'm sorry I haven't replyed to your last posts, but my knowledge regarding the Fantom SDK is NIL :blink:

By the looks of your program, I think you should add error handling in the loops, maybe break loop execution upon an error?

There is also no visible delay in the upper loop, and this together with the lack of error handling can get you into trouble.

/J

Link to comment
And in regards to the loop control with a timer. That also gave in expected results where if button is pressed the bot would go into loop(or just pressed a few times if you press it once)

I had a little time on my hands this morning, so I've rewritten some of your code with a couple of suggestions to save a little memory and boost performance. I don't have the NXT toolkit installed, so I don't suggest that my code will work perfectly (if at all ;) ), but hopefully it'll introduce you to a couple of techniques...

post-181-1163778320.png?width=400

Download File:post-181-1163778178.vi

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.