LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help in rs232 serial communication

Highlighted

Hi

 

I have problem in rs-232c communication.

 

I'm using nl-42 sound meter.

 

I read serial manual but I can't understand command.

 

I add string with \n\r too in manual ,but nothing respond.

 

In my opinion I don't understand command exactly.

 

I add serial manual too. please somebody help me~!~!

 

캡처7.PNG캡처8.PNG

 

 

캡처2.PNG캡처3.PNG캡처4.PNG캡처5.PNG캡처6.PNG

 

 

 

캡처.PNG

0 Kudos
Message 1 of 16
(386 Views)
Highlighted

I think a few hints about how to configure and use VISA will solve most of your problems.

  • Look at the VISA Configure Serial Port function.  Do you see the "F" you put on the "Enable Termination Character (T)" terminal?  Erase it, and let it take its Default Value (T).  Modern Serial devices, including the one you are using, communicate in "Commands" that end in a Termination Character (<LF>, by default) -- you want to take advantage of this.
  • Between the VISA Write function and the VISA Read function, you have a "Bytes at Port" Property node.  Remove it, and connect the VISA Write directly to the VISA Read.
  • Modify the VISA Read by wiring a constant value (a common value to use is 1000, though I prefer 1024) to the number of Bytes to read.

Now, your code will work (probably), assuming you've set up the other parameters such as the Baud Rate and the other numeric specifications (the N-8-1 configuration is probably the most common, and is, I think, the default, so you probably don't need to wire any of the parameters (except Baud Rate) to Configure Serial Port.

 

So you send your Instrument a serial Command, ending in <CR><LF>.  You then do a VISA Read of (say) 1024 Bytes.  Your Instruments sends you a response ("Hello, Human, What is your name? <CR><LF>") (that is probably not what it will send, but it will end in the <CR><LF>).  Because you've enabled Termination Character and asked for more Bytes than it is sending, you'll get the entire Response String, and nothing else.  Now all you have to do is to do some String parsing to figure out what the command response was, and if it has numeric data, how to "extract" it.

 

Here's a hint -- look at "Scan from String" (on the String Palette).  For example, the Clock command gives you three numbers separated by "/", a space, then three number separated by Colons.  You can probably parse this with "%d/%d/%d %d:%d:%d" and get it to give you back 6 integer values ...

 

Bob Schor

Message 2 of 16
(345 Views)
Highlighted

DO NOT USE BYTES AT PORT!  It is the wrong thing to use 99% of the time.

 

You check the bytes at port immediately after you sent the message.  You gave the device zero time to receive the message, act on it, and return any data.  Even the LabVIEW examples which use bytes at port (and they are poor examples) show to put a wait in there.

 

Read Crossrulz's recent VI Week presentation for tips on how to do serial communication properly in LabVIEW.

Message 3 of 16
(339 Views)
Highlighted

Very thanks for your response.

 

I try like this but I have a timeout error ...

 

 

캡처9.PNG

0 Kudos
Message 4 of 16
(295 Views)
Highlighted

Thanks for your help.

 

I did like this but I got a timeout error...

 

I intall usb driver but doesn't response...

 

Please fix my code. 

 

Thank you again.

캡처9.PNG

0 Kudos
Message 5 of 16
(317 Views)
Highlighted

Hi odoria,

 


@odoria wrote:

I did like this but I got a timeout error...

I intall usb driver but doesn't response...


Which driver did you install?

Does the COM port appear in Windows device manager and in MAX?

Does that serial device come with software from the manufacturer?

Can you communicate with that device using either some "terminal" software (like HyperTerm or similar) or VISA test panel in MAX?

 


@odoria wrote:

Please fix my code. 


You did not attach any code so far: we cannot debug or edit images using LabVIEW!

 

A simple "fix" would be to use AutoCleanup…

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 6 of 16
(280 Views)
Highlighted

So are you using the RS-232 or the USB?  Notice that they are different connectors on the device and you have to set up the device to choose which one to use.  At the moment I suspect the device is not set up correctly and/or you are using the wrong connector.


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 7 of 16
(263 Views)
Highlighted

Yes im using rs232 and in NI MAX I can see

 

it's connected.

 

And I setting all same as manual.

 

Thanks for your help.

0 Kudos
Message 8 of 16
(228 Views)
Highlighted

Im using rs-232 cable and I set up too

 

device setring as rs-232 communication.

 

Setting same baudrate...etc .. in

 

communication manual.

 

Thanks for your help.

0 Kudos
Message 9 of 16
(226 Views)
Highlighted

I wonder if there is problem with the language settings on your PC.  In your first message it shows you are concatenating the carriage return and line feed characters onto your string to write by way of the string constants.   So that seems good.

 

But the screen show show and indicator for that result set for \code display mode.  It should look like $Echo,On\r\n  however you have other character in place of the \.  It looks like a W with a line through it.  It is like it is some other character up in the high end of the ASCII table.

 

Right after the concatenation, add a String to Byte Array function and put an indicator on that.  Expand it so we can see all the bytes.  Run your code and give us a screenshot.  I want to see what the byte values are for the string being sent and see if they are correct.  Those last two should be 13 and 10.

0 Kudos
Message 10 of 16
(198 Views)