New to DAQFactory so probably a simple syntax error


Recommended Posts

Hello. I have a test platform that consists of 3 serial devices; a servo, a force gauge and a travel indicator all of which I've communicated with using WinWedge in the past. What I'm having a problem with is the code used to strip off the unwanted parts of a string sent from the force gauge and the travel indicator so under Channels the chart and table can use the leftover numbers.


With the rs232 monitor window open, communication with the force gauge looks like:

Tx: ?\013
Rx: 0.014 lbF\013\010


I'd like to get rid of the " lbF" so I tried the following:

private string dataout = "?" + DoubleToStr(Channel) + Chr(13)
private string datain = Poll(dataout,13)


When I create a new channel and look at the table data, the value is reported as "NaN" (or something very similar, I'm not at the machine at the moment). I am having the same issue with the travel indicator but the code is very slightly different. The reported value in the channel table is the same, though.


I'm sure it's something embarrassingly simple I'm overlooking, but any help would be greatly appreciated. Thank you!



Link to comment
Share on other sites

Are you doing this in a protocol?  In general I recommend against creating user protocols until you need to reuse across multiple applications and have tested the logic in regular sequences.  The reason is that its a lot harder to edit and debug a user protocol.  With a regular sequence you can even add breakpoints.

That all said, the only problem that jumps out at me is that your are polling for data until a carriage return (13), but the device is responding with a carriage return and line feed.  That line feed gets left in the queue and may be processed as the first character of the next query if the serial port isn't purged first.  I would add:

? showHidden(datain)

right before the return statement so you can see what the data stream looks like that is being processed.

BTW, there is no reason really to use left() in this case because strToDouble() will take all valid characters that convert to numbers and then stop, so "0.014 lbF" gets converted to 0.014.  It returns NaN only if the first character of the string being converter is not a valid numeric.

Link to comment
Share on other sites

Yes, within a I/O type. I was using an old guide for serial communication with DAQFactory and had copy/pasted the code, with minor changes. After pondering the problem for a bit I didn't see why the "DoubleToStr(Channel)" was necessary. After removing it the problem went away and the value I was after was correctly shown in the channel.


You were right in the example above that strToDouble() would remove the need for "left()". In the case of the travel indicator (which I didn't show code for) I wound up needing to use Mid() because the devices return string was a little more complex (Rx: GN01,+000.16572\013\010), but the code edit I mentioned solved the problem of "NaN" being shown in the channel table.


Thank you very much for the help!

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.