04-11-2024 04:57 AM - edited 04-11-2024 05:01 AM
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.
04-11-2024 05:10 AM
@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:
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?
04-11-2024 05:35 AM
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:
04-11-2024 05:43 AM
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!
04-11-2024 05:54 AM
@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.
04-11-2024 05:57 AM
@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.
04-11-2024 06:05 AM
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!
04-11-2024 06:17 AM
Can you send me a link please?
04-11-2024 06:19 AM
It works with Terminal software and doesn't with my Lab view vi.
04-11-2024 06:21 AM
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!