Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting integer values from visa serial read

Solved!
Go to solution

Hi,

 

I am having trouble to get the correct integer values from the serial read string that i receive. E.g. If I send 0p3 i get 48,112,51 as array elements. I have used the string to byte array function to convert the string I read from the serial port. The values are the ascii equivalents. How can I get 0,p,3 back? I need these as the program further performs a length and crc check which go wrong as  0 is now taken as 48.

 

regards

Harshil.

0 Kudos
Message 1 of 19
(5,903 Views)

Hi

 

And what value would you assign to "p"?

Maybe the way you calculate the crc is wrong.

 

the value 48 is the normal ascii value for zero.

 

Maybe you have to explain a bit more about your requirements

greetings from the Netherlands
0 Kudos
Message 2 of 19
(5,897 Views)

I had used 0p3 just as an example. Well the serial port is reading from a gamma meter. The gamma meter sends its data in a kind of BCD format (where the each byte is 0-255).

 

E.g. The packet received has the length field of the data which is 2 bytes long (byte 2 and 3). For me to get the value of the length I have to do the following

 

length = data(2)*256 + data(3)  -- where data is the array of the data read from the serial port.

 

Using the string to byte array gives the ascii equivalents. Therefore if the value received was 5 then labview would give me 53 and 53*256 would be completely off.

 

Hope this clarifies. The overall scenario is that i am trying to convert matlab code into labview so that the gamma meter could be used with the clients system which runs labview.

I have also attached the matlab file as a txt file but you can change the extension to a .m file.

 

regards

Harshil

0 Kudos
Message 3 of 19
(5,879 Views)

Can you please post make/model of gamma meter and link to communications manual for this instrument?

0 Kudos
Message 4 of 19
(5,862 Views)

Hi,

 

I do not have the gamma meter model however, I do have te communication manual that I have attached. The device is working on mode 3.

 

regards

Harshil

0 Kudos
Message 5 of 19
(5,854 Views)

Harshil,

 

Do you have an example of an actual string received from the instrument?

0 Kudos
Message 6 of 19
(5,844 Views)

Hi,

 

Sorry but i do not have any data from the gamma meter. What the client has said when he ran the matlab program was that he got integer values. If it would help I can attach all the matlab files used to get data from the gamma meter.

 

Thanks for all your help.

 

regards

Harshil

0 Kudos
Message 7 of 19
(5,826 Views)

Harshil,

 

Still looking at the comm manual.  It appears to use a mixture of ASCII characters and hex values.

 

Are you setup to communicate with the instrument using the Matlab code?  If so, you could use NI-Spy to record what is happening when the Matlab code communicates with the instrument. 

                                                               

What version of LV are you running?

Message Edited by Wayne.C on 04-17-2009 09:47 AM
0 Kudos
Message 8 of 19
(5,816 Views)

Thanks for all your help Wayne ,

 

I do not have the gamme meter, it is at the clients site. What I have done temporarily is that I am reading the string, scanning each byte, converting it into a integer and then storing it into an array. The problem is if the gamma meter responds with a character in the string than the program will fail. I am going to try this method this week at the clients site and report back if it works. 

 

I also have another question. The total data the gamma meter could send would be upto nearly 500bytes. However this is not the case all the time. The problem is that I have set the VISA read to read 500 bytes. Whenever it reads anything less, it gives an error. How can I avoid this as I do not have control over the the data bytes that could come in?

 

Also, I am using Labview 8.5

 

regards

Harshil.

 

 

0 Kudos
Message 9 of 19
(5,781 Views)

Harshil,

 

You don't have to read the complete receive buffer at one time.  Each reply from the gamma meter includes the length of the message.  Read the first 3 bytes of reply from the instrument, parse out the LEN value.  You can then calulate how many bytes are remaining to be read. 

0 Kudos
Message 10 of 19
(5,775 Views)