LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA read/write to serial port - Unable to impelement multiple write commands!

Solved!
Go to solution
Highlighted

Hi,

 

I am new to Labview and I am trying to read from a pressure sensor through a USB virtual serial port. I am able to read port when using HyperTerminal

 

The code sequence I should be writing to port in order to get measurements using hyperterminal is the following :

 

'*' (2A hex) => start, and the port replies by asking "Command", I should then enter

FF => measurement select, the port should ask for the "mode", I should therefore enter

0A => high resolution measurement mode, and it is then that I should start receiving measurements.

 

The port is always responding by errors when I write the start command or the FF one. I tried implemeting a stacked sequence to write the three commands and then read the port, I added some delay between the three of them but it doesn't work.

 

Now, I made it really simple and took off the stacked sequence and just put the three commands one after the other, and trying to fix it by single stepping over the code.

 

I am really stuck at this point, could anybody help me please? I read a lot fo articles on the forum but I am unable to fix this issue

 

Thanks,

 

I attached my VI, and the SCP1000 documentation (I can provide other versions of my demo if needed)

 

 

0 Kudos
Message 1 of 13
(4,569 Views)
Highlighted
can you post the vi for lv 8.0?
0 Kudos
Message 2 of 13
(4,554 Views)
Highlighted

The port is always responding by errors when I write the start command or the FF one

 

Can you please specify the exact error that you are getting?

0 Kudos
Message 3 of 13
(4,554 Views)
Highlighted
Solution
Accepted by topic author The Dice Man

The reason for your problem is a very common misapprehension even among experienced programmers. Just take a look at this thread

http://forums.ni.com/ni/board/message?board.id=170&thread.id=417750

In your data sheet then they refer codes like 0xFF or 0x0A so does this mean a one byte value. Then you in your \ code enabled constant write FF\n so is this equal to the values in hex 46460A and your instrument do not understand it. But it will understand FF0A. So to fix your problem you must type in \FF\n in your '\' codes enabled string. Remember also if you type in \32 it will be converted to character 2 this because 0x32 is 50 decimal and the ASCII code 50 is equal 2

Take some time and swap the string dispaly format between '\' display and Hex display and you will see the difference 😉

Hopes this helps

 



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 4 of 13
(4,555 Views)
Highlighted

Hi guys, thank you for you response,

 

I am using lv 8.5 and I do not know if it is possible to convert my VI to lb 8.0 or I would do it, is that possible?


Coq rouge wrote:

The reason for your problem is a very common misapprehension even among experienced programmers. Just take a look at this thread

http://forums.ni.com/ni/board/message?board.id=170&thread.id=417750

In your data sheet then they refer codes like 0xFF or 0x0A so does this mean a one byte value. Then you in your \ code enabled constant write FF\n so is this equal to the values in hex 46460A and your instrument do not understand it. But it will understand FF0A. So to fix your problem you must type in \FF\n in your '\' codes enabled string. Remember also if you type in \32 it will be converted to character 2 this because 0x32 is 50 decimal and the ASCII code 50 is equal 2

Take some time and swap the string dispaly format between '\' display and Hex display and you will see the difference 😉

Hopes this helps

 


Le coq rouge, I already read the thread you're pointing before I post my question, it confused me a bit, but I will read it again now

 

I tried to swap between \code display, normal displa and hex display and watch the behaviour of the VI but it still not working properly. The errors are not visa read/write errors, but the device doesn't seem to understand my commands.

 

I will explain the communication protocol. It is a command/response archi I believe, I will atach a screen shot of a simple VI and let me know guys if what I am doing is correct or not. Should I read port after each command I sent to it?

 

'*' => start command, the device is supposed to get back to me with the software version and asking for the next command

0xFF => set device to measurement mode, the device should come back to me asking to specify mode,

0x0A or 0x09 => high resolution/high speed measurement modes.

Threafter it should start transmitting measurements,

 

Now, I implemented the write procedures in a stacked sequence, but when I read the port, it always displays :

 

error

command

error command

 

or as the screen shot shows, it only processes the start command and keep asking for the next command while I already wrote it to port..

 

Please help me, it is an urgent matter as I should hand this back in by the end of the week. This is my first time I use Labview,

Message Edited by The Dice Man on 06-23-2009 10:14 AM
Download All
0 Kudos
Message 5 of 13
(4,524 Views)
Highlighted

Your front panel controls are set to \codes display, and show 0A, which means they will send a "0" then an "A".  (Change to hex mode display and you will see 2 bytes of hex 30 and 41 are being sent.

 

In slash code display, make it \0A in the string control.  Then switch to hex mode display and you will see it is 0A hex.

 

(Is it me, but is there a rash of people getting string control displays completely mixed up? This is the 2nd thread today that has been linked to the other thread which was just occurring in the last couple days.)

0 Kudos
Message 6 of 13
(4,516 Views)
Highlighted

Hi Ravens, thank you for your quick reply,

 

I have changed it to \09\n (which is just another measurement mode as the \0A) one. And you can see the attachment that I have put above (just before your reply)

 

It seems that start command has been read properly, and as you can see in the read string display, it is asking for the next command, which in this case \FF\n that I already wrote to port.

 

My concern is, do I have to read port within my stacked sequ. after each write command?

 

Thanks again,

 

Message Edited by The Dice Man on 06-23-2009 10:27 AM
0 Kudos
Message 7 of 13
(4,510 Views)
Highlighted

If I am not wrong your pressure unit is not made for standard RS232 but something called SPI OR TWI. This is synchronous data transfer format RS232 is asynchronous. So You will never be able to read from your device with a standard serial port. I think You need the "NI USB-8451" or something compatible. You will find other devices that cost less than the NI USB-8451 but You may end up with the same cost if You count time used to get it on air I think 😉



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 8 of 13
(4,506 Views)
Highlighted

Hi Le Coq Rouge,

 

Yeah, it is a SPI/TWI communication protocol. I thought I would be able to use the standard VISA serial read/write to communicate with my device.

 

Is there another way of overcoming this without the need to buy NI USB-8451?

 

Thanks man,

0 Kudos
Message 9 of 13
(4,503 Views)
Highlighted
Perhaps with a micro-controller That use SPI and send back data in RS232 format. But then again time is money 😉


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 10 of 13
(4,500 Views)