11-06-2019 04:56 AM - edited 11-06-2019 05:34 AM
The read return count changes at times. Thus making the communication to be lost and re establish itself when the return count comes back to normal. I am using an RS232 cable and serial port to communicate with Nanotech C5 motion controller. Kindly Help !
Solved! Go to Solution.
11-06-2019 08:21 AM
I would imagine that the two independent loops each writing/reading from the same bus might be the cause of your issue. You could end up with something like the following:
string wr1 | | string rd1
| string wr |
Uncertain how the instrument might react
11-06-2019 08:53 AM
As stated in one of your other threads, you are dealing with raw/hex/binary data. Therefore you need to make sure the Termination Character is turned OFF. Otherwise, if there just happens to be a 0xA byte in your message, the read will end there and you will not have all of your message. Use the VISA Configure Serial Port. One of the inputs on the top is to enable the termination character. Set that to FALSE.
11-06-2019 10:03 AM
I tried setting the termination character to false in the visa configure serial port. But Still the return count from visa read changes. I am expecting a return count of 23 from the visa read. But I obtain a return count of 4 at times which changes to 23 after a while.
11-06-2019 11:23 AM
So is the 4chars response some sort of error? What does the 4 char response mean according to the instrument manual?
One solution is to put the read-write in a while loop, use a case statement to catch the 4 vs 23 char cases, repeat the write-read for 4 char and continue for 23 char cases.
It likely that you are doing the read too quickly after the write and a short delay (10ms? 100ms?) might prevent the 4char responses.
Craig
11-06-2019 11:29 AM
Remove the VISA Open. That might be resetting all of your settings.
11-07-2019 03:09 AM
I removed visa open and tried but there is still an issue with my visa read.
11-07-2019 03:13 AM - edited 11-07-2019 03:14 AM
I am expecting my string(Hexadecimal string) read to be : 4E54 0013 052B 0D00 0001 60FD 0000 0000 0400 0003 0096 00 (23 bytes). But I get a return count of 19 from my visa read at times (randomly ) which changes my string read to :0003 0096 (4 bytes) causing a timeout in my visa read.
11-07-2019 10:50 AM
As Minions pointed out, you are hammering away at the instrument in two parallel loops. You might want to introduce a small delay between Write and Read. You might also want to capture when the read byte count isn't correct and do something. Here's a first take at just repeating the Write, delay, Read process when the read count and byte count are not equal.
I'd run this and monitor when the loop has to iterate more than once (read count) and track down the source of the problems.
Craig
11-08-2019 01:17 PM - edited 11-08-2019 01:18 PM
The problem was using two parallel loops. Whenever the read file in both the loops tried to access the resource at the same time, it got timed out thus causing an error. I made a serial connection and it started to work well.