LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Commniucation with port com

Hello,

I made the following program to communicate with the Serial port (Com port). Through this program, I send commands to the device, but it happens nothing.  Thank-you. When I send  with Terminal program commands to the device. It Works. Can anyone give me a solution.

111.JPG

0 Kudos
Message 1 of 15
(567 Views)

@Sina6611 wrote:

Hello,

I made the following program to communicate with the Serial port (Com port). Through this program, I send commands to the device, but it happens nothing.  Thank-you. When I send  with Terminal program commands to the device. It Works.


Nothing principal wrong except unusually high baud rate and Open Visa in while loop - you don't need this and may be give some time to device before read it and sending new command.

Original "Simple Serial" Example from NI looks like this:

SimpleSerial.png

If you run this in cycle, then you must be sure that your device is able to handle commands and respond at this while loop iterations rate and you read complete response before sending new command.

 

If you wrote "It Works" what is your problem actually?

Message 2 of 15
(552 Views)

As stated over and over again in this forum, you should not use Bytes at Port. It's far better to set the proper Termination Character (usually Linefeed or Carriage return, although it can be another character) and let VISA terminate the Read when this specific character is received.

Furthermore, your Wait function does not affect the Write-Read sequence because it's executed in parallel (check the Dataflow concept), so your program writes the command and immediately checks if there is any response character (obviously there is nothing).

 

Here is a link to a thorough presentation on this subject:

VIWeek 2020/Proper way to communicate over serial

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 3 of 15
(528 Views)

Hi Sina,

 


@Sina6611 wrote:

Through this program, I send commands to the device, but it happens nothing.


Reading BytesAtPort immediatly after VISAWrite is wrong.

Using BytesAtPort together with using a TermChar is also (most often) wrong.

Setting a timeout of 100s might irritate the user of your VI…

A baudrate of (exactly) 250kbaud is quite uncommon.

 

Please watch this video before starting serial communication with your device!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 15
(527 Views)

@pincpanter wrote:

As stated over and over again in this forum, you should not use Bytes at Port. It's far better to set the proper Termination Character (usually Linefeed or Carriage return, although it can be another character) and let VISA terminate the Read when this specific character is received.

Furthermore, your Wait function does not affect the Write-Read sequence because it's executed in parallel (check the Dataflow concept), so your program writes the command and immediately checks if there is any response character (obviously there is nothing).

 

Here is a link to a thorough presentation on this subject:

VIWeek 2020/Proper way to communicate over serial


Then you should explain this to NI first to remove this from standard NI examples. In general this way could be helpful at the beginning if developer would like to check if something in port at all then read. But later replace it with reading till terminator or fixed amount of bytes, agree. I've used this several times during putting some specific devices into operation, but haven't any in production code at the end.

0 Kudos
Message 5 of 15
(514 Views)

@Sina6611 wrote:

When I send  with Terminal program commands to the device. It Works. Can anyone give me a solution.

 


Please share with us the screenshot of your terminal with command you sent and response as well as the whole settings of the terminal, then we can help, probably.

0 Kudos
Message 6 of 15
(512 Views)

Hi Sina,

 


@Sina6611 wrote:

When I send  with Terminal program commands to the device. It Works.


Does your terminal program automatically append LF/CR chars (LineFeed/CarriageReturn) to each message?

If it does then you should do this in your VI too!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 15
(506 Views)

Can you send me a link please?

0 Kudos
Message 8 of 15
(488 Views)

It works with Terminal software and doesn't with my Lab view vi. 

0 Kudos
Message 9 of 15
(486 Views)

Hi Sina,

 


@Sina6611 wrote:

Can you send me a link please?


Who is "you"?

 

You got so many links to the same video tutorial: please watch it!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 15
(482 Views)