01-13-2010 01:13 PM
I have a piece of equipment that requires P849 protocol via RS232-C. I can connect to the equipment using NI-M&A Explorer on the COM1 (ASRL1) device. The protocal is simple, send ascii 5 (ENQ character) and equipment replies with ascii 6 (ACK character) for handshaking. Then commands start with ascii 2 (STX character) followed <message> followed by ascii 3 (ETX character). I see appropiate responses but continue to get TMO errors ... I've tried various VI_ATTR settings but no progress made.
Is this simply an issue with VI_ATTR settings or can NiVisa just not handle this protocal?
small NI-SPY log attached.
Thanks in advance.
Solved! Go to Solution.
01-13-2010 01:29 PM
VISA should have no problems with this. Are you only using the VISA test panel or have you actually written some code? With no termination character, the read will timeout if it does not get the 300 bytes you are requesting. Have you tried enabling the term character and setting it to ACK?
One thing that's missing in the test panel is a way to read the number of bytes available at the serial port. With term character disabled, this is usually what is used to determine the number of bytes to actually read.
01-13-2010 02:32 PM
I can't use ACK as the termination character because the message string that gets sent and returned ends in ETX. I also can't reduce the buffer size since the equipment reply size is unknown (300 should be plenty). I know where is an option to replace chars, in this case ETX with ACK, but that will still break the communcation loop when I read the message reply.
I was using a Visa session from the M&A Explorer. I also have a Java program using JNI to also communicate with the equipment.
I dont have my notes with me but I believe the communication was like this
Host sends ENQ tool replyies with ACK
Host sends "STX <msg> ETX" tool will reply with ENQ
Host sends back ACK and tool replyies with "STX <msg reply> ETX"
Host sends ENQ tool replies with ACK
Thanks.
01-13-2010 02:59 PM
As I said, you are guaranteed a timeout if the request more bytes than are available and you have no termination character. That is what is supposed to happen.
Since the test panel in MAX is not intended to accomodate all conditions and is in fact pretty basic, don't use it. Use something a bit more sophisticated. If you are looking to replace the Java program you have, what language are you planning on? I've done very similar communication in LabVIEW and VISA.
01-13-2010 03:20 PM - edited 01-13-2010 03:26 PM
Micho,
A timeout will occur if there is more that one second between the issuance of ENQ and receipt of ACK or there is more that one second between any two characters in a command or response string.
If you are doing the above communication manually you may well get a timeout - but I see from the SPY log that this is not the problem. But perhaps it will help...
Ronnie
01-13-2010 03:31 PM
Thanks for the reply but I am getting the same results using a java program. It's definatly an issue with the termination char ... but the problem is I can't define more than one termination char ... here is an example of the communcation sequence
• Host sends ENQ character (ASCII 5, inquiry).
• Equipment responds with ACK character (ASCII 6, acknowledgment).
• Host sends STX CD ETX string (CD is a request for identification information).
• Equipment sends ENQ character (ASCII 5, inquiry).
• Host responds with ACK character (ASCII 6, acknowledgment).
• Equipment responds with STX Castle Handler 6 v1.02b Logic ETX character string.
So you see, the last char the equipment will send will either be ACK, ENQ, or ETX. I also can't set the buffer size since the equipment reply size will vary.
01-13-2010 03:47 PM
Micho, Have you tried the attribute:
If it is set to VI_ASRL_END_TERMCHAR, the read will terminate as soon as the character in VI_ATTR_TERMCHAR is received. In this case, VI_ATTR_TERMCHAR_EN is ignored.
Because the default value of VI_ATTR_TERMCHAR is 0Ah (linefeed), read operations on serial ports will stop reading whenever a linefeed is encountered. To change this behavior, you must change the value of one of these attributes—VI_ATTR_ASRL_END_IN or VI_ATTR_TERMCHAR.
[From the VI_ATTR_ASRL_END_IN help]
Ronnie
01-13-2010 03:49 PM
I can't help with the Java implementation but I've done it a couple of different ways and you don't really set the buffer size - you set the number of bytes to read from the buffer.
If I need to verify that the equipment is responding with the correct characters, I will first set the term char enable off. then, after doing the VISA Write, I will use the function to determine the number of bytes in the buffer (VI_ATTR_ASRL_AVAIL_NUM). I will pass this number to the VISA Read. I will scan the string returned for whatever single or multiple character I want. This is in a loop and if the expected character(s) are there, the loop stops. If they aren't, then the loop continues. I would place a timeout function (separate from the VISA built-in timeout) and return an error if the character(s) are never seen. The character(s) are a string that I pass to this general read function.
Another technique to use is to simply not care if the instrument is returning all of the correct acknowledgements and simply read whatever is returned. In this case, I have one loop with the VI_ATTR_ASRL_AVAIL_NUM function and exit the loop when the number is greater than 0 (there is also a timeout function here as well if the instrument never responds with anything). Then, another loop is called and this also has VI_ATTR_ASRL_AVAIL_NUM to pass the number of bytes to the VISA Read. This loop exits when the number of bytes is 0.
Which technique you use is up to you. There is more error checking in the first technique. The second is more like how Hyperterminal works. You just get whatever the instrument sends.
01-13-2010 03:55 PM
Hi Ronnie, yes I have tried that with all 3 settings
VI_ASRL_END_NONE (0)
VI_ASRL_END_LAST_BIT (1)
VI_ASRL_END_TERMCHAR (2)
The problem with setting to VI_ASRL_END_TERMCHAR is that I can only define one VI_ATTR_TERMCHAR .... I need three!
If VI_ATTR_ASRL_END_IN set to VI_ASRL_END_TERMCHAR and set VI_ATTR_TERMCHAR to 0x6 I can get past the first ENQ/ACK exchange but then timeouts on the STX<msg>ETX exchange.
01-13-2010 03:59 PM