04-15-2009 11:04 AM
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.
Solved! Go to Solution.
04-15-2009 12:29 PM
04-16-2009 03:45 AM
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
04-16-2009 10:04 AM
Can you please post make/model of gamma meter and link to communications manual for this instrument?
04-16-2009 10:36 AM
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
04-16-2009 12:53 PM
Harshil,
Do you have an example of an actual string received from the instrument?
04-17-2009 02:40 AM
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
04-17-2009 08:46 AM - edited 04-17-2009 08:47 AM
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?
04-20-2009 04:26 AM
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.
04-20-2009 06:56 AM
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.