Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i use "fscanf" and "fread" (matlab code) in Labview

Solved!
Go to solution

Hello, all,

 

i m trying to write a VI according to my matlab file, now i m confused about "fscanf" and "fread",

i used VISA-Read subVI for "fread" function but don't know which for the "fscanf"

and i don't know how the read the datamatrix with a subVI.

Is there someone can give me a tip, that will be very kind, thank you.

 

yours

 

Adam

0 Kudos
Message 1 of 10
(7,366 Views)
I thought fscanf read from a file?

In any case, there are several functions that you might use on the string returned by a VISA Read. There is Spreadsheet String to Array and Scan From String. You did not provide an example of the string or expected results. Essential information and when missing, an exact answer cannot be given.
0 Kudos
Message 2 of 10
(7,358 Views)

thank you for you answers,


here is the example:

s1=serial('COM1');

...

A=fscanf(s1,'%s');

A=fread(s1,2);

B=fread(s1,[2 messurePoint]);

 

so i m reading from the serial port

0 Kudos
Message 3 of 10
(7,353 Views)
Just do a VISA Read and report back what it returns. You can also run the basic serial example.
0 Kudos
Message 4 of 10
(7,350 Views)

i don't quit understand what are you mean, could you explain a little more?

i have seen all the serial examples, but they aren't help.

0 Kudos
Message 5 of 10
(7,322 Views)
The only way to capture data is with a VISA Read. If you cannot understand the string returned or need help in converting it, you need to attach the actual string that you read.

Explain what you mean by 'aren't help'. That is an inadequate description.
0 Kudos
Message 6 of 10
(7,312 Views)

first thank you for your answer. the problem is when i want to read the datamatrix from the hardware with "fread(s1, [2 points])", i don't know how to realize it in Labview, and i can't find answers in LabviewHelp.

Yesterday i fund the subVI "VISA Bytes at Serial Port", but i can't set the byte width like in Matlab "fread(s1, 2)".

thanks again for your time.

 

0 Kudos
Message 7 of 10
(7,306 Views)
You aren't looking very closely, then. If your problem is not knowing how to set the number of bytes to read, you have not looked at the VISA Read function. A very noticeable input is the byte count.
0 Kudos
Message 8 of 10
(7,301 Views)
Solution
Accepted by topic author Adamyuan

hello, everyone,

 

i think i find out how to solve my problem.(Serial Device Controll)

fscanf is indeed expressed as VISA-Read in Labview, and very time you use fscanf, it means to write something in the memorizer of the device,

e.g:

fprintf=VISA-Write

fscanf=VISA-Read, but the Value which been readed is storaged in the memorizer of the device, when you make a indicator for the output of the VISA-Read, this Value will be showed and delete from the device memorizer. This is for my Device OTDR, i m not sure whether it's all right for other Device.

 

When you want to read the datamatrix, for example 2D, just use VISA-Read two times.


When you still have questions about this, feel free to ake, i will try to answer you.

 

Yours

 

Adam Yuan

 

0 Kudos
Message 9 of 10
(7,227 Views)
0 Kudos
Message 10 of 10
(7,223 Views)