mike72 Posted October 3, 2012 Share Posted October 3, 2012 im trying to connect my la crosse ws2300 weather station and cant even get the protocol right. does anyone have an idea what protocol i should use? thanks mike Link to comment Share on other sites More sharing options...
AzeoTech Posted October 4, 2012 Share Posted October 4, 2012 I would start by asking the manufacturer for the specifications for their protocol. Link to comment Share on other sites More sharing options...
mike72 Posted October 4, 2012 Author Share Posted October 4, 2012 apparently they wont give out the protocol, and getting nothing but zeros from a null or ansi protocol. any other ideas? thanks, mike Link to comment Share on other sites More sharing options...
AzeoTech Posted October 4, 2012 Share Posted October 4, 2012 Yeah, I didn't think they would. Many companies are silly about that. I think its either they don't want to release it because then they are stuck with it, or more likely because they want to leave the option of forcing you to buy their proprietary software. Silly either way. Anyhow, if you are getting all 0's then chances are you have the wrong comm port settings, baud rate or something else. You may need to play with it until you get something other than 0's. The other option is to sniff the comms while running their software. There are tools available to do that, or if you have a second PC, or one PC with several Comm ports, you can do it with DAQFactory. Link to comment Share on other sites More sharing options...
mike72 Posted October 5, 2012 Author Share Posted October 5, 2012 thanks for the reply, i got the com settings right, but still no luck. how would i check the protocol with daqfactory? i have 2 pc's and a few com ports to spare. it is a pity that no one has done this before, im really not clued up on protocols. thanks again mike Link to comment Share on other sites More sharing options...
AzeoTech Posted October 5, 2012 Share Posted October 5, 2012 Let's assume you have two computers. On the first computer you'd run their software, then run a null modem serial cable from that computer to one of the two ports on your second computer. That computer would run DAQFactory. Then you would run a cable from the other serial port to the LaCrosse unit. Start up DAQFactory, and create two serial devices, both with "NULL" for protocol and really short timeouts, say 50. Then create a sequence like this, where "softComm" is the comm port connected to the other computer, and "hardComm" is the one connected to the LaCrosse unit: private string datainwhile(1) try datain = device.hardComm.read(1) device.softComm.write(datain) catch() endcatch try datain = device.softComm.read(1) device.hardComm.write(datain) catch() endcatchendwhile[/CODE]Then start up their software. You may need to tweak the code, but at a minimum you should get the query from the software. If it is a poll / response, you can get this query with one computer and two comm ports. Just connect the two ports together with a null modem cable. Have their software use one port, and have DAQFactory connect to the other. You should see their queries in the monitor. Link to comment Share on other sites More sharing options...
mike72 Posted October 7, 2012 Author Share Posted October 7, 2012 ok....... i think ive just gone over my head with this one. thank you so much for your help, ill keep an eye on the forum to see if anyone else reads this and sends the protocol. thanks again mike Link to comment Share on other sites More sharing options...
AzeoTech Posted October 7, 2012 Share Posted October 7, 2012 Yeah, its not particularly easy to figure out an undocumented proprietary protocol. You'd probably be better off just creating your own weather station. Have you looked at the LabJack stuff? They have a temperature / humidity probe, and you could easily wire the anemometer of your LaCrosse unit to a counter input. For that matter, you could probably just bypass all their data acquisition and use their sensors with an inexpensive LabJack U3. You'd probably get better results too. Link to comment Share on other sites More sharing options...
mike72 Posted October 15, 2012 Author Share Posted October 15, 2012 hi there guru ive been thinking of a way around my problem, and the weather program logs to a file called currdat.lst. is there a way i can use this info and put it into DAQfactory? that way, the heavy weather program can just sit in the background. if i open the currdat.lst file in notepad, this is what i get: [header] programm_name = "heavy weather" programm_version = "Ver. 2.0 beta release" file_name = "currdat.lst" file_format_version = "ver. 1.0" [time] start = 3559026877 start_date_string = "Fri Oct 12 12:34:37 2012" last_actualisation = 3559276474 last_actualisation_date_string = "Mon Oct 15 09:54:34 2012" next_actualisation = 3559276534 next_actualisation_date_string = "Mon Oct 15 09:55:34 2012" [weather_picture] comment = "-1=not valid, 0=rain, 1=cloud, 2=sun" number = 1 [weather_tendency] comment_1 = "-1=not valid, 0=no change of air pressure" comment_2 = " 1=air pressure rising, 2=air pressure falling" number = 1 [indoor_temperature] deg_C = "19.6" deg_F = "67.2" [outdoor_temperature] deg_C = "20.1" deg_F = "68.1" [indoor_humidity] percent = "60" [outdoor_humidity] percent = "72" [dewpoint] deg_C = "14.9" deg_F = "58.8" [windchill] deg_C = "20.1" deg_F = "68.1" [wind_speed] mps = "0.0" kmh = "0.0" mph = "0.0" knt = "0.0" bft = " 0" [wind_direction] deg = "270.0" name = "W" [rain_total] mm = "0.0" inch = "0.00" [rain_24h] mm = "0.0" inch = "0.00" [rain_1h] mm = "0.0" inch = "0.00" [pressure_absolute] hpa = "1012.6" inHg = "29.90" [pressure_relative] hpa = "1015.0" inHg = "29.97" [storm_alarm] comment = "-1=not valid, 0=storm alarm not activ, 1=storm alarm activ" number = 0 it will be great if i can get this working thanks again mike Link to comment Share on other sites More sharing options...
AzeoTech Posted October 15, 2012 Share Posted October 15, 2012 Sure. You can use the low level File. functions to open and read this file, assuming the weather program doesn't have it locked for writing. Then you just need to read and parse the file. I'd do something like this. This is off the cuff and doesn't show reading all values, but should get you started: private string datainprivate datatry private handle = file.open("currdata.lst",1,0,0,1) while(1) datain = file.read(handle) if (isEmpty(datain)) break endif switch case (datain == "[pressure_absolute]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,'"',1)) data.time = systime() myPressureAbsoluteHPAChannel.addValue(data) datain = file.read(handle) // read next line data = strToDouble(parse(datain,'"',1)) data.time = systime() myPressureAbsoluteINHGChannel.addValue(data) case (datain == "[pressure_relative]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,'"',1)) data.time = systime() myPressureRelativeHPAChannel.addValue(data) datain = file.read(handle) // read next line data = strToDouble(parse(datain,'"',1)) data.time = systime() myPressureRelativeINHGChannel.addValue(data) endcase endwhilecatch() ? strLastErrorendcatch[/CODE] Link to comment Share on other sites More sharing options...
mike72 Posted October 16, 2012 Author Share Posted October 16, 2012 hi guru we are getting there... slowly but surely i get a NAN reply on the channels, and see it doesnt update. the lst file looks like it updates once a minute. got any ideas to fix that? mike Link to comment Share on other sites More sharing options...
mike72 Posted October 16, 2012 Author Share Posted October 16, 2012 hi guru below is what i have so far. i had to add a delay at the bottom, otherwise it overloads a cpu. when i stop and start the sequence, i get one data set to the channels, and thats it. somehow it doesnt see the while loop, or i cant see where the problem is. think the problem is me. otherwise, it works great, all the data i need is comming into the right channel. just for info, its a test channel, with A-D and sequencial channel numbers. thanks again for your help mike private string datainprivate datatry private handle = file.open("c:\weather.lst",1,0,0,1) while(1) datain = file.read(handle) if (isEmpty(datain)) break endif switch case (datain == "[pressure_absolute]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() pressure_rel.addValue(data) case (datain == "[pressure_relative]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() pressure_abs.addValue(data) case (datain == "[indoor_temperature]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() temp_in.addValue(data) case (datain == "[outdoor_temperature]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() temp_out.addValue(data) case (datain == "[wind_direction]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() wind_dir.addValue(data) case (datain == "[wind_speed]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() wind_speed.addValue(data) case (datain == "[indoor_humidity]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() humid_in.addValue(data) case (datain == "[outdoor_humidity]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() humid_out.addValue(data) case (datain == "[dewpoint]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() dewpoint.addValue(data) endcase delay(60) endwhile catch() ? strLastErrorendcatch[/CODE] Link to comment Share on other sites More sharing options...
AzeoTech Posted October 16, 2012 Share Posted October 16, 2012 The problem is the delay(60). Each iteration of the while loop reads only a single line of the file, so a 60 line file would take an hour to read. Change that delay to 0.1. Then put another while loop outside that while with a delay(60). I truthfully am not completely sure the isEmpty() line will pickup the end of file. Add something like ? "Done reading" outside the inner loop. Also the file.open should be inside the loop. Basically: while(1) try file.open(...) while(1) file.read(...) ... delay(0.05) endwhile file.close(...) catch() ? strLastError endcatch delay(60)endwhile[/CODE]Make sure the delay(60) is AFTER the endcatch. Link to comment Share on other sites More sharing options...
mike72 Posted October 16, 2012 Author Share Posted October 16, 2012 thanks for the reply guru, it doesnt kill the cpu anymore but still doesnt update. any more ideas? mike private string datainprivate datawhile(1)try private handle = file.open("c:\weather.lst",1,0,0,1) while(1) datain = file.read(handle) if (isEmpty(datain)) break endif switch case (datain == "[pressure_absolute]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() pressure_rel.addValue(data) case (datain == "[pressure_relative]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() pressure_abs.addValue(data) case (datain == "[indoor_temperature]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() temp_in.addValue(data) case (datain == "[outdoor_temperature]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() temp_out.addValue(data) case (datain == "[wind_direction]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() wind_dir.addValue(data) case (datain == "[wind_speed]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() wind_speed.addValue(data) case (datain == "[indoor_humidity]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() humid_in.addValue(data) case (datain == "[outdoor_humidity]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() humid_out.addValue(data) case (datain == "[dewpoint]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() dewpoint.addValue(data) endcase delay(0.05) endwhile file.Close(c:\weather.lst) catch() ? strLastErrorendcatchdelay(60)endwhile[/CODE] Link to comment Share on other sites More sharing options...
AzeoTech Posted October 17, 2012 Share Posted October 17, 2012 You probably need to either step through the code or add a bunch of print (?) statements so you know what is happening. I'm guessing the problem is that datain never equals any of the things you check for, probably because of a hidden character, like a space in the front or end. You might want to do: datain = rtrim(ltrim(datain)) right after the read() to eliminate any spaces. Link to comment Share on other sites More sharing options...
mike72 Posted October 17, 2012 Author Share Posted October 17, 2012 the code reads the right values, but it doesnt update or loop the statement. Link to comment Share on other sites More sharing options...
AzeoTech Posted October 17, 2012 Share Posted October 17, 2012 You mean it reads it once, then that's it? Its probably stuck in the loop because it can't tell its at the end of the file. Try changing the isempty() line to: if (datain == "") Link to comment Share on other sites More sharing options...
mike72 Posted October 17, 2012 Author Share Posted October 17, 2012 yip, it reads once then nothing else. tried replacing the (isEmpty(datain)) statement to (datain =="") but it doesnt read any values. its somewhere in the inner loop, but where? mike Link to comment Share on other sites More sharing options...
AzeoTech Posted October 17, 2012 Share Posted October 17, 2012 Hmm, try just adding a counter: try while(1) ... private count = 0 while(count < 200) count++ .... endwhile .... endwhile ...catch() ...endcatch[/CODE]That will make it so the inner loop will read a maximum of 200 lines. If it gets to the end and gets stuck, it will repeat up to a maximum of 200 times and then go to the outer loop. 200 times with a 0.05 delay is only 10 seconds, and given your outer loop is 60, it shouldn't be a problem. You can make it smaller if the files are smaller. You also can make the outer delay() a wait() to make it run exactly every 60 seconds. Just add a delay(0.1) inside the catch() Link to comment Share on other sites More sharing options...
mike72 Posted October 17, 2012 Author Share Posted October 17, 2012 hey..... well done guru. it works!!!! do you want a copy of the final code for others to see? thanks again, would of never been able to do it alone. mike Link to comment Share on other sites More sharing options...
AzeoTech Posted October 17, 2012 Share Posted October 17, 2012 Sure, though truthfully its kind of a kludge. I really need to figure out how you can tell the eof when working with text files. I suppose you could just do: if (File.getPosition(handle) >= file.getLength(handle)) breakendif[/CODE]You might try that instead of the counter. Also, you can probably get rid of the delay(0.05) now that the inner loop isn't spinning indefinitely. Do it after you are sure its all working. Link to comment Share on other sites More sharing options...
mike72 Posted October 17, 2012 Author Share Posted October 17, 2012 ok, here it is... and still running. it logs a value between 2 and 4 times a minute. not too worried about it, as long as its logging ;-) thanks again guru, now we dont need their protocol. mike While(1)private string datainprivate datatry private handle = file.open("c:\weather.lst",1,0,0,1) private count = 0 while(count < 200) count++ datain = file.read(handle) switch case (datain == "[pressure_absolute]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() pressure_rel.addValue(data) case (datain == "[pressure_relative]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() pressure_abs.addValue(data) case (datain == "[indoor_temperature]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() temp_in.addValue(data) case (datain == "[outdoor_temperature]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() temp_out.addValue(data) case (datain == "[average_wind_direction]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() wind_dir.addValue(data) case (datain == "[wind_speed_average]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() wind_speed.addValue(data) case (datain == "[indoor_humidity]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() humid_in.addValue(data) case (datain == "[outdoor_humidity]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() humid_out.addValue(data) case (datain == "[dewpoint]") datain = file.read(handle) // read next line data = strToDouble(parse(datain,1,'"',1)) data.time = systime() dewpoint.addValue(data) endcase delay(0.1) endwhile catch() ? strLastErrorendcatchdelay(1)endwhile[/CODE] Link to comment Share on other sites More sharing options...
mike72 Posted October 18, 2012 Author Share Posted October 18, 2012 hi guru, me again left the code to run the whole of the night and seen it stopped somewhere throughout the night, then restarted the whole program again. it stopped again, more or less after 5 hours, and gives an error : F0000 No Error Returned : w3 Line 5. looks like something in the count loop is causing it. got any ideas? mike Link to comment Share on other sites More sharing options...
mike72 Posted October 18, 2012 Author Share Posted October 18, 2012 guru it looks like the problem is somewhere else. even if i stop and start the sequence, i still get the error. even with playing with the count times. the .lst file i read from is still good, changing every minute so its not that. only thing that works is restarting DAQfactory. now im really confused. mike Link to comment Share on other sites More sharing options...
AzeoTech Posted October 18, 2012 Share Posted October 18, 2012 Most likely the problem is that the other application is writing to the file in the middle of you reading it. You have a couple choices: 1) the error shouldn't matter. Does it completely stop the sequence? You may need to put the file.close() after the endcatch 2) do a file.copy() to copy the file to a temporary file that you then read instead of reading the file the other application is changing directly. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.