From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Communicating with an instrument via serial port

I am new to the world of instrument communication and would like to communicate and control a mass flow controller. I have been given the commands to send to the controller to query for an address. They are:

 

MAC ID (Targeted MFC controller address)

STX(0x02)

Command code()x80 for read)

Packet length(0x03)

Class ID(0x03)

Instance ID(0x01)

Attribute ID(0x)1)

Pad(0x00)

Checksum

 

I would like to use the Serial Write command to send these to the controller but I am unsure how to type the commands in, or what syntax to use. If anyone out there is able to help that would be great.

 

Many thanks.

0 Kudos
Message 1 of 10
(4,232 Views)

If you are using the serial commands to communicate then its prettymuch easy.

You can refer to example shipped with the LabVIEW.

You can go to Menu>> Help >> Example finder and there is an example simple serial read write which you can save elsewhere and modify your code.

OR

http://www.ni.com/example/27669/en/

0 Kudos
Message 2 of 10
(4,226 Views)

Hi and thanks for that.   I've had a look at the example and it doesn't really let me know how to write the commands to send given that they are in hexadecimal format and there are a number of them.  If you've any ideas I'd love to hear them.

 

0 Kudos
Message 3 of 10
(4,223 Views)

@doljam wrote:

Hi and thanks for that.   I've had a look at the example and it doesn't really let me know how to write the commands to send given that they are in hexadecimal format and there are a number of them.  If you've any ideas I'd love to hear them.

 


You can change the string control in LabVIEW Front panel as HexaDecimal Display. Just right Click and select hexa decimal display

 

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 4 of 10
(4,219 Views)

Its not a problem that you are sending a HEX data or any other data as the data will be in string format so you will need to change the display format

You can go through this document and check how to send HEX data. You can also find the example attached to the document.

http://digital.ni.com/public.nsf/allkb/6C24F2F07BC23BB78625722800710865

0 Kudos
Message 5 of 10
(4,216 Views)

Perfect thanks for that.  One last question.  How do I include the Checksum requirement in each command?

 

0 Kudos
Message 6 of 10
(4,215 Views)

@doljam wrote:

Perfect thanks for that.  One last question.  How do I include the Checksum requirement in each command?

 


Checksum/CRC calculation has different methods. Common CRC calculation is to add all the payload otherthan header and Send along with the data.

Header

DataPayload

CRC

Need to send in this way

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 10
(4,205 Views)

Would you be able to tell me exactly what a CRC is and how it is coded.  Sorry if I appear to be asking nonsensical questions but I am learning fast!

Regards,

 

0 Kudos
Message 8 of 10
(4,176 Views)

Basic CRC is just adding the data which you are going to send to a device and append along with data, In the receiving end same will be decoded to verify wether all data has been received wihout any Loss. if both CRC Matches it means that data received without any loss.

 

Check this link, may be useful for you to understand on CRC calculation.

 

http://forums.ni.com/t5/LabVIEW/CRC-CCITT-16bit-Initial-Value-of-0xFFFF-or-0x1D0F/td-p/896664

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 9 of 10
(4,169 Views)

@doljam wrote:

Would you be able to tell me exactly what a CRC is and how it is coded.


A CRC is a check to make sure the data was recieved properly.  It can range from a simple adding of the bytes to some interesting shifting, masking, XOR, and inverting.  Unfortunately, you need to know how the instrument is calculating the CRC before you can even start to code that part up.

 

As far as creating your message, create an array of bytes for your data and then use Byte Array To String which will give you the raw data string to send via the VISA Write.  For the read, you can use the String To Byte Array and then Index Array and Array Subset to get the parts of the data you need.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 10
(4,132 Views)