edwardewilliams

Members
  • Content Count

    12
  • Joined

  • Last visited

Community Reputation

0 Neutral

About edwardewilliams

  • Rank
    Member
  1. edwardewilliams

    Parsing inbound strings with delimiters

    Ah, now I get it on the "@" character. As for the sequence, it finally turned out that DF apparently didn't like "TIME" as a variable name for some reason. Once I replaced that variable with "TM" instead, everything works fine. Odd. I also had a great deal of trouble getting changes to take effect while editing the sequence. I couldn't just do "apply and compile" then hit "restart sequence". I had to stop the sequence, apply and compile, save the file, then hit "start sequence" in debug - otherwise my new edits would not be run. Something to do with still having the serial port open perhaps?? Anyway, main issue solved for now. Thanks for the pointers.
  2. edwardewilliams

    Parsing inbound strings with delimiters

    OK, educate me on the following method: device.COM5.Purge() datain = "" datain = device.COM5.ReadUntil(10) ?datain PString = parse(datain,-1,",") ?PString[0] ?PString[1] ?PString[2] ?PString[3] ?PString[4] site = PString[0] date = PString[1] time = PString[2] chan = PString[3] val = PString[4] The "PString" array is created ok, and the ?PString[x] statements output the values in the array. Clearly, however, I'm not assigning the variables correctly from that array (site = PString[0], etc) because those variables do not get populated, and in fact the while loops hangs just after that last ?PString[x] statement... The software guys across the way are going to love it when I tell them that they're going to need a different sting delimiter than "@" if we're going to make our new box work with DF. Oh well, they'll get over it. - and no, pickiness is not the issue - I'm trying not to look COMPLETELY dumb...
  3. very, very simple task - take inbound data coming in on a com port, parse various things out of the string, display the parsed output... Here's the code: global string datain = "" global string site = "" global string date = "" global string time = "" global string chan = "" global string val = "" ?"SEQUENCE START" while(1) try() ?"WAITING INSIDE WHILE" device.COM5.Purge() datain = "" datain = device.COM5.ReadUntil(10) site = parse(datain,0,"@") date = parse(datain,1,"@") time = parse(datain,2,"@") chan = parse(datain,3,"@") val = parse(datain,4,"@") ?"Datain: " + datain ?"Site: " + site ?"Date: " + date ?"Time: " + time ?"Channel: " + chan ?"Reading: " + val catch() ?strlasterror endcatch endwhile I'm using global variables just so I can access them from the command alert window for testing - they'll normally be private variables - just FYI. example of an inbound string: TEST UNIT@11/06/08@21:00:25@ A1@ 16.94/013/010 (pay no attention to the wrong direction slashes on the line termination characters - the board apparently doesn't like backslashes in posts...) The issue is this - I see the deata coming in on Com 5 just fine in both the direct port monitor and the docking window. The "datain" string gets stored, but then the parse commands don't actually seem to be parsing and I can't figure out why. I've also tried the codee this way: datain = parse((device.COM5.ReadUntil(10)),-1,"@") site = datain[0] date = datain[1] time = datain[2] chan = datain[3] val = datain[4] and in this case, when I display datain, which should be an array, all I get back is the raw string as opposed to something more like {"TEST UNIT","11/06/08","21:00:25", etc...}), thus I have no array to go through in the subsequent calls. I'm clearly missing something simple - and after you stare at code for hours, you go a little funny in the eyes, so I'm sure it's an obvious and simple error. Help?
  4. edwardewilliams

    Odd (and new) issue with serial polling/parsing sequence

    Thanks for the tips. If the issue happened all the time, it would be easier to find - but it's intermittent and hard to predict, so the "quick fix" is needed for the moment. Appreciate the help, as always.
  5. edwardewilliams

    Odd (and new) issue with serial polling/parsing sequence

    Sorry, I should have clarified. The parsing loop exectues properly for each of the inbound reading as they come and get placed in to the "DATAIN" string. (no, the remote device isn't sending the same stirng over and over) Say for instance I'm reading five channels, they all get read and properly parsed. Then, the remote device gets done sending and while we're waiting for the timeout to occur in order to cause the while loop to error out and the function to exit, the last reading (the fifth channel in my example, for instance) just continually re-parses. In other words, the parsing loop just re-executes on whatever the last string was that was placed in to "DATAIN" In the copy of this I have running on my machine, I've added a number of "?" statements and they show that the parsing loop simply keeps repeating, re-parsing that last piece of data and creating new entries on the associated channel over and over until manually stopped. It's as if the connection isn't timing out or the function isn't seeing the timeout.... ? We did, however, have an "ingnore("all")" call in the startup routine...... I'll see how it works now.
  6. We use the following custom sequence to poll remote serial device over telemetry links. The link is established elswhere in DF and the Device Number (dn) is passed to this function. function PollLogger(dn) ispolling = 1 try private string datain = "junk" private string chan private ch private val private count = 0 while (1) try purge() write(chr(13)) delay(2) write(chr(13)) delay(2) write(chr(13)) delay(3) read(3) purge() if (resetpulse[dn]) //sitenum or dn? write("ch,p1"+chr(13)) delay(3) purge() write("pm=3"+chr(13)) delay(3) purge() resetpulse[dn] = 0//sitenum or dn? endif write("cr,a"+chr(13)) break catch() ? strLastError endcatch count++ if (count > 3) return endif delay(10) endwhile while (1) try datain = readuntil(10) // read a line: BV: 12.831310 chan = right(parse(datain,0,":"),2) val = strtodouble(parse(datain,1,":")) if (val == NaN()) val = 0 endif if (chan == "BV") ch = 0 else ch = strtodouble(mid(chan,1,10)) endif chan = left(chan,1) switch case (chan == "B") Channel.AddValue(strDevice,dn,"BatteryVoltage",0,val) case (chan == "S") Channel.AddValue(strDevice,dn,"SDISensor",ch,val) case (chan == "A") Channel.AddValue(strDevice,dn,"AnalogInput",ch,val) case (chan == "P") Channel.AddValue(strDevice,dn,"PulseInput",ch,val) endcase catch() ? "PollLogger: " + strLastError timepolled[dn] = systime() return endcatch endwhile catch() ? strLastError endcatch timepolled[dn] = systime() This has worked well for us in the past, but recently we've started having a problem where the last value read and placed in the "DATAIN" string will continue to parse over and over and over again - about every 8 seconds or so. Setting the timeout for the remote device to a shorter time solves the problem (the sequence relies on comm timeout to move on out of the read/parse loop) but then we have a problem where some of the devices may not connect since sometimes, depending on the device, it can take 10-15 seconds to obtain a connect - if device timeout is set shorter than that to avoid this problem, then we never connect in the first place. Thoughts as to how to make this more predictable? We can't have a "hard out" from the read/parse loop since depending on the device, we get a different number and combination of channels and channel types with no "end of data" character or similar termination sequence available.
  7. edwardewilliams

    Combo Box issue w/displayed text

    Yup. Works great! Thanks for the fix.
  8. Cool, thanks. Since we're using a custom user protocol to do our devices reads via telemetry, it looks like we'll have to modify that routine or create a new one for this project in order to do this if we want to continue to use MyChannel.AddValue() as the method of inserting readings in to the appropriate channels though, yes? Just out of curiosity, is there any chance that DF 6.0 might allow a more flexible use of the AddValue() function or provide something similar that would allow pre-processing and conversion before stuffing the value in the channel? In other words, is the idea of bringing the functionality of channel conversions to the AddValue() function being looked at? Thanks again for the feedback.
  9. edwardewilliams

    Combo Box issue w/displayed text

    UPDATE. Have verified that this issue seems to be due to the similar starting charcters of the soil names. Changing the list to read something like 1.Sand 2.Sandy Loam 3.Loamy Sand ...etc. completely cures the issue. So, for now, we've edited the pull-down list to include a space ahead of the offending values so they're sufficiently different not to be improperly displayed.
  10. Some quick background before the quesiton: On the app I'm currently working on, we want the customer to have the ability to apply custom calibration formulae to incoming data from a set of soil sensors. The way the systems are built in the field put 4 to 8 sensors at each of a number of measurement stations in a field. So, we do many things based on an array structure like "DataIn[sT][PR]" where 'ST' is the station number and 'PR' is the probe. However, the actual raw inbound data for each probe comes in on individual channels and we currently place those values in the channels with AddValue() as we parse the incoming data strings. What we want to be able to do is to allow the customer the option of applying a custom calibration to each probe at each station to tweak their system for slight variations in soil type over and above the "standard" values we will be including with the package. There are four possible formulas that can be applied to the incoming values. Each formula is a polynomial with 2 to 4 terms. We have a setup page all built so the customer can set the coefficients for each term and store those values for each station and probe. So now, I need a way to apply the chosen formula to the inbound readings. I can't use a channel conversion because they don't work with AddValue() and I can't place a SWITCH or IF statement in the "EVENT" tab of the channel to select a formula. So how would you solve the problem of doing this: If (Formula_Select == 1) MyChannel.AddValue(VAL + (VAL*A[ST][PR]) + (VAL*B[ST][PR]^2) + (VAL*C[ST][PR]^3)) If (Formula_Select == 2) MyChannel.AddValue(a diffferent formula) If (Formula_Select == 3) MyChannel.AddValue(another formula) ...etc endif My current thought is to bring the raw values in to one channel and then use a sequence to do the maths after all acquisition for a cycle is done. But that seems a bit wasteful of channels and gets confusing from a programming standpoint after more than just a couple of stations.
  11. edwardewilliams

    Combo Box issue w/displayed text

    Sure thing. Attached. ComboBox_Example.ctl ComboBox_Example.ctl
  12. I've run in to an odd issue with the Combo Box screen component. I have ten items in the list, and the combo box sets a variable used to pull soil type names out of an array. All of it works fine - the correct value is placed in to the variable and the correct name is selected from the array, but after making the selection, the name that's displayed in the combo box component itself is cometimes incorrect. For instance, when selection 3 is set, the name for selection 2 appears. When selection 8 is set, the name for selection 7 appears. Now, the names of the items in the list are similar - soils go by general texture descriptions such as "Loam", "Loamy Sand", "Sandy Loam", "Silty Clay", "Silty Clay Loam" and so on. The names that get incorrectly displayed are the ones that start with similar names - when "LOAM" is selected, it's "LOAMY SAND" that sets displayed. Is there a way to get around this? I'm guessing this is because of the way that DF processes the name displays in the "back office".